Permalink
Browse files

first pass at recursive file list (although skipping leaves at the mo…

…ment)
  • Loading branch information...
jtauber committed Jul 15, 2012
1 parent 8b73e46 commit b23c7537ff7175f69f5ca31c518e95630848723b
Showing with 24 additions and 0 deletions.
  1. +24 −0 clidat.py
View
@@ -66,6 +66,26 @@ def show_directory(filename, offset=None):
print "%08X %08X %08X %s %08X | %08X %08X %08X | %08X" % (file_id, offset, size1, time.ctime(timestamp), version, size2, unk1, unk2, size2 - size1)
+## list
+
+def show_list(filename):
+ """
+ list all the files in the DAT
+ """
+ f = DatFile(filename)
+ go_list(f, f.directory_offset)
+
+
+def go_list(f, offset):
+ d = f.directory(offset)
+
+ for i, block_size, dir_offset in d.subdir_ptrs:
+ go_list(f, dir_offset)
+ if i < d.count:
+ j, unk1, file_id, offset, size1, timestamp, version, size2, unk2 = d.file_ptrs[i]
+ print "%08X %08X %08X %s %08X | %08X %08X %08X | %08X" % (file_id, offset, size1, time.ctime(timestamp), version, size2, unk1, unk2, size2 - size1)
+
+
## mainline
def show_usage(argv0):
@@ -74,6 +94,7 @@ def show_usage(argv0):
print("%s file_block <filename> <hex-offset>" % argv0)
print("%s directory <filename>" % argv0)
print("%s directory <filename> <hex-offset>" % argv0)
+ print("%s list <filename>" % argv0)
if len(sys.argv) < 3:
show_usage(sys.argv[0])
@@ -100,5 +121,8 @@ def show_usage(argv0):
show_directory(filename, offset)
else:
show_usage()
+ elif command == "list":
+ filename = sys.argv[2]
+ show_list(filename)
else:
show_usage(sys.argv[0])

0 comments on commit b23c753

Please sign in to comment.