blob: b8fb004f3f03f1853b967617cfa8857c913c6897 [file] [log] [blame]
Christina Quastad6f4d32015-06-24 15:44:36 +02001#!/usr/bin/env python
2
3import array
4from constants import *
5
6
7# Address book entries
8name = 'deine mudda'
9phone = '0123456789abcdef'
10
11def 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
42replace.last_req = array('B')
43
44if __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))