Skip to content

Instantly share code, notes, and snippets.

@NWPlayer123
Last active March 24, 2018 08:54
Show Gist options
  • Save NWPlayer123/870f1d27a9be84e6259050d417cb7c25 to your computer and use it in GitHub Desktop.
Save NWPlayer123/870f1d27a9be84e6259050d417cb7c25 to your computer and use it in GitHub Desktop.
faster, checks for magic bytes
from zlib import decompress
from io import BytesIO
import sys
data = open(sys.argv[1], "rb").read()
#use this without making giant range() array
size = len(data) - 1
#better than a string ?
output = BytesIO()
#get byte 0 for the loop
char = data[0]
#cuz size counts down
pos = 0
num_chunks = 0
while size:
if char == "\x78":
if data[pos+1] in ["\x01", "\x9C", "\xDA"]:
try:
test = decompress(data[pos:])
output.write(test)
num_chunks += 1
except:
pass
pos += 1
char = data[pos]
size -= 1
output.seek(0)
print("num_chunks: %d" % num_chunks)
name = sys.argv[1].split(".")
name = name[:-1] + ["d"] + [name[-1]]
with open(".".join(name), "wb") as o:
o.write(output.read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment