Skip to content

Instantly share code, notes, and snippets.

@penguino118
Created May 3, 2024 19:09
Show Gist options
  • Save penguino118/e8e2095fdd1a9ddf37f37625c414b255 to your computer and use it in GitHub Desktop.
Save penguino118/e8e2095fdd1a9ddf37f37625c414b255 to your computer and use it in GitHub Desktop.
Auto Modellista BIN Extractor
import os
import sys
import struct
def wu08(value):
return struct.pack("<B", value)
def int32_read(buf, offset):
return struct.unpack("<i", buf[offset:offset+4])[0]
def pzz_decompress(b): # by infval # https://github.com/infval/pzzcompressor_jojo/blob/master/pzz_comp_jojo.py
bout = bytearray()
size_b = len(b) // 2 * 2
cb = 0 # Control bytes
cb_bit = -1
i = 0
while i < size_b:
if cb_bit < 0:
cb = b[i + 0]
cb |= b[i + 1] << 8
cb_bit = 15
i += 2
continue
compress_flag = cb & (1 << cb_bit)
cb_bit -= 1
if compress_flag:
c = b[i + 0]
c |= b[i + 1] << 8
offset = (c & 0x7FF) * 2
if offset == 0:
break # End of the compressed data
count = (c >> 11) * 2
if count == 0:
i += 2
c = b[i + 0]
c |= b[i + 1] << 8
count = c * 2
index = len(bout) - offset
for j in range(count):
bout.append(bout[index + j])
else:
bout.extend(b[i: i + 2])
i += 2
return bout
def get_ext(file):
test = int32_read(file, 0x4)
if test == 4: return "amo"
test = int32_read(file, 0x0)
if test == 843925844: return "tm2"
else: return "bin"
filepath = sys.argv[1]
with open(filepath, "rb") as input_file:
buf = input_file.read()
funny = pzz_decompress(buf)
filename = os.path.basename(filepath)[:-4]
working = True
read_offset = 0x0
os.mkdir(filename)
index = 0
while working:
file_offset = int32_read(funny, read_offset)
if file_offset == -1:
break
file_end = int32_read(funny, read_offset+0x4)
if file_end == -1:
file_end = len(funny)
file = funny[file_offset:file_end]
type = get_ext(file)
with open(f"{filename}/file{index:04}_{hex(file_offset)}.{type}", "wb") as out_file:
for byte in bytearray(file):
aah = wu08(byte)
out_file.write(aah)
read_offset += 0x4
index += 1
if file_end == -1: working = False
print(int32_read(funny, 0x0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment