Christina Quast | ad6f4d3 | 2015-06-24 15:44:36 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import array |
| 4 | from constants import * |
| 5 | |
| 6 | |
| 7 | # Address book entries |
| 8 | name = 'deine mudda' |
| 9 | phone = '0123456789abcdef' |
| 10 | |
| 11 | def replace(data): |
| 12 | print(replace.last_req) |
| 13 | if data is None: |
| 14 | raise MITMReplaceError |
| 15 | else: |
| 16 | try: |
| 17 | if data[0] == 0xA0: |
| 18 | print("INS: ", hex(data[1])) |
| 19 | replace.last_req = data |
| 20 | return data |
| 21 | |
| 22 | if data[0] == 0x3B: |
| 23 | return data |
| 24 | #print("*** Replace ATR") |
| 25 | #return array('B', NEW_ATR) |
| 26 | elif data[0] == 0x9F: |
| 27 | return data |
| 28 | # print("*** Replace return val") |
| 29 | # return array('B', [0x60, 0x00]) |
| 30 | elif replace.last_req[1:5] == array('B', [0xB2, 0x01, 0x04, 0x1A]): # phone book request |
| 31 | print("*** Replace phone book") |
| 32 | # return array('B', [0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0xff, 0xff, 0xff, 0xff, 0x09, 0x81, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xff, 0xff, 0xff, 0xff, 0x90, 0x00]) |
| 33 | resp = map(ord, name) + ([0xff]*(12-len(name))) + [len(name) + 1] + [0x81] |
| 34 | for x in range(1,len(phone)/2+1): |
| 35 | list.append(resp, int(phone[x*2-2:2*x:], 16)) |
| 36 | resp += ([0xff]*(replace.last_req[4]-len(resp))) + [0x90, 0x00] |
| 37 | return array('B', resp) |
| 38 | except ValueError: |
| 39 | print("*** Value error! ") |
| 40 | return data |
| 41 | |
| 42 | replace.last_req = array('B') |
| 43 | |
| 44 | if __name__ == '__main__': |
| 45 | print("Replacing PHONE_BOOK_REQ", PHONE_BOOK_REQ, "with", replace(PHONE_BOOK_REQ)) |
| 46 | print("Replacing PHONE_BOOK_RESP", PHONE_BOOK_RESP, "with", replace(PHONE_BOOK_RESP)) |