From 3689a35410fc1eb57b6c4f9e41a068671e4e5e52 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Fri, 19 Jan 2024 21:36:13 -0700 Subject: [PATCH] Updated to decompile --- README | 5 +++++ get_pyc.py | 30 ++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 README 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)