exe反编译为python语言_如何反编译Python写的exe到py
參考鏈接:
https://blog.csdn.net/qq_44198436/article/details/97314626?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task
https://www.cnblogs.com/pcat/p/8990482.html
https://www.cnblogs.com/pcat/p/11625300.html
準(zhǔn)備工作:
1. 下載pyinstxtractor.py(百度上搜):https://github.com/extremecoders-re/pyinstxtractor
2. 安裝uncompyle6:?pip install uncompyle6
3. 下載16進(jìn)制編輯器:https://www.jb51.net/softs/557257.html#downintro2
為了驗(yàn)證效果,接下來從創(chuàng)建py開始一步步看結(jié)果。
第一步:自己寫一個(gè)py打包成exe -- target_exe.py(簡單的兩數(shù)相加)
#!/usr/bin/env python#_*_ coding: UTF-8 _*_
"""=================================================
@Project -> File : Python-20210127 -> target_exe.py.py
@IDE : PyCharm
@Author : Aimee
@Date : 2021/2/23 8:57
@Desc :
================================================="""
importsysdefmain():print("target_exe started") #main()函數(shù)開始了
argc =len(sys.argv)if argc == 3:
a= int(sys.argv[1])
b= int(sys.argv[2])
result= a + b #兩數(shù)相加
print("a + b =", result)if a < 0 or a > 100: #對(duì)a的作用域進(jìn)行判斷
print("a is not in [0, 100]")if a > 0 and b >0:print("a and b >0")if __name__ == '__main__':
main()
View Code
target_exe.py->target_exe.exe
pyinstaller -F target_exe.py
將target_exe.py重命名為target_exe_origin.py
第二步:解壓exe
將pyinstxtractor.py放在與exe同級(jí)目錄下,運(yùn)行
python pyinstxtractor.py target_exe.exe
會(huì)在當(dāng)前目錄生成一個(gè)target_exe.exe_extracted文件夾,里面會(huì)有一些沒有后綴的文件名,target_exe就是我們需要進(jìn)行反編譯的文件。在正向編譯過程中,生成的pyc會(huì)把python版本信息和時(shí)間戳去掉,但是反編譯的時(shí)候我們需要將其補(bǔ)齊。
注意到在target_exe.exe_extracted還存在一個(gè)沒有后綴名的文件struct,用16進(jìn)制編輯器打開struct和target_exe文件。
兩個(gè)文件都有E3,可以看到struct在E3的前面還有一段,應(yīng)該就是Python版本和時(shí)間戳了,將前面一段復(fù)制到target_exe中,直接在16進(jìn)制編輯器里面復(fù)制就好了。
保存,然后重命名target_exe為target_exe.pyc。
第三步:反編譯pyc文件,得到target_exe.py
uncompyle6 -o target_exe.py target_exe.pyc
得到target_exe.py,那么現(xiàn)在將得到的target_exe.py和原本寫的target_exe_origin.py進(jìn)行對(duì)比,看看結(jié)果
可以發(fā)現(xiàn),注釋沒有了,雙引號(hào)變單引號(hào),if-and變成兩個(gè)if,功能沒啥變化。
OK,反編譯就講到這里。
總結(jié)
以上是生活随笔為你收集整理的exe反编译为python语言_如何反编译Python写的exe到py的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 时间序列预测-入门概念
- 下一篇: python中continue用法_Py