Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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