日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

Python编译与反编译.exe

發(fā)布時(shí)間:2023/12/14 python 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python编译与反编译.exe 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

文章目錄

  • 簡(jiǎn)介
  • 1. PyInstaller
    • 編譯為.exe
    • 反編譯.exe
  • 2. PyInstaller加密
    • 編譯為.exe
    • 反編譯.exe
  • 3. py2exe
    • 編譯為.exe
    • 反編譯.exe
  • Python 2.7 反編譯
  • 相關(guān)工具
  • 遇到的坑
  • 參考文獻(xiàn)

簡(jiǎn)介

Python 程序編譯為 .exe 使用 PyInstaller,反編譯使用 PyInstaller Extractor

或編譯使用 py2exe,反編譯使用 unpy2exe 或 uncompyle2

本文使用 Python 3




1. PyInstaller

編譯為.exe

安裝 Windows 虛擬環(huán)境管理包

pip install virtualenvwrapper-win

新建虛擬環(huán)境

mkvirtualenv compile

PyCharm 配置

進(jìn)入虛擬環(huán)境

workon compile

安裝

pip install pyinstaller

tool.py

from datetime import datetimedef now():return datetime.now()

main.py

import os from tool import nowif __name__ == '__main__':print(now())os.system('pause')

編譯為.exe

pyinstaller -F main.py

運(yùn)行 dist 文件夾里的 .exe



反編譯.exe

下載 pyinstxtractor.py,放到 .exe 同一目錄下

運(yùn)行

python pyinstxtractor.py main.exe

效果

生成了文件夾 xxx.exe_extracted,找到以下文件:

  • xxx.exe.manifest
  • xxx.pyc

使用 Python 反編譯在線工具,上傳 xxx.pyc 和 PYZ-00.pyz_extracted/tool.pyc


或使用 Uncompyle6

pip install uncompyle6 uncompyle6 main.pyc




2. PyInstaller加密

編譯為.exe

安裝

pip install tinyaes

打包

pyinstaller -F --key 123456 main.py



反編譯.exe

運(yùn)行

python pyinstxtractor.py main.exe

多了很多 Error

外層的 main.pyc 依然能使用 Python 反編譯在線工具


內(nèi)層的則加密了




3. py2exe

編譯為.exe

安裝

pip install py2exe

setup.py

from distutils.core import setup import py2exesetup(console=['main.py'])

打包

python setup.py py2exe

運(yùn)行 dist 文件夾里的 .exe



反編譯.exe

安裝

pip install unpy2exe

下載 unpy2exe.py,放到 .exe 同一目錄下

添加 main 方法

if __name__ == '__main__':unpy2exe('main.exe')

運(yùn)行

python unpy2exe.py

生成了 main.py.pyc

使用 Python 反編譯在線工具




Python 2.7 反編譯

安裝

git clone https://github.com/wibiti/uncompyle2.git cd uncompyle2 python setup.py install

反編譯.exe

python C:\Python27\Scripts\unpy2exe main.exe -v

運(yùn)行

python C:\Python27\Scripts\uncompyle2 -o main.py main.py.pyc

PyInstaller反編譯
python C:\Python27\Scripts\pyinstxtractor.exe main.py




相關(guān)工具

  • Py2ExeDumper
  • Easy Python Decompiler
  • pycdc




遇到的坑




參考文獻(xiàn)

  • PyInstaller Extractor GitHub
  • 談?wù)?Pyinstaller 的編譯和反編譯,如何保護(hù)你的代碼
  • Python打包為exe——pyinstaller
  • Python反編譯 - 在線工具
  • How to decompile an exe file compiled by py2exe
  • 總結(jié)

    以上是生活随笔為你收集整理的Python编译与反编译.exe的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。