让我说我有:
>>> def test(a):
>>> print a
现在,我想探索测试在编译形式中的样子。
>>> test.func_code.co_code
'|\x00\x00GHd\x00\x00S'
我可以使用 dis 模块获取反汇编表单:
>>> import dis
>>> dis.dis(test)
2 0 LOAD_FAST 0 (a)
3 PRINT_ITEM
4 PRINT_NEWLINE
5 LOAD_CONST 0 (None)
8 RETURN_VALUE
是否有一个开源和维护的反编译器可以用来将字节码重新转换成可读的python代码?
更新:感谢建议反编译,但它已过时(python2.3),没有人再维护它了。 python2.5或更高版本有什么用吗?
答案 0 :(得分:6)
答案 1 :(得分:5)
从github获取uncompyle2! :)
答案 2 :(得分:3)
现在还有uncompyle6用Python编写,pycdc用C ++编写。
这两个版本都处理Python字节码的几个版本,包括Python 2版本和Python 3版本。
答案 3 :(得分:2)
Decompyle是一个python反汇编程序 转换Python的反编译器 字节码(.pyc或.pyo)重新进入 等效的Python源码。验证 生成的代码(重新编译)是 也可以。
答案 4 :(得分:2)
Uncompyle2使用Python 2.7为我工作。
https://github.com/wibiti/uncompyle2
快速如何使用uncompyle2,安装它然后
>>>import uncompyle2
>>> with open("decompiled.py","wb") as f:
... uncompyle2.uncompyle_file("compiled.pyc",f)
它将在decompile.py中生成源代码
答案 5 :(得分:1)
除了DevC所写的内容:
Uncompyle2适用于Python 2.7
,您也可以从命令行解编译:
$ uncompyle2 compiled.pyc>> source.uncompyle2.py
安装Uncompyle2,执行
$ git clone https://github.com/wibiti/uncompyle2
$ cd uncompyle2
$ sudo ./setup.py install