summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoritsme <itsme@xs4all.nl>2021-07-07 13:03:00 +0200
committeritsme <itsme@xs4all.nl>2021-07-07 13:03:00 +0200
commitae535cadc68bb1968fdf5b860e4ec8d194608852 (patch)
treefcd65568c8978fbc09ec9a798a26d140dcf6a956
parenta8824d8041a975d6304106dbb33d547a97ada4a1 (diff)
the basedef can be both an index and rawbytes. printing some Bank def values as escaped string now
-rw-r--r--crodump.py24
1 files 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 @@
1import os.path 1import os.path
2import io 2import io
3import struct 3import struct
4import re
4from binascii import b2a_hex 5from binascii import b2a_hex
5from hexdump import hexdump, asasc, tohex, unhex 6from hexdump import hexdump, asasc, tohex, unhex, strescape
6from koddecoder import kodecode 7from koddecoder import kodecode
7from readers import ByteReader 8from readers import ByteReader
8 9
@@ -150,11 +151,14 @@ def destruct_bank_definition(args, data):
150 151
151 index_or_length = rd.readdword() 152 index_or_length = rd.readdword()
152 if index_or_length >> 31: 153 if index_or_length >> 31:
153 d[keyname] = rd.readbytes(index_or_length & 0x7FFFFFFF) 154 value = d[keyname] = rd.readbytes(index_or_length & 0x7FFFFFFF)
154 print("%-20s - %s" % (keyname, toout(args, d[keyname]))) 155 if re.search(b'[^\x0d\x0a\x09\x20-\x7e\xc0-\xff]', value):
156 print("%-20s - %s" % (keyname, toout(args, d[keyname])))
157 else:
158 print("%-20s - \"%s\"" % (keyname, strescape(d[keyname])))
155 else: 159 else:
156 d[keyname] = index_or_length 160 d[keyname] = index_or_length
157 print("%-20s -> %s" % (keyname, d[keyname])) 161 print("%-20s -> #%s" % (keyname, d[keyname]))
158 return d 162 return d
159 163
160def decode_field(data): 164def decode_field(data):
@@ -238,9 +242,9 @@ class Database:
238 if self.stru: 242 if self.stru:
239 print("stru") 243 print("stru")
240 self.stru.dump(args) 244 self.stru.dump(args)
241 if args.struonly: 245 if args.struonly:
242 self.dumptabledefs(args) 246 self.dumptabledefs(args)
243 return 247 return
244 if self.index: 248 if self.index:
245 print("index") 249 print("index")
246 self.index.dump(args) 250 self.index.dump(args)
@@ -259,7 +263,11 @@ class Database:
259 idx = dbdef.get("Base%03d" % i) 263 idx = dbdef.get("Base%03d" % i)
260 if idx: 264 if idx:
261 print("== Base%03d ==" % i) 265 print("== Base%03d ==" % i)
262 tbinfo = self.stru.readrec(idx) 266 if type(idx)==int:
267 tbinfo = self.stru.readrec(idx)
268 else:
269 # the table def is in the value.
270 tbinfo = struct.pack("<B", 4) + idx
263 tbdef = destruct_base_definition(args, tbinfo) 271 tbdef = destruct_base_definition(args, tbinfo)
264 272
265 273