From d30a78c7ea4c702519b00243b43d507582b119c0 Mon Sep 17 00:00:00 2001 From: itsme Date: Fri, 9 Jul 2021 21:06:35 +0200 Subject: crodump: improved strudump output and code --- crodump.py | 73 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/crodump.py b/crodump.py index 09823b8..86a6926 100644 --- a/crodump.py +++ b/crodump.py @@ -198,32 +198,16 @@ class Datafile: C = zlib.decompressobj(-15) return C.decompress(data[8:-3]) -def destruct_bank_definition(args, data): +def dump_bank_definition(args, bankdict): """ decode the 'bank' / database definition """ - rd = ByteReader(data) - - version = rd.readbyte() - print("bank version: %02x" % version) - - d = dict() - while not rd.eof(): - keyname = rd.readname() - if keyname in d: - print("WARN: duplicate key: %s" % keyname) - - index_or_length = rd.readdword() - if index_or_length >> 31: - value = d[keyname] = rd.readbytes(index_or_length & 0x7FFFFFFF) - if re.search(b'[^\x0d\x0a\x09\x20-\x7e\xc0-\xff]', value): - print("%-20s - %s" % (keyname, toout(args, d[keyname]))) - else: - print("%-20s - \"%s\"" % (keyname, strescape(d[keyname]))) + for k, v in bankdict.items(): + if re.search(b'[^\x0d\x0a\x09\x20-\x7e\xc0-\xff]', v): + print("%-20s - %s" % (k, toout(args, v))) else: - d[keyname] = index_or_length - print("%-20s -> #%s" % (keyname, d[keyname])) - return d + print("%-20s - \"%s\"" % (k, strescape(v))) + def decode_field(data): rd = ByteReader(data) @@ -249,8 +233,6 @@ def destruct_base_definition(args, data): """ rd = ByteReader(data) - version = rd.readbyte() - print("base version: %02x" % version) unk123 = [rd.readword() for _ in range(3)] unk45 = [rd.readdword() for _ in range(2)] tablename = rd.readname() @@ -343,20 +325,39 @@ class Database: return self.dumptabledefs(args) + def decode_bank_definition(self, data): + """ + decode the 'bank' / database definition + """ + rd = ByteReader(data) + + d = dict() + while not rd.eof(): + keyname = rd.readname() + if keyname in d: + print("WARN: duplicate key: %s" % keyname) + + index_or_length = rd.readdword() + if index_or_length >> 31: + d[keyname] = rd.readbytes(index_or_length & 0x7FFFFFFF) + else: + refdata = self.stru.readrec(index_or_length) + if refdata[:1] != b"\x04": + print("WARN: expected refdata to start with 0x04") + d[keyname] = refdata[1:] + return d + def dumptabledefs(self, args): dbinfo = self.stru.readrec(1) - dbdef = destruct_bank_definition(args, dbinfo) - - for i in range(100): - idx = dbdef.get("Base%03d" % i) - if idx: - print("== Base%03d ==" % i) - if type(idx)==int: - tbinfo = self.stru.readrec(idx) - else: - # the table def is in the value. - tbinfo = struct.pack("