Skip to content

Instantly share code, notes, and snippets.

@NWPlayer123
Created September 13, 2017 01:55
Show Gist options
  • Save NWPlayer123/a5599fa0fe6b4f8455f78a591800e977 to your computer and use it in GitHub Desktop.
Save NWPlayer123/a5599fa0fe6b4f8455f78a591800e977 to your computer and use it in GitHub Desktop.
Metroid Samus Returns pkg files
# -------------------------------------
# data is aligned to nearest 0x80
# header size is normally 0x7C aka
# 0x80 aligned, minus 4
# (doesn't include 4 bytes for the header size)
# then data size starting at [header_size + 4]
# then number of files, read 12 bytes each and seek
# 12 = hash(?), start pos, end pos (from start of file)
# then just seek to [header_size + 4] and extract files
from struct import pack, unpack
from os.path import exists
from os import mkdir
import sys
#sys.argv.append("metroidqueendeathpowerbomb.pkg")
with open(sys.argv[1], "rb") as f:
base = ".".join(sys.argv[1].split(".")[:-1])
header_size = unpack("<I", f.read(4))[0]
data_size = unpack("<I", f.read(4))[0]
file_count = unpack("<I", f.read(4))[0]
info = []
for i in range(file_count):
data = unpack("<3I", f.read(12))
info.append(data)
print("%08X %08X %08X" % data)
if not exists(base):
mkdir(base)
for i in info:
f.seek(i[1])
#time to do some guessing
magic = f.read(4)
f.seek(i[1])
if magic == b"CWAV":
with open(base + "/%08X.bcwav" % i[1], "wb") as o:
o.write(f.read(i[2] - i[1]))
elif magic == b"MANM":
with open(base + "/%08X.anim" % i[1], "wb") as o:
o.write(f.read(i[2] - i[1]))
elif magic == b"MCAN":
with open(base + "/%08X.camera" % i[1], "wb") as o:
o.write(f.read(i[2] - i[1]))
elif magic == b"MMDL":
with open(base + "/%08X.model" % i[1], "wb") as o:
o.write(f.read(i[2] - i[1]))
elif magic == b"MTXT":
with open(base + "/%08X.texture" % i[1], "wb") as o:
o.write(f.read(i[2] - i[1]))
else:
with open(base + "/%08X.bin" % i[1], "wb") as o:
o.write(f.read(i[2] - i[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment