一、py打包成exe
1.1、安装pyinstaller
pip install pyinstaller
1.2、打包
源文件:test.py  打包:pyinstaller -n name -F xxx.py(或者pyinstaller -n name -D xxx.py)
- -F:在dist目录下生成单个exe文件(常用)
- -D:在dist目录下生成目录文件
- -n:指定生成后的文件名,如果没有,默认为源文件名
示例一:-F打包生成test-exe.exe  示例二:-D打包生成test目录  最后完成,打包后的文件在dist目录下  测试执行exe文件,完成 
二、exe解包出py文件
2.1、工具下载
-
1、pyinstxtractor.py下载地址:https://github.com/extremecoders-re/pyinstxtractor -
2、安装uncompyle6:pip install uncompyle6 -
3、16进制编辑器下载:自行网上搜索下载或使用HxD
2.2、exe–>pyc
 python pyinstxtractor.py xxx.exe(exe文件)  解压出xxx.exe_extracted目录,目录下存在struct.pyc和xxx.pyc文件(xxx和exe包名相同) 
2.3、修改pyc文件
注:如果python版本为3.9及以上版本,无需进行这一步骤
修改目录下的struct.pyc和xxx.pyc
用16进制编译器打开这两个文件,将struct.pyc的E3前的内容替换掉xxx.pyc的E3前的内容
拷贝struct.pyc文件的E3前的内容  复制到xxx.pyc的E3前,保存  
2.4、pyc–>py
示例测试,uncompyle6反编译python3.9版本生成的文件失败,反编译出的结果为空,但是python3.8版本及一下反编译没问题
1、python3.8版本及以下:
2、python3.9版本:
- 使用pyc在线工具:https://tool.lu/pyc/
- 此处选择的pyc文件无需修改,直接使用pyinstxtractor.py生成的pyc文件
 注:有网络文档说pycdc可以反编译3.9版本以上的pyc文件,有兴趣可以测试一下 ? ? ? -----------日常记录---------------
|