别再问我exe反编译成Python脚本了!
大数据DT
共 8311字,需浏览 17分钟
·
2021-08-29 03:56
导读:我曾经写了一篇:别再问我Python打包成exe了!(终极版),相信解决了不少小伙伴的Pyinstaller打包问题。
pyinstaller -Fw --icon=h.ico auto_organize_gui.py --add-data="h.ico;/"
pyinstaller -w --icon=h.ico auto_organize_gui.py --add-data="h.ico;."
通过 pyinstxtractor.py 脚本提取pyc文件 通过 pyi-archive_viewer 工具提取pyc文件
Python pyinstxtractor.py auto_organize_gui.exe
pyi-archive_viewer auto_organize.exe
U: go Up one level
O <name>: open embedded archive name
X <name>: extract name
Q: quit
pip install uncompyle6
uncompyle6 xxx.pyc>xxx.py uncompyle6 -o xxx.py xxx.pyc
uncompyle6 auto_organize.cpython-37.pyc>auto_organize.py
uncompyle6 auto_organize_gui.exe_extracted/auto_organize_gui.pyc>auto_organize_gui.py
uncompyle6 auto_organize_gui.exe_extracted/PYZ-00.pyz_extracted/auto_organize.pyc > auto_organize.py
import os
import sys
import pyinstxtractor
exe_file = r"D:/PycharmProjects/gui_project/dist/auto_organize_gui.exe"
sys.argv = ['pyinstxtractor', exe_file]
pyinstxtractor.main()
# 恢复当前目录位置
os.chdir("..")
[*] 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
def find_main(pyc_dir):
for pyc_file in os.listdir(pyc_dir):
if not 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
pyc_dir = os.path.basename(exe_file)+"_extracted"
main_file = find_main(pyc_dir)
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
if not 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()
pyinstaller -Fw --icon=h.ico auto_organize_gui.py --add-data="h.ico;/" --key 123456
pip install tinyaes
exe_file = r"D:/PycharmProjects/gui_project/dist/auto_organize_gui.exe"
uncompyle_exe(exe_file, True)
评论