将 Python 打包的 exe 进行反编译
2021/4/20 12:26:53
本文主要是介绍将 Python 打包的 exe 进行反编译,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Python 打包成 exe 之后,是否能从二进制文件中恢复出源代码?没有加密的话是可以的。
首先需要解包。
直接从 github 上下载就行:https://github.com/countercept/python-exe-unpacker
使用也简单:python pyinstxtractor.py xxx.exe
解包后,得到 xxx.exe_extracted 就是所有的 pyc 文件了。
找到 xxx.exe_extracted\struct 中的 pyc 签名信息:
然后可以并使用下面的脚本进行拼接(PYZ-00.pyz_extracted 里面的 pyc 只缺中间一部分):
import os import argparse parser =argparse.ArgumentParser() parser.add_argument('--filename', '-f', type=str, help="file name of the file to be modified!") args = parser.parse_args() if args.filename: print("filename: " + args.filename) if os.access(args.filename, os.W_OK): print("- processing...") else: print("- access is denied! exit!") exit(0) else: print("-h for help!") exit(0) structBytes=b'\x70\x79\x69\x30\x10\x01\x00\x00' with open(args.filename, "rb") as f: bytes = f.read() bytes=bytes[:8]+structBytes+bytes[12:] with open(args.filename, "wb") as g: g.write(bytes) print("- successed!")
多个文件的话。。。再叠加个批处理吧,顺便直接用 uncompyle6 把 pyc 反编译成 python 源代码 = =
set "path" "C:\DevApp\Anaconda3\Scripts;C:\DevApp\Anaconda3;C:\DevApp\Anaconda3\DLLs;C:\DevApp\Anaconda3\\Library\bin;%path%" /m @echo off set here=%~dp0 pushd %here% cd xxx.exe_extracted\PYZ-00.pyz_extracted for /f "delims=" %%i in ('dir /s/b "*.pyc"') do ( python.exe %here%\cooking.py -f %%i start uncompyle6 -o . %%i ) popd
这里之所以用 start,是因为有些 pyc 没法直接反编译,这样的话 script 会被卡住。用 start 开始新进程,并行处理,有一两个卡住也没关系。
最后发现有 4 个没法反编译,从文件大小可以看出来:
还好,可以从文件名猜到用了什么库。
这篇关于将 Python 打包的 exe 进行反编译的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python