-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump.py
executable file
·84 lines (80 loc) · 3.32 KB
/
dump.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
from smartcard.CardType import AnyCardType
from smartcard.CardConnection import CardConnection
from smartcard.CardRequest import CardRequest
from smartcard.util import toHexString, toBytes
cardtype = AnyCardType()
cardrequest = CardRequest( timeout=60, cardType=cardtype )
cardservice = cardrequest.waitforcard()
cardservice.connection.connect(CardConnection.T0_protocol)
SELECT = [0x00, 0xA4, 0x04, 0x00, 0x08]
THAI_ID_CARD = [0xA0, 0x00, 0x00, 0x00, 0x54, 0x48, 0x00, 0x01]
REQ_CID = [0x80, 0xb0, 0x00, 0x04, 0x02, 0x00, 0x0d]
REQ_THAI_NAME = [0x80, 0xb0, 0x00, 0x11, 0x02, 0x00, 0x64]
REQ_ENG_NAME = [0x80, 0xb0, 0x00, 0x75, 0x02, 0x00, 0x64]
REQ_GENDER = [0x80, 0xb0, 0x00, 0xE1, 0x02, 0x00, 0x01]
REQ_DOB = [0x80, 0xb0, 0x00, 0xD9, 0x02, 0x00, 0x08]
REQ_ADDRESS = [0x80, 0xb0, 0x15, 0x79, 0x02, 0x00, 0x64]
REQ_ISSUE_EXPIRE = [0x80, 0xb0, 0x01, 0x67, 0x02, 0x00, 0x12]
REQ_OFFICE=[0x80, 0xB0, 0x00, 0xE2, 0x02, 0x00, 0x64]
REQ_CARD_UNIQUE=[0x80, 0xB0, 0x16, 0x19, 0x02, 0x00, 0x0E]
REQ_OFFICER=[0x80, 0xB0, 0x01, 0x5A, 0x02, 0x00, 0x0D]
DATA = [REQ_CID,REQ_THAI_NAME,REQ_ENG_NAME,REQ_GENDER,REQ_DOB,REQ_ADDRESS,REQ_ISSUE_EXPIRE,REQ_OFFICE,REQ_CARD_UNIQUE,REQ_OFFICER]
apdu = SELECT+THAI_ID_CARD
response, sw1, sw2 = cardservice.connection.transmit( apdu )
response, sw1, sw2 = cardservice.connection.transmit( REQ_CID )
if sw1 == 0x61:
GET_RESPONSE = [0X00, 0XC0, 0x00, 0x00 ]
apdu = GET_RESPONSE + [sw2]
response, sw1, sw2 = cardservice.connection.transmit( apdu )
result = ""
for i in response:
result = result+chr(i)
f = open(result+'.jpg','w')
f2 = open(result+'.txt','w')
for d in DATA:
response, sw1, sw2 = cardservice.connection.transmit( d )
if sw1 == 0x61:
GET_RESPONSE = [0X00, 0XC0, 0x00, 0x00 ]
apdu = GET_RESPONSE + [sw2]
response, sw1, sw2 = cardservice.connection.transmit( apdu )
result = ""
for i in response:
result = result+chr(i)
f2.write(result.rstrip().decode('tis-620').encode('utf8')+"\n")
response, sw1, sw2 = cardservice.connection.transmit( [0x80, 0xb0, 0x01, 123, 0x02, 0x00, (256-122)] )
if sw1 == 0x61:
GET_RESPONSE = [0X00, 0XC0, 0x00, 0x00 ]
apdu = GET_RESPONSE + [sw2]
response, sw1, sw2 = cardservice.connection.transmit( apdu )
result = ""
for i in response:
result = result+chr(i)
f.write(result)
for d in range(0x02,0x15):
response, sw1, sw2 = cardservice.connection.transmit( [0x80, 0xb0, d, 0x00, 0x02, 0x00, 0x80] )
if sw1 == 0x61:
GET_RESPONSE = [0X00, 0XC0, 0x00, 0x00 ]
apdu = GET_RESPONSE + [sw2]
response, sw1, sw2 = cardservice.connection.transmit( apdu )
result = ""
for i in response:
result = result+chr(i)
f.write(result)
response, sw1, sw2 = cardservice.connection.transmit( [0x80, 0xb0, d, 0x80, 0x02, 0x00, 0x80] )
if sw1 == 0x61:
GET_RESPONSE = [0X00, 0XC0, 0x00, 0x00 ]
apdu = GET_RESPONSE + [sw2]
response, sw1, sw2 = cardservice.connection.transmit( apdu )
result = ""
for i in response:
result = result+chr(i)
f.write(result)
response, sw1, sw2 = cardservice.connection.transmit( [0x80, 0xb0, 0x15, 0x00, 0x02, 0x00, 0x79] )
if sw1 == 0x61:
GET_RESPONSE = [0X00, 0XC0, 0x00, 0x00 ]
apdu = GET_RESPONSE + [sw2]
response, sw1, sw2 = cardservice.connection.transmit( apdu )
result = ""
for i in response:
result = result+chr(i)
f.write(result)