Skip to content

Instantly share code, notes, and snippets.

@marcan
Created November 15, 2023 02:32
Show Gist options
  • Save marcan/3b7a596816cca9b26c1d108c95a3e730 to your computer and use it in GitHub Desktop.
Save marcan/3b7a596816cca9b26c1d108c95a3e730 to your computer and use it in GitHub Desktop.
import sys, struct, subprocess
fd = open(sys.argv[1], "rb")
fd.seek(0x3c, 0)
hdr = fd.read(12)
magic, blocksize = struct.unpack(">4sQ", hdr)
assert magic == b"pbzx"
outfd = open(sys.argv[2], "wb")
while True:
hdr = fd.read(16)
if not hdr:
break
uncompressed_size, compressed_size = struct.unpack(">QQ", hdr)
print(f"{compressed_size:#x} -> {uncompressed_size:#x}")
blk = fd.read(compressed_size)
print(f"@{fd.tell():#x}")
if uncompressed_size == compressed_size:
outfd.write(blk)
else:
ret = subprocess.run(["xzcat"], input=blk, capture_output=True, check=True)
outfd.write(ret.stdout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment