[*] 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文件修护校验头
1 2 3 4 5 6 7 8 9 10 11 12
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 withopen(file, "rb") as f: head = f.read(4) list(map(hex, head))
1 2
['0x42', '0xd', '0xd', '0xa']
校准入口类:
1 2 3 4 5 6 7 8 9 10
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" withopen(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())
校准子类:
1 2 3 4 5 6 7 8 9 10
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) withopen(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())
🛬开始反编译
1 2 3 4 5 6 7 8 9
from uncompyle6.binimport 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()
# 提取exe中的pyc import os import sys import pyinstxtractor from uncompyle6.binimport uncompile import shutil
# 预处理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 else: print("子文件中没有找到pyc文件,无法反编译!") return withopen(file, "rb") as f: head = f.read(4)
if os.path.exists("pycfile_tmp"): shutil.rmtree("pycfile_tmp") os.mkdir("pycfile_tmp") main_file_result = f"pycfile_tmp/{main_file}.pyc" withopen(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())
ifnot complie_child: return for pyc_file in os.listdir(pyz_dir): ifnot pyc_file.endswith(".pyc"): continue pyc_file_src = f"{pyz_dir}/{pyc_file}" pyc_file_dest = f"pycfile_tmp/{pyc_file}" print(pyc_file_src, pyc_file_dest) withopen(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())
os.mkdir("py_result/other") for pyc_file in os.listdir("pycfile_tmp"): if pyc_file==main_file+".pyc": continue sys.argv = ['uncompyle6', '-o', f'py_result/other/{pyc_file[:-1]}', f'pycfile_tmp/{pyc_file}'] uncompile.main_bin()