Skip to content

Instantly share code, notes, and snippets.

@xyzz
Created August 20, 2013 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xyzz/3b2c88f6b6e38c907c47 to your computer and use it in GitHub Desktop.
Save xyzz/3b2c88f6b6e38c907c47 to your computer and use it in GitHub Desktop.
# all <3 to http://mce.do.am/forum/25-36-1
import sys
import os
def read_int(fin, count):
return int.from_bytes(fin.read(count), byteorder="little")
def read_uint32(fin):
return read_int(fin, 4)
PADDING = 0x800
def main():
if len(sys.argv) != 3:
print("Usage: deuni.py source.uni output-dir/")
return
fin = open(sys.argv[1], "rb")
if fin.read(4) != b"UNI2":
print("Invalid file")
return
unk = fin.read(4)
files_count = read_uint32(fin)
table_start = read_uint32(fin) * PADDING
data_start = read_uint32(fin) * PADDING
fin.seek(table_start)
files = []
for x in range(files_count):
unk = read_uint32(fin)
sector_start = read_uint32(fin)
sector_size = read_uint32(fin)
file_size = read_uint32(fin)
file_start = data_start + sector_start * PADDING
files.append((file_start, file_size))
num = 0
for file_start, file_size in files:
fin.seek(file_start)
fout = open(os.path.join(sys.argv[2], str(num)), "wb")
fout.write(fin.read(file_size))
fout.close()
num += 1
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment