METADATA 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. Metadata-Version: 2.4
  2. Name: decompyle3
  3. Version: 3.9.3
  4. Summary: Python cross-version byte-code library and disassembler
  5. Author-email: Rocky Bernstein <rb@dustyfeet.com>
  6. License-Expression: GPL-3.0-or-later
  7. Project-URL: Homepage, https://github.com/rocky/python-decompile3
  8. Project-URL: Downloads, https://github.com/rocky/python-decompile3/releases
  9. Keywords: Python bytecode,bytecode,disassembler
  10. Classifier: Development Status :: 5 - Production/Stable
  11. Classifier: Intended Audience :: Developers
  12. Classifier: Programming Language :: Python
  13. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  14. Classifier: Programming Language :: Python :: 3.7
  15. Classifier: Programming Language :: Python :: 3.8
  16. Classifier: Programming Language :: Python :: 3.9
  17. Classifier: Programming Language :: Python :: 3.10
  18. Classifier: Programming Language :: Python :: 3.11
  19. Classifier: Programming Language :: Python :: 3.12
  20. Classifier: Programming Language :: Python :: 3.13
  21. Classifier: Programming Language :: Python :: Implementation :: PyPy
  22. Description-Content-Type: text/x-rst
  23. License-File: COPYING
  24. Requires-Dist: click
  25. Requires-Dist: spark-parser<1.9.2,>=1.8.9
  26. Requires-Dist: xdis<6.3,>=6.1.0
  27. Provides-Extra: dev
  28. Requires-Dist: pre-commit; extra == "dev"
  29. Requires-Dist: pytest; extra == "dev"
  30. Dynamic: license-file
  31. |buildstatus| |Pypi Installs| |Latest Version| |Supported Python Versions|
  32. |packagestatus|
  33. .. contents::
  34. decompyle3
  35. ==========
  36. A native Python cross-version decompiler and fragment decompiler.
  37. A reworking of uncompyle6_.
  38. I gave a talk on this at `BlackHat Asia 2024 <https://youtu.be/H-7ZNrpsV50?si=nOaixgYHr7RbILVS>`_.
  39. Introduction
  40. ------------
  41. *decompyle3* translates Python bytecode back into equivalent Python
  42. source code. It accepts bytecodes from Python version 3.7 on.
  43. For decompilation of older Python bytecode, see uncompyle6_.
  44. Why this?
  45. ---------
  46. Uncompyle6 is awesome, but it has a fundamental problem in the way
  47. it handles control flow. In the early days of Python, when there was
  48. little optimization and code was generated in a very template-oriented way, figuring out control flow structures could be done by simply looking at code patterns.
  49. Over the years, more code optimization, specifically around handling jumps, has made it harder to support detecting control flow strictly
  50. from code patterns. This was noticed as far back as Python 2.4 (2004), but since this is a difficult problem, so far it hasn't been tackled
  51. in a satisfactory way.
  52. The initial attempt to fix to this problem was to add markers in the
  53. instruction stream, initially this was a ``COME_FROM`` instruction, and
  54. then use that in pattern detection.
  55. Over the years, I've extended that to be more specific, so
  56. ``COME_FROM_LOOP`` and ``COME_FROM_WITH`` were added. And I added checks
  57. at grammar-reduce time to make try to make sure jumps match with
  58. supposed ``COME_FROM`` targets.
  59. However, all of this is complicated, not robust, has greatly slowed down deparsing and is not really tenable.
  60. In this project, we began rewriting and refactoring the grammar.
  61. However, even this isn't enough. Control flow needs
  62. to be addressed by using dominators and reverse-dominators, which the python-control-flow_ project can give.
  63. This I am *finally* slowly doing in yet another non-public project. It
  64. is a lot of work. Funding in the form of sponsorship while greatly
  65. appreciated isn't commensurate with the amount of effort, and
  66. currently I have a full-time job. So it may take time before it is
  67. available publicly, if at all.
  68. Requirements
  69. ------------
  70. The code here can be run on Python versions 3.7 or 3.8. The bytecode
  71. files it can read have been tested on Python bytecodes from versions
  72. 3.7 and 3.8.
  73. Installation
  74. ------------
  75. You can install from PyPI using the name ``decompyle3``::
  76. pip install decompyle3
  77. To install from source code, this project uses setup.py, so it follows the standard Python routine::
  78. $ pip install -e . # set up to run from source tree
  79. or::
  80. $ python setup.py install # may need sudo
  81. A GNU Makefile is also provided, so :code:`make install` (possibly as root or
  82. sudo) will do the steps above.
  83. Running Tests
  84. -------------
  85. ::
  86. make check
  87. A GNU makefile has been added to smooth over setting up and running the right
  88. command, and running tests from fastest to slowest.
  89. If you have remake_ installed, you can see the list of all tasks
  90. including tests via :code:`remake --tasks`
  91. Usage
  92. -----
  93. Run
  94. ::
  95. $ decompyle3 *compiled-python-file-pyc-or-pyo*
  96. For usage help:
  97. ::
  98. $ decompyle3 -h
  99. Verification
  100. ------------
  101. If you want Python syntax verification of the correctness of the
  102. decompilation process, add the :code:`--syntax-verify` option. However since
  103. Python syntax changes. You should use this option if the bytecode is
  104. the right bytecode for the Python interpreter that will be checking
  105. the syntax.
  106. You can also cross-compare the results with another Python decompiler
  107. like unpyc37_ . Since they work differently, bugs here often aren't in
  108. that, and vice versa.
  109. There is an interesting class of these programs that is readily
  110. available to give stronger verification: those programs that, when run, test themselves. Our test suite includes these.
  111. And Python comes with another set of programs like this: its test
  112. suite for the standard library. We have some code in :code:`test/stdlib` to
  113. facilitate this kind of checking too.
  114. Known Bugs/Restrictions
  115. -----------------------
  116. **We support only released versions, not candidate versions.** Note however
  117. that the magic of a released version is usually the same as the *last* candidate version prior to release.
  118. We also don't handle PJOrion_ or otherwise obfuscated code. For
  119. PJOrion try: PJOrion Deobfuscator_ to unscramble the bytecode to get
  120. valid bytecode before trying this tool; pydecipher_ might help with that.
  121. This program can't decompile Microsoft Windows EXE files created by
  122. Py2EXE_, although we can probably decompile the code after you extract
  123. the bytecode properly. `Pydeinstaller <https://github.com/charles-dyfis-net/pydeinstaller>`_ may help with unpacking Pyinstaller bundlers.
  124. Handling pathologically long lists of expressions or statements is slow. We don't handle Cython_ or MicroPython, which don't use bytecode.
  125. There are numerous bugs in decompilation. And that's true for every
  126. other CPython decompilers I have encountered, even the ones that
  127. claimed to be "perfect" on some particular version like 2.4.
  128. As Python progresses, decompilation also gets harder because the
  129. compilation is more sophisticated and the language itself is more
  130. sophisticated. I suspect that attempts there will be fewer ad-hoc
  131. attempts like unpyc37_ (which is based on a 3.3 decompiler) simply
  132. because it is harder to do so. The good news, at least from my
  133. standpoint, is that I think I understand what's needed to address the
  134. problems in a more robust way. But right now, until such time as
  135. the project is better funded, I do not intend to make any serious effort
  136. to support Python versions 3.8 or 3.9, including bugs that might come
  137. in. I imagine at some point I may be interested in it.
  138. You can easily find bugs by running the tests against the standard
  139. test suite that Python uses to check itself. At any given time, there are
  140. dozens of known problems that are pretty well isolated and that could
  141. be solved if one were to put in the time to do so. The problem is that
  142. there aren't that many people who have been working on bug fixing.
  143. You may run across a bug, that you want to report. Please do so. But
  144. be aware that it might not get my attention for a while. If you
  145. sponsor or support the project in some way, I'll prioritize your
  146. issues above the queue of other things I might be doing instead. In
  147. rare situations, I can do a hand decompilation of bytecode for a fee.
  148. However, this is expensive, usually beyond what most people are willing
  149. to spend.
  150. See Also
  151. --------
  152. * https://github.com/andrew-tavera/unpyc37/ : indirect fork of https://code.google.com/archive/p/unpyc3/ The above projects use a different decompiling technique than what is used here. Instructions are walked. Some instructions use the stack to generate strings, while others don't. Because control flow isn't dealt with directly, it too suffers the same problems as the various ``uncompyle`` and ``decompyle`` programs.
  153. * https://github.com/rocky/python-xdis : Cross Python version disassembler
  154. * https://github.com/rocky/python-xasm : Cross Python version assembler
  155. * https://github.com/rocky/python-decompile3/wiki : Wiki Documents that describe the code and aspects of it in more detail
  156. .. |buildstatus| image:: https://dl.circleci.com/status-badge/img/gh/rocky/python-decompile3/tree/master.svg?style=svg
  157. :target: https://dl.circleci.com/status-badge/redirect/gh/rocky/python-decompile3/tree/master
  158. .. |packagestatus| image:: https://repology.org/badge/vertical-allrepos/python:uncompyle6.svg
  159. :target: https://repology.org/project/python:decompyle3/versions
  160. .. _Cython: https://en.wikipedia.org/wiki/Cython
  161. .. _MicroPython: https://micropython.org
  162. .. _uncompyle6: https://pypi.python.org/pypi/uncompyle6
  163. .. _python-control-flow: https://github.com/rocky/python-control-flow
  164. .. _trepan: https://pypi.python.org/pypi/trepan3k
  165. .. _compiler: https://pypi.python.org/pypi/spark_parser
  166. .. _HISTORY: https://github.com/rocky/python-decompile3/blob/master/HISTORY.md
  167. .. _debuggers: https://pypi.python.org/pypi/trepan3k
  168. .. _remake: https://bashdb.sf.net/remake
  169. .. _unpyc37: https://github.com/andrew-tavera/unpyc37/
  170. .. _this: https://github.com/rocky/python-decompile3/wiki/Deparsing-technology-and-its-use-in-exact-location-reporting
  171. .. |TravisCI| image:: https://travis-ci.org/rocky/python-decompile3.svg
  172. :target: https://travis-ci.org/rocky/python-decompile3
  173. .. |CircleCI| image:: https://circleci.com/gh/rocky/python-decompile3.svg?style=svg
  174. :target: https://circleci.com/gh/rocky/python-decompile3
  175. .. _PJOrion: http://www.koreanrandom.com/forum/topic/15280-pjorion-%D1%80%D0%B5%D0%B4%D0%B0%D0%BA%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5-%D0%BA%D0%BE%D0%BC%D0%BF%D0%B8%D0%BB%D1%8F%D1%86%D0%B8%D1%8F-%D0%B4%D0%B5%D0%BA%D0%BE%D0%BC%D0%BF%D0%B8%D0%BB%D1%8F%D1%86%D0%B8%D1%8F-%D0%BE%D0%B1%D1%84
  176. .. _Deobfuscator: https://github.com/extremecoders-re/PjOrion-Deobfuscator
  177. .. _Py2EXE: https://en.wikipedia.org/wiki/Py2exe
  178. .. |Supported Python Versions| image:: https://img.shields.io/pypi/pyversions/decompyle3.svg
  179. .. |Latest Version| image:: https://badge.fury.io/py/decompyle3.svg
  180. :target: https://badge.fury.io/py/decompyle3
  181. .. |PyPI Installs| image:: https://pepy.tech/badge/decompyle3/month
  182. .. _pydecipher: https://github.com/mitre/pydecipher