Created
September 10, 2018 09:39
-
-
Save Lattyware/c7ae85998f62a5d1a985de6bfc662048 to your computer and use it in GitHub Desktop.
Automates some of the legwork for dealing with ZiX-12B archives with unrpa.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
import subprocess | |
import re | |
import os | |
import sys | |
import platform | |
import StringIO | |
try: | |
import uncompyle6 | |
except ImportError: | |
print("You need uncompyle6 - do a 'pip install uncompyle6' in your python 2.x environment.") | |
sys.exit(1) | |
try: | |
import _string | |
except ImportError: | |
print("You need the '_string' module from the source. Find '_string.pyd'/'_string.so' for your platform.") | |
sys.exit(1) | |
archive, extraction_path, loader = sys.argv[1:] | |
if platform.system() == "Windows": | |
python3 = ["py", "-3"] | |
else: | |
python3 = ["python3"] | |
with open(archive, "rb") as f: | |
line = f.readline() | |
parts = line.split() | |
raw_offset = parts[-1] | |
decompiled = StringIO.StringIO() | |
uncompyle6.decompile_file(loader, outstream=decompiled) | |
match = re.search(r"verificationcode = _string.sha1\('(.*)'\)", decompiled.getvalue()) | |
verification_code = match.group(1).encode("ascii", "ignore") | |
decompiled.close() | |
offset = _string.offset(raw_offset) | |
key = _string.sha1(verification_code) | |
paths = subprocess.check_output( | |
python3 + ["unrpa", "-mp", extraction_path, archive, "-o", str(offset), "-k", str(key), "-v"]) | |
for path in paths.split(os.linesep): | |
if path: | |
path = os.path.join(extraction_path, path) | |
with open(path, "rb") as f: | |
decoded = _string.run(f.read(64), key) + f.read() | |
with open(path, "wb") as f: | |
f.write(decoded) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please note this is a Python 2 script - it will need to be run in the same directory as
_string.pyd
/_string.so
, and on a version of Python compatible with the one used for the Ren'Py project that module was originally from.To run, place alongside
_string
,unrpa
and then run, providing the path to the archive, the path to the extraction folder, and the path to theloader.pyo
file from the Ren'Py project the archive is from. E.g:On Linux:
python2 decoder.py archive.rpa extracted loader.pyo
On Windows:
py -2 decoder.py archive.rpa extracted loader.pyo