From 6ab29a7ec498d3893dd602b881ae4d354a784b10 Mon Sep 17 00:00:00 2001 From: itsme Date: Wed, 7 Jul 2021 10:25:29 +0200 Subject: several updates: * added 'readrec' method to Datafile * case insensitive filename matching * added 'destruct' option to decode top level stru information. --- crodump.py | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 110 insertions(+), 23 deletions(-) diff --git a/crodump.py b/crodump.py index 7a9d9f3..f50f45b 100644 --- a/crodump.py +++ b/crodump.py @@ -4,6 +4,8 @@ import struct from binascii import b2a_hex from hexdump import hexdump, asasc, tohex, unhex from koddecoder import kodecode +from readers import ByteReader + """ python3 crodump.py crodump chechnya_proverki_ul_2012 python3 crodump.py kodump -s 6 -o 0x4cc9 -e 0x5d95 chechnya_proverki_ul_2012/CroStru.dat @@ -28,10 +30,12 @@ def enumunreferenced(ranges, filesize): class Datafile: """ Represent a single .dat with it's .tad index file """ - def __init__(self, dat, tad): + def __init__(self, dat, tad, need_decode=False): self.dat = dat self.tad = tad + self.need_decode = need_decode + self.readtad() self.dat.seek(0, io.SEEK_END) @@ -48,9 +52,40 @@ class Datafile: self.dat.seek(ofs) return self.dat.read(size) + def readrec(self, idx): + ofs, ln, chk = self.tabidx[idx-1] + if ln==0xFFFFFFFF: + # deleted record + return + + flags = ln>>24 + + ln &= 0xFFFFFFF + dat = self.readdata(ofs, ln) + + if not dat: + # empty record + encdat = dat + elif self.need_decode and not flags: + extofs, extlen = struct.unpack("> 31: + d[keyname] = rd.readbytes(index_or_length & 0x7FFFFFFF) + print("%-20s - %s" % (keyname, toout(args, d[keyname]))) + else: + d[keyname] = index_or_length + print("%-20s -> %s" % (keyname, d[keyname])) + def main(): import argparse parser = argparse.ArgumentParser(description='CRO hexdumper') @@ -222,6 +305,10 @@ def main(): cro.add_argument('dbdir', type=str) cro.set_defaults(handler=cro_dump) + des = subparsers.add_parser('destruct', help='Stru dumper') + des.add_argument('--ascdump', '-a', action='store_true') + des.set_defaults(handler=destruct) + args = parser.parse_args() if args.handler: -- cgit v1.2.3