python怎样进行反编译
python进行反编译的方法:可以利用第三方库uncompyle来实现。该库可以将代码反编译成字节码指令和源代码。例如:【uncompyle_file('test.pyc',fp,showasm=1,showast=0)】。
1、使用第三方库uncompyle
这个库可以将代码反编译成字节码指令和源代码
(推荐教程:Python入门教程)
举例:
from uncompyle2 import * fp = open("code.txt","wb") uncompyle_file('test.pyc',fp,showasm=1,showast=0) fp.close()
2、使用python自带的dis模块
>>> import dis >>> def inplace_add(): ... a = 0 ... a += 1 ... >>> def add_and_assign(): ... a = 0 ... a = a + 1 ... >>> dis.dis(inplace_add) 2 0 LOAD_CONST 1 (0) 3 STORE_FAST 0 (a) 3 6 LOAD_FAST 0 (a) 9 LOAD_CONST 2 (1) 12 INPLACE_ADD 13 STORE_FAST 0 (a) 16 LOAD_CONST 0 (None) 19 RETURN_VALUE >>> dis.dis(add_and_assign) 2 0 LOAD_CONST 1 (0) 3 STORE_FAST 0 (a) 3 6 LOAD_FAST 0 (a) 9 LOAD_CONST 2 (1) 12 BINARY_ADD 13 STORE_FAST 0 (a) 16 LOAD_CONST 0 (None) 19 RETURN_VALUE
来源:PY学习网:原文地址:https://www.py.cn/article.html