-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathDebuggerScriptFile.py
More file actions
104 lines (87 loc) · 2.42 KB
/
DebuggerScriptFile.py
File metadata and controls
104 lines (87 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# -*- coding:utf8 -*-
'''
Created on 2016-7-19
@author: [email protected]
@organization: https://www.javacardos.com/
@copyright: JavaCardOS Technologies. All rights reserved.
'''
from Util import Util
class DebuggerScriptFile(object):
'''
classdocs
'''
__DEBUGGER_COMMANDS1 = [
"RF_ON"
, "RF_OFF"
, "RF_AUTO"
, "RF_MANUAL"
]
__DEBUGGER_COMMANDS2 = [
# "%UID%"
"REQA"
, "WUPA"
, "ANTICOLLISION"
, "SELECT"
, "RATS"
, "HLTA"
, "PPS"
, "REQB"
, "WUPB"
, "SLOT-MARKER"
, "ATTRIB"
, "HLTB"
, "I-BLOCK"
, "R-BLOCK"
, "S-BLOCK"
, "AUTHENTICATION"
, "READ_BLOCK"
, "WRITE_BLOCK"
, "INCREMENT"
, "DECREMENT"
, "RESTORE"
, "TRANSFER"
]
def __init__(self, scriptPath):
'''
Constructor
'''
self.__scriptPath = scriptPath
def parse(self):
ret = True
error = ''
scriptLines = []
with open(self.__scriptPath, 'r') as scriptFile:
scriptLines = scriptFile.readlines()
commandsInfo = []
for scriptLine in scriptLines:
scriptLine = scriptLine.strip()
lineTokens = scriptLine.split()
error = 'Invalid script line format. %s' %(scriptLine)
if (len(lineTokens) < 1):
ret = False
break
commandName = lineTokens[0].upper()
if commandName in DebuggerScriptFile.__DEBUGGER_COMMANDS1:
commandsInfo.append((commandName, ''))
continue
elif commandName in DebuggerScriptFile.__DEBUGGER_COMMANDS2:
if (len(lineTokens) < 2):
ret = False
break
commandValue = lineTokens[1]
if not Util.ishexstr(commandValue):
ret = False
break
commandsInfo.append((commandName, commandValue))
continue
else:
ret = False
break
if ret:
return ret, commandsInfo
return ret, error
def save(self, commandsInfo):
with open(self.__scriptPath, 'w') as scriptFile:
for commandInfo in commandsInfo:
scriptFile.write(commandInfo[0] + ' ' + commandInfo[1] + '\n')
scriptFile.flush()