Skip to content

Commit

Permalink
Do not crash after KVS unpack failure
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba2k2 committed Dec 1, 2023
1 parent 665743e commit d9f6b14
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions bk7231tools/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,25 @@ def dissect_dump_file(args):
break
pos, storage_data = result
aes = AES.new(key=KEY_MASTER, mode=AES.MODE_ECB)
kvs = KVStorage.unpack(storage_data, aes=aes)
try:
kvs = KVStorage.unpack(storage_data, aes=aes)
except Exception:
print("!!! Couldn't unpack KVStorage, perhaps dump file is invalid?")
traceback.print_exc()
break
keys = list(kvs.indexes.keys())
print(f"\t{pos:#06x}: {kvs.length // 1024:d} KiB - {len(keys)} keys")
print("\n".join(f"\t- '{key}'" for key in keys))
if args.extract:
dumpfile_name = Path(dumpfile).stem

out_name = os.path.join(output_directory, f"{dumpfile_name}_storage.json")
kvs_data = kvs.read_all_values_parsed()
try:
kvs_data = kvs.read_all_values_parsed()
except Exception:
print("!!! Couldn't read parsed KVS values")
traceback.print_exc()
break
with open(out_name, "w") as f:
print(f"\t\textracted all keys to {out_name}")
json.dump(kvs_data, f, indent="\t")
Expand Down

0 comments on commit d9f6b14

Please sign in to comment.