From ae535cadc68bb1968fdf5b860e4ec8d194608852 Mon Sep 17 00:00:00 2001 From: itsme Date: Wed, 7 Jul 2021 13:03:00 +0200 Subject: the basedef can be both an index and rawbytes. printing some Bank def values as escaped string now --- crodump.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/crodump.py b/crodump.py index e311190..868a4be 100644 --- a/crodump.py +++ b/crodump.py @@ -1,8 +1,9 @@ import os.path import io import struct +import re from binascii import b2a_hex -from hexdump import hexdump, asasc, tohex, unhex +from hexdump import hexdump, asasc, tohex, unhex, strescape from koddecoder import kodecode from readers import ByteReader @@ -150,11 +151,14 @@ def destruct_bank_definition(args, data): index_or_length = rd.readdword() if index_or_length >> 31: - d[keyname] = rd.readbytes(index_or_length & 0x7FFFFFFF) - print("%-20s - %s" % (keyname, toout(args, d[keyname]))) + 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]))) else: d[keyname] = index_or_length - print("%-20s -> %s" % (keyname, d[keyname])) + print("%-20s -> #%s" % (keyname, d[keyname])) return d def decode_field(data): @@ -238,9 +242,9 @@ class Database: if self.stru: print("stru") self.stru.dump(args) - if args.struonly: - self.dumptabledefs(args) - return + if args.struonly: + self.dumptabledefs(args) + return if self.index: print("index") self.index.dump(args) @@ -259,7 +263,11 @@ class Database: idx = dbdef.get("Base%03d" % i) if idx: print("== Base%03d ==" % i) - tbinfo = self.stru.readrec(idx) + if type(idx)==int: + tbinfo = self.stru.readrec(idx) + else: + # the table def is in the value. + tbinfo = struct.pack("