Christina Quast | 9836933 | 2015-03-02 16:08:40 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | import usb.core |
| 4 | import usb.util |
| 5 | import sys |
Christina Quast | 2b8a18b | 2015-04-12 09:31:36 +0200 | [diff] [blame^] | 6 | import array |
Christina Quast | 9836933 | 2015-03-02 16:08:40 +0100 | [diff] [blame] | 7 | |
Christina Quast | 2b8a18b | 2015-04-12 09:31:36 +0200 | [diff] [blame^] | 8 | from constants import PHONE_RD |
Christina Quast | 9836933 | 2015-03-02 16:08:40 +0100 | [diff] [blame] | 9 | |
| 10 | def find_dev(): |
| 11 | dev = usb.core.find(idVendor=0x03eb, idProduct=0x6004) |
| 12 | if dev is None: |
| 13 | raise ValueError("Device not found") |
| 14 | else: |
| 15 | print("Found device") |
| 16 | return dev |
| 17 | |
| 18 | def find_eps(dev): |
| 19 | dev.set_configuration() |
| 20 | |
| 21 | cfg = dev.get_active_configuration() |
| 22 | print("Active config: ") |
| 23 | print(cfg) |
| 24 | intf = cfg[(0,0)] |
| 25 | |
| 26 | ep_in = usb.util.find_descriptor( |
| 27 | intf, |
| 28 | custom_match = \ |
| 29 | lambda e: \ |
| 30 | usb.util.endpoint_direction(e.bEndpointAddress) == \ |
| 31 | usb.util.ENDPOINT_IN) |
| 32 | |
| 33 | assert ep_in is not None |
| 34 | |
| 35 | ep_out = usb.util.find_descriptor( |
| 36 | intf, |
| 37 | custom_match = \ |
| 38 | lambda e: \ |
| 39 | usb.util.endpoint_direction(e.bEndpointAddress) == \ |
| 40 | usb.util.ENDPOINT_OUT) |
| 41 | |
| 42 | assert ep_out is not None |
| 43 | print("****") |
| 44 | print(ep_in) |
| 45 | print(ep_out) |
| 46 | return (ep_in, ep_out) |
| 47 | |
| 48 | # main code |
Christina Quast | f2582fc | 2015-03-06 19:09:35 +0100 | [diff] [blame] | 49 | def sniff(): |
Christina Quast | 9836933 | 2015-03-02 16:08:40 +0100 | [diff] [blame] | 50 | dev = find_dev() |
Christina Quast | 2b8a18b | 2015-04-12 09:31:36 +0200 | [diff] [blame^] | 51 | ans = array.array('B', []) |
Christina Quast | 9836933 | 2015-03-02 16:08:40 +0100 | [diff] [blame] | 52 | |
| 53 | while True: |
| 54 | #ep_out.write("Hello") |
| 55 | try: |
Christina Quast | 2b8a18b | 2015-04-12 09:31:36 +0200 | [diff] [blame^] | 56 | ans += dev.read(PHONE_RD, 64, 1000) |
Christina Quast | 9836933 | 2015-03-02 16:08:40 +0100 | [diff] [blame] | 57 | except KeyboardInterrupt: |
| 58 | print("Bye") |
| 59 | sys.exit() |
Christina Quast | 2b8a18b | 2015-04-12 09:31:36 +0200 | [diff] [blame^] | 60 | except Exception as e: |
| 61 | print e |
| 62 | |
| 63 | if len(ans) >= 15: |
| 64 | print("".join("%02x " % b for b in ans)) |
| 65 | ans = array.array('B', []) |