Skip to content

Instantly share code, notes, and snippets.

@darthcloud
Created May 29, 2020 12:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darthcloud/1316ba802d33dab32f90a29ab915e440 to your computer and use it in GitHub Desktop.
Save darthcloud/1316ba802d33dab32f90a29ab915e440 to your computer and use it in GitHub Desktop.
Bluetooth H4 raw binary trace to Wireshark's text2pcap
#!/usr/bin/env python3
import sys
with open(sys.argv[1], "rb") as f:
byte = f.read(1)
while byte:
if int(byte[0]) == 0x01:
byte += f.read(3)
byte += f.read(int(byte[3]))
print('O 00000 ' + ''.join('{:02x} '.format(x) for x in byte))
elif int(byte[0]) == 0x02:
byte += f.read(4)
byte += f.read(int(byte[3]) | (int(byte[4]) << 4))
print('00000 ' + ''.join('{:02x} '.format(x) for x in byte))
elif int(byte[0]) == 0x04:
byte += f.read(2)
byte += f.read(int(byte[2]))
print('I 00000 ' + ''.join('{:02x} '.format(x) for x in byte))
byte = f.read(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment