From e013ba878023f7222c28f9bc02b4270ffdd91bf9 Mon Sep 17 00:00:00 2001 From: megazig Date: Tue, 30 Jun 2009 13:47:44 -0500 Subject: [PATCH] started znd.py --- znd.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 znd.py diff --git a/znd.py b/znd.py new file mode 100755 index 0000000..0144dda --- /dev/null +++ b/znd.py @@ -0,0 +1,60 @@ +#!/usr/bin/python + +import sys, re, struct + +from Struct import Struct + +def nullterm(str_plus): + z = str_plus.find('\x00\x00') + if z != -1: + return str_plus[:z] + else: + return str_plus + +class ZND(object): + def __init__(self, data): + self.data = [] + if data != None: + self.Unpack(data) + + def Unpack(self, data): + pos = 0 + + count = Struct.uint32(data[pos:pos+4], endian='>') + pos += 4 + print "Count: %08x" % count + + print "\n%08x\n" % pos + + offset_list = [] + for x in xrange(count): + offset = Struct.uint32(data[pos:pos+4], endian='>') + pos += 4 + print "Offset: %08x" % offset + offset_list.append(offset) + + print "\n%08x\n" % pos + + for x in xrange(count): + pos = offset_list[x] + string = nullterm(data[pos:]) + string = unicode(string, 'utf_16_be') + print "String: %s" % string + pos += len(string) + +def main(): + if len(sys.argv) == 1: + print 'Usage: python bmg.py' + sys.exit(1) + f = open(sys.argv[1], 'rb') + if f: + znd_buffer = f.read() + f.close() + else: + print 'Could not open file for reading' + sys.exit(1) + + znd = ZND(znd_buffer) + +if __name__ == "__main__": + main()