是否可以将已编译的.pyc文件反编译为.py文件?

问题:是否可以将已编译的.pyc文件反编译为.py文件?

是否可以从.py文件生成的.pyc文件中获取一些信息?

Is it possible to get some information out of the .pyc file that is generated from a .py file?


回答 0

Uncompyle6适用于Python 3.x和2.7-推荐的选项,因为它是最新的工具,旨在统一早期的fork,并专注于自动化单元测试。在GitHub的页面有更多的细节。

  • 如果您使用的是Python 3.7+,则还可以尝试decompile3,它是Uncompyle6的一个分支,专注于3.7及更高版本。
  • 如果需要,确实会在这些项目上引发GitHub问题-两个都在一系列Python版本上运行单元测试套件

较旧的Uncompyle2仅支持Python 2.7。一段时间前,这对我很有效,可以将.pyc字节码反编译为.py,而unpyclib崩溃并发生异常。

使用所有这些工具,您可以获得包括变量名在内的代码,但没有注释。

Uncompyle6 works for Python 3.x and 2.7 – recommended option as it’s most recent tool, aiming to unify earlier forks and focusing on automated unit testing. The GitHub page has more details.

  • if you use Python 3.7+, you could also try decompile3, a fork of Uncompyle6 focusing on 3.7 and higher.
  • do raise GitHub issues on these projects if needed – both run unit test suites on a range of Python versions

With these tools, you get your code back including variable names and docstrings, but without the comments.

The older Uncompyle2 supports Python 2.7 only. This worked well for me some time ago to decompile the .pyc bytecode into .py, whereas unpyclib crashed with an exception.


回答 1

是的,您可以unpyclibpypi上找到它。

$ pip install unpyclib

比您可以反编译.pyc文件

$ python -m unpyclib.application -Dq path/to/file.pyc

Yes, you can get it with unpyclib that can be found on pypi.

$ pip install unpyclib

Than you can decompile your .pyc file

$ python -m unpyclib.application -Dq path/to/file.pyc

回答 2

您可以尝试Easy Python Decompiler。它基于Decompyle ++和Uncompyle2。它支持反编译python版本1.0-3.3

注意:我是上述工具的作者。

You may try Easy Python Decompiler. It’s based on Decompyle++ and Uncompyle2. It’s supports decompiling python versions 1.0-3.3

Note: I am the author of the above tool.