[*] Processing D:/PycharmProjects/gui_project/dist/auto_organize_gui.exe [*] Pyinstaller version: 2.1+ [*] Python version: 37 [*] Length of package: 9491710 bytes [*] Found 984 files in CArchive [*] Beginning extraction...please standby [*] Found 157 files in PYZ archive [*] Successfully extracted pyinstaller archive: D:/PycharmProjects/gui_project/dist/auto_organize_gui.exe
You can now use a Python decompiler on the pyc files within the extracted directory
预处理pyc文件修护校验头
deffind_main(pyc_dir): for pyc_file in os.listdir(pyc_dir): ifnot pyc_file.startswith("pyi-"
) and pyc_file.endswith("manifest"): main_file = pyc_file.replace(".exe.manifest", "") result = f"{pyc_dir}/{main_file}" if os.path.exists(result): return main_file
pyz_dir = f"{pyc_dir}/PYZ-00.pyz_extracted" for pyc_file in os.listdir(pyz_dir): if pyc_file.endswith(".pyc"): file = f"{pyz_dir}/{pyc_file}" break with open(file, "rb") as f: head = f.read(4) list(map(hex, head))
['0x42', '0xd', '0xd', '0xa']
校准入口类:
import shutil if os.path.exists("pycfile_tmp"): shutil.rmtree("pycfile_tmp") os.mkdir("pycfile_tmp") main_file_result = f"pycfile_tmp/{main_file}.pyc" with open(f"{pyc_dir}/{main_file}", "rb") as read, open(main_file_result, "wb") as write: write.write(head) write.write(b"\0"*12) write.write(read.read())
校准子类:
pyz_dir = f"{pyc_dir}/PYZ-00.pyz_extracted" for pyc_file in os.listdir(pyz_dir): pyc_file_src = f"{pyz_dir}/{pyc_file}" pyc_file_dest = f"pycfile_tmp/{pyc_file}" print(pyc_file_src, pyc_file_dest) with open(pyc_file_src, "rb") as read, open(pyc_file_dest, "wb") as write: write.write(read.read(12)) write.write(b"\0"*4) write.write(read.read())
开始反编译
from uncompyle6.bin import uncompile
ifnot os.path.exists("py_result"): os.mkdir("py_result") for pyc_file in os.listdir("pycfile_tmp"): sys.argv = ['uncompyle6', '-o', f'py_result/{pyc_file[:-1]}', f'pycfile_tmp/{pyc_file}'] uncompile.main_bin()