-
Notifications
You must be signed in to change notification settings - Fork 3
/
pymobibACR38.py
executable file
·213 lines (180 loc) · 6.37 KB
/
pymobibACR38.py
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/env python
#
# (c) 2009 MOBIB Extractor project. This software is provided 'as-is',
# without any express or implied warranty. In no event will the authors be held
# liable for any damages arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to no restriction.
#
# Technical remarks and questions can be addressed to
# <tania.martin@uclouvain.be>
# <jean-pierre.Szikora@uclouvain.be>
#
from smartcard.System import readers
from smartcard.util import toHexString, toBytes
debug = 0
j = 0
r=readers()
print "Readers List: %s" %r
for i in range(len(r)):
if str(r[i]) == "ACS ACR38 Smart Card Reader 00 00" or str(r[i]) == "ACS ACR38U 00 00":
j = i
connection = r[j].createConnection()
connection.connect()
select_icc = toBytes("80 A4 08 00 04 3F 00 00 02")
select_holder = toBytes("80 A4 08 00 04 3F 00 3F 1C")
select_envhol = toBytes("80 A4 08 00 04 20 00 20 01")
select_eventlog = toBytes("80 A4 08 00 04 20 00 20 10")
select_contractlist = toBytes("80 A4 08 00 04 20 00 20 50")
select_contract = toBytes("80 A4 08 00 04 20 00 20 20")
select_counters = toBytes("80 A4 08 00 04 20 00 20 69")
select_loadlog = toBytes("80 A4 08 00 04 10 00 10 14")
select_purchaselog = toBytes("80 A4 08 00 04 10 00 10 15")
read_1record = toBytes("80 B2 01 04 1D")
read_2record = toBytes("80 B2 02 04 1D")
read_3record = toBytes("80 B2 03 04 1D")
read_4record = toBytes("80 B2 04 04 1D")
read_5record = toBytes("80 B2 05 04 1D")
read_6record = toBytes("80 B2 06 04 1D")
read_7record = toBytes("80 B2 07 04 1D")
read_8record = toBytes("80 B2 08 04 1D")
data,sw1,sw2 = connection.transmit(select_icc)
if debug:
print "Select ICC: %02x %02x" % (sw1,sw2)
if sw2 == 0x19:
data,sw1,sw2 = connection.transmit(read_1record)
if debug:
print "ReadRecord: %02x %02x" % (sw1,sw2)
print ("ICC: %s" % toHexString(data))
else:
print ("Error in ICC select")
data,sw1,sw2 = connection.transmit(select_holder)
if debug:
print "Select Holder: %02x %02x" % (sw1,sw2)
if sw2 == 0x19:
data,sw1,sw2 = connection.transmit(read_1record)
if debug:
print "Holder1 ReadRecord: %02x %02x" % (sw1,sw2)
print ("Holder1: %s" % toHexString(data))
data,sw1,sw2 = connection.transmit(read_2record)
if debug:
print "Holder2 ReadRecord: %02x %02x" % (sw1,sw2)
print ("Holder2: %s" % toHexString(data))
else:
print ("Error in Holder select")
data,sw1,sw2 = connection.transmit(select_envhol)
if debug:
print "Select EnvHol: %02x %02x" % (sw1,sw2)
if sw2 == 0x19:
data,sw1,sw2 = connection.transmit(read_1record)
if debug:
print "EnvHol1 ReadRecord: %02x %02x" % (sw1,sw2)
print ("EnvHol1: %s" % toHexString(data))
data,sw1,sw2 = connection.transmit(read_2record)
if debug:
print "EnvHol2 ReadRecord: %02x %02x" % (sw1,sw2)
print ("EnvHol2: %s" % toHexString(data))
else:
print ("Error in EnvHol select")
data,sw1,sw2 = connection.transmit(select_eventlog)
if debug:
print "Select EventLog: %02x %02x" % (sw1,sw2)
if sw2 == 0x19:
data,sw1,sw2 = connection.transmit(read_1record)
if debug:
print "EvLog1 ReadRecord: %02x %02x" % (sw1,sw2)
print ("EvLog1: %s" % toHexString(data))
data,sw1,sw2 = connection.transmit(read_2record)
if debug:
print "EvLog2 ReadRecord: %02x %02x" % (sw1,sw2)
print ("EvLog2: %s" % toHexString(data))
data,sw1,sw2 = connection.transmit(read_3record)
if debug:
print "EvLog3 ReadRecord: %02x %02x" % (sw1,sw2)
print ("EvLog3: %s" % toHexString(data))
else:
print ("Error in EventLog select")
data,sw1,sw2 = connection.transmit(select_contractlist)
if debug:
print "Select ContractList: %02x %02x" % (sw1,sw2)
if sw2 == 0x19:
data,sw1,sw2 = connection.transmit(read_1record)
if debug:
print "ContractList ReadRecord: %02x %02x" % (sw1,sw2)
print ("ConList: %s" % toHexString(data))
else:
print ("Error in ContractList select")
data,sw1,sw2 = connection.transmit(select_contract)
if debug:
print "Select Contract: %02x %02x" % (sw1,sw2)
if sw2 == 0x19:
data,sw1,sw2 = connection.transmit(read_1record)
if debug:
print "Contract1 ReadRecord: %02x %02x" % (sw1,sw2)
print ("Contra1: %s" % toHexString(data))
data,sw1,sw2 = connection.transmit(read_2record)
if debug:
print "Contract2 ReadRecord: %02x %02x" % (sw1,sw2)
print ("Contra2: %s" % toHexString(data))
data,sw1,sw2 = connection.transmit(read_3record)
if debug:
print "Contract3 ReadRecord: %02x %02x" % (sw1,sw2)
print ("Contra3: %s" % toHexString(data))
data,sw1,sw2 = connection.transmit(read_4record)
if debug:
print "Contract4 ReadRecord: %02x %02x" % (sw1,sw2)
print ("Contra4: %s" % toHexString(data))
data,sw1,sw2 = connection.transmit(read_5record)
if debug:
print "Contract5 ReadRecord: %02x %02x" % (sw1,sw2)
print ("Contra5: %s" % toHexString(data))
data,sw1,sw2 = connection.transmit(read_6record)
if debug:
print "Contract6 ReadRecord: %02x %02x" % (sw1,sw2)
print ("Contra6: %s" % toHexString(data))
data,sw1,sw2 = connection.transmit(read_7record)
if debug:
print "Contract7 ReadRecord: %02x %02x" % (sw1,sw2)
print ("Contra7: %s" % toHexString(data))
data,sw1,sw2 = connection.transmit(read_8record)
if debug:
print "Contract8 ReadRecord: %02x %02x" % (sw1,sw2)
print ("Contra8: %s" % toHexString(data))
else:
print ("Error in Contract select")
data,sw1,sw2 = connection.transmit(select_counters)
if debug:
print "Select Counters: %02x %02x" % (sw1,sw2)
if sw2 == 0x19:
data,sw1,sw2 = connection.transmit(read_1record)
if debug:
print "Counters ReadRecord: %02x %02x" % (sw1,sw2)
print ("Counter: %s" % toHexString(data))
else:
print ("Error in ContractList select")
data,sw1,sw2 = connection.transmit(select_loadlog)
if debug:
print "Select LoadLog: %02x %02x" % (sw1,sw2)
if sw2 == 0x19:
data,sw1,sw2 = connection.transmit(read_1record)
if debug:
print "ReadRecord: %02x %02x" % (sw1,sw2)
print ("LoadLog: %s" % toHexString(data))
else:
print ("Error in LoadLog select")
data,sw1,sw2 = connection.transmit(select_purchaselog)
if debug:
print "Select PurchaseLog: %02x %02x" % (sw1,sw2)
if sw2 == 0x19:
data,sw1,sw2 = connection.transmit(read_1record)
if debug:
print "PurchaseLog1 ReadRecord: %02x %02x" % (sw1,sw2)
print ("Purcha1: %s" % toHexString(data))
data,sw1,sw2 = connection.transmit(read_2record)
if debug:
print "PurchaseLog2 ReadRecord: %02x %02x" % (sw1,sw2)
print ("Purcha2: %s" % toHexString(data))
else:
print ("Error in PurchaseLog select")