Commits

clach04 committed 3611cb7 Draft

initial meta data only reader.

  • Participants

Comments (0)

Files changed (1)

+#!/usr/bin/env python
+# -*- coding: us-ascii -*-
+# vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab
+#
+"""Pure Python version of Janes Longbow 2 detre tool.
+See Longbow 2: TRE extractor by Mario Brito
+"""
+
+import os
+import sys
+import struct
+
+def b2ui4(buf):
+    """buffer to unsigned 4 byte int (little endian)
+    """
+    num_files = struct.unpack('<L', buf)[0]  # little endian
+    return num_files
+
+def read_ui4(f):
+    buf = f.read(4)
+    result = b2ui4(buf)
+    return result
+
+def doit(tre_filename):
+    f = open(tre_filename, 'rb')
+    
+    # Longbow 2 MOVIES2.TRE file from cd2
+    buf = f.read(4)
+    assert buf == 'SKNK', "doesn't appear to be a Longbow2 TRE file. Got %r" % buf
+    buf = f.read(4)
+    assert buf == 'TREE', "doesn't appear to be a Longbow2 TRE file. Got %r" % buf
+    buf = f.read(4)
+    assert buf == '010A', "wrong version, possibly not a Longbow2 TRE file. Got %r" % buf
+    
+    num_files = read_ui4(f)
+    print repr(num_files)
+    print '%d files' % num_files
+    
+    header_size = read_ui4(f)
+    print '%d' % header_size
+    
+    start_offset = []
+    for x in range(num_files):
+        start_offset.append(read_ui4(f))
+    
+    size1 = []
+    for x in range(num_files):
+        size1.append(read_ui4(f))
+    
+    size2 = []
+    for x in range(num_files):
+        size2.append(read_ui4(f))
+    
+    zero_buf = []
+    for x in range(num_files):
+        zero_buf.append(read_ui4(f))
+    
+    print start_offset
+    print size1
+    print size2
+    print zero_buf
+    
+
+    filenames = []
+    for x in range(num_files):
+        filename = []
+        while 1:
+            b = f.read(1)
+            if b == '\x00':
+                break
+            else:
+                filename.append(b)
+        filename = ''.join(filename)
+        filename_list = filename.split('\\')  # Windows/DOS seperator
+        if filename_list[0] == '..':
+            del(filename_list[0])
+        top_f = filename_list[0]
+        bot_f = filename_list[1:]
+        filename = os.path.join(top_f, *bot_f)
+        filenames.append(filename)
+    print filenames
+    #buf = f.read(4096)
+    #print repr(buf)
+    
+    
+    f.close()
+
+
+def main(argv=None):
+    if argv is None:
+        argv = sys.argv
+    
+    #tre_filename = argv[1]
+    tre_filename = '/windows/lb2/MOVIES2.TRE'
+    doit(tre_filename)
+    
+    return 0
+
+
+if __name__ == "__main__":
+    sys.exit(main())