diff options
-rwxr-xr-x | usb_application/apdu_split.py | 22 | ||||
-rw-r--r-- | usb_application/constants.py | 3 |
2 files changed, 21 insertions, 4 deletions
diff --git a/usb_application/apdu_split.py b/usb_application/apdu_split.py index d2c928c..c210470 100755 --- a/usb_application/apdu_split.py +++ b/usb_application/apdu_split.py @@ -29,12 +29,14 @@ class apdu_states(Enum): APDU_S_SW1 = 9 APDU_S_SW2 = 10 APDU_S_FIN = 11 + PTS = 12 class Apdu_splitter: def __init__(self): self.state = apdu_states.APDU_S_CLA self.buf = [] + self.pts_buf = [] self.data = [] self.ins = array('B', []) self.data_remainig = 0 @@ -44,9 +46,19 @@ class Apdu_splitter: self.buf.append(c) self.state = apdu_states(self.state.value + 1) + def func_PTS(self, c): + self.pts_buf.append(c) + print("PTS: ", self.pts_buf) + if self.pts_buf == [0xff, 0x00, 0xff]: + self.state = apdu_states.APDU_S_FIN + def func_APDU_S_CLA_P1_P2(self, c): - self.buf.append(c) - self.state = apdu_states(self.state.value + 1) + if self.state == apdu_states.APDU_S_CLA and c == 0xff: + self.state = apdu_states.PTS + self.pts_buf = [c] + else: + self.buf.append(c) + self.state = apdu_states(self.state.value + 1) def func_APDU_S_P3(self, c): self.buf.append(c) @@ -103,7 +115,8 @@ class Apdu_splitter: apdu_states.APDU_S_DATA : func_APDU_S_DATA, apdu_states.APDU_S_DATA_SINGLE : func_APDU_S_DATA_SINGLE, apdu_states.APDU_S_SW1 : func_APDU_S_SW1, - apdu_states.APDU_S_SW2 : func_APDU_S_SW2 } + apdu_states.APDU_S_SW2 : func_APDU_S_SW2, + apdu_states.PTS : func_PTS } INS_data_expected = [0xC0, 0xB0] @@ -121,9 +134,10 @@ if __name__ == '__main__': 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x91, 0x00, 0x17, 0x04, 0x00, 0x00, 0x00, 0x83, 0x8A, 0x90, 0x00] + pts = [0xff, 0x00, 0xff] apdus = [] apdu = Apdu_splitter() - for c in msg2 + msg1: + for c in pts + msg2 + msg1: apdu.split(c) if apdu.state == apdu_states.APDU_S_FIN: apdus.append(apdu) diff --git a/usb_application/constants.py b/usb_application/constants.py index 5013fd2..6263957 100644 --- a/usb_application/constants.py +++ b/usb_application/constants.py @@ -8,6 +8,9 @@ PHONE_WR = 0x4 PHONE_RD = 0x85 PHONE_INT = 0x86 +# Change FIDI +CMD_CHANGE_FIDI = array('B', [0xff, 0x00, 0xff]) +CHANGE_FIDI = array('B', [0xff, 0xff, 0xff, 0x00, 0xff]) CMD_SEL_ROOT = array('B', [0xA0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00]) CMD_SEL_FILE = array('B', [0xA0, 0xA4, 0x00, 0x00, 0x02, 0x7F, 0x20]) |