Bluetooth H4 raw binary trace to Wireshark's text2pcap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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