#!/usr/bin/env python3 # BlueKitchen GmbH (c) 2022 # parse PacketLogger and dump encryption keys import sys import datetime import struct def as_hex(data): str_list = [] for byte in data: str_list.append("{0:02x} ".format(byte)) return ''.join(str_list) def as_key(data): str_list = [] for byte in data: str_list.append("{0:02x}".format(byte)) return ''.join(str_list) def as_bd_addr(data): str_list = [] for byte in data: str_list.append("{0:02x}".format(byte)) return ':'.join(str_list) def read_header(f): bytes_read = f.read(13) if bytes_read: return struct.unpack(">IIIB", bytes_read) else: return (-1, 0, 0, 0) def handle_at_offset(data, offset): return struct.unpack_from(" 66000: print ("Error parsing pklg at offset %u (%x)." % (pos, pos)) break packet = fin.read(packet_len) pos = pos + 4 + entry_len if type == 0x00: handle_cmd(packet) elif type == 0x01: handle_evt(packet) elif type == 0x02: pass elif type == 0x03: pass except TypeError as e: print(e) print ("Error parsing pklg at offset %u (%x)." % (pos, pos))