diff --git a/README b/README new file mode 100644 index 0000000..b4fe2ad --- /dev/null +++ b/README @@ -0,0 +1,5 @@ +Steps: + +1. Extract PYZ from executable with `pyi-archive_viewer` +2. Run get_co.py on the PYZ file to extract all code objects embedded in the PYZ file +3. Run get_pyc.py on the extracted directory to get the pyc and py files for the co diff --git a/get_pyc.py b/get_pyc.py index 893a843..e2212aa 100755 --- a/get_pyc.py +++ b/get_pyc.py @@ -52,18 +52,28 @@ def code_to_bytecode(code, mtime=0, source_size=0): if len(sys.argv) < 3: - print("Usage %s " % sys.argv[0]) + print("Usage %s " % sys.argv[0]) sys.exit(1) in_path = Path(sys.argv[1]) -out_path = Path(sys.argv[2]) +pyc_path = Path(sys.argv[2]) +py_path = Path(sys.argv[3]) for path in in_path.rglob("*.co"): - with open(str(path), "rb") as file: - data = file.read() - co = marshal.loads(data) - pyc = code_to_bytecode(co, time.time()) - out_file = out_path / path.relative_to(in_path) - out_file.parent.mkdir(parents=True, exist_ok=True) - with open(str(out_file), "wb") as file: - file.write(pyc) + try: + co = marshal.loads(path.read_bytes()) + pyc = code_to_bytecode(co, time.time()) + + pyc_file = pyc_path / path.relative_to(in_path).with_suffix(".pyc") + pyc_file.parent.mkdir(parents=True, exist_ok=True) + + with open(str(pyc_file), "wb") as file: + file.write(pyc) + + py_file = py_path / path.relative_to(in_path).with_suffix(".py") + py_file.parent.mkdir(parents=True, exist_ok=True) + + with open(str(py_file), 'w') as decompiled: + uncompyle6.main.decompile_file(str(pyc_file), decompiled) + except: + print("Failed to decompile %s" % path)