| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
import pyshark |
| 4 |
import struct |
| 5 |
import sys |
| 6 |
import binascii |
| 7 |
|
| 8 |
dev_addr = 6 |
| 9 |
|
| 10 |
|
| 11 |
def hexDump(s): |
| 12 |
h = " ".join(map("{:02x}".format, s)) |
| 13 |
t = "" |
| 14 |
for i in range(len(s)): |
| 15 |
c = s[i] |
| 16 |
if c>=0x20 and c<0x7f: |
| 17 |
t += chr(c) |
| 18 |
else: |
| 19 |
t += "." |
| 20 |
return( h + " | " + t) |
| 21 |
|
| 22 |
def isFromHost(p): |
| 23 |
return ("host" == p.usb.src) and ((None==dev_addr) or (dev_addr == int(p.usb.device_address))) |
| 24 |
|
| 25 |
def isToHost(p): |
| 26 |
return ("host" == p.usb.dest) |
| 27 |
|
| 28 |
def isDataPacket(p): |
| 29 |
return ("USB.CAPDATA" in p) |
| 30 |
|
| 31 |
def getData(p): |
| 32 |
if not isDataPacket(p): |
| 33 |
return None |
| 34 |
return binascii.a2b_hex(p["USB.CAPDATA_RAW"].value) |
| 35 |
|
| 36 |
|
| 37 |
cap = pyshark.FileCapture(sys.argv[1], include_raw=True, use_json=True) |
| 38 |
nextaddr = 0 |
| 39 |
for p in cap: |
| 40 |
if isDataPacket(p): |
| 41 |
dump = hexDump(getData(p)) |
| 42 |
if isFromHost(p): |
| 43 |
print("> " + dump) |
| 44 |
else: |
| 45 |
print("< " + dump) |
| 46 |
|