From 5393bc3bd1457c8100ee47ad0bc4bfec8160622e Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Wed, 20 Dec 2023 15:29:04 +0100 Subject: [PATCH] tool: add dump_keys.py that dumps link keys and long term keys from pklg files --- tool/dump_keys.py | 136 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100755 tool/dump_keys.py diff --git a/tool/dump_keys.py b/tool/dump_keys.py new file mode 100755 index 000000000..1a5c41882 --- /dev/null +++ b/tool/dump_keys.py @@ -0,0 +1,136 @@ +#!/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))