Skip to content

Instantly share code, notes, and snippets.

@NWPlayer123
Last active June 22, 2019 21:33
Show Gist options
  • Save NWPlayer123/9a512c85e868b1fc78eec9b77a6fd5dd to your computer and use it in GitHub Desktop.
Save NWPlayer123/9a512c85e868b1fc78eec9b77a6fd5dd to your computer and use it in GitHub Desktop.
for PSPGO firmwares, only based on 5.70
from zlib import decompress
from struct import unpack
from os.path import exists
from os import makedirs
import sys
with open(sys.argv[1], "rb") as f:
inputname = ".".join(sys.argv[1].split(".")[:-1])
assert f.read(4) == b"PSAR"
assert unpack("<I", f.read(4))[0] == 2 #version?
f.seek(0, 2)
fullsize = f.tell()
f.seek(8)
assert unpack("<I", f.read(4))[0] == (fullsize - 32) #size of file
assert unpack("<I", f.read(4))[0] == 1 #idk
assert f.read(16) == "\x00" * 16
print(f.read(16).rstrip("\x00")) #version string? 5.70
f.read(0x100) #???
while f.tell() < fullsize: #run til end cuz I can't find a size var
header = unpack("<I256s3I", f.read(0x110))
print("%08X %08X %08X %08X %s" % (header[0], header[2], header[3], header[4], header[1].rstrip("\x00")))
data = decompress(f.read(header[2]))
filename = inputname + "/" + header[1].rstrip("\x00").replace(":", "") #"flash0/XXX", "ipl/XXX"
path = "/".join(filename.split("/")[:-1])
if not exists(path):
makedirs(path)
with open(filename, "wb") as o:
o.write(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment