All Projects → rocky → Python Decompile3

rocky / Python Decompile3

Licence: gpl-3.0
Python decompiler for 3.7-3.8 Stripped down from uncompyle6 so we can refactor and fix up some long-standing problems

Programming Languages

python
139335 projects - #7 most used programming language
bytecode
52 projects

Projects that are alternatives of or similar to Python Decompile3

vandal
Static program analysis framework for Ethereum smart contract bytecode.
Stars: ✭ 121 (-60.07%)
Mutual labels:  decompiler
xray
Hexrays decompiler plugin that colorizes and filters the decompiler's output based on regular expressions
Stars: ✭ 97 (-67.99%)
Mutual labels:  decompiler
MBBSDASM
MBBSDASM is an x86 Disassembler for 16-bit DOS / Windows 3.0 Segmented Executable (NE) EXE/DLL File Format with special features related to The MajorBBS & Worldgroup Modules
Stars: ✭ 34 (-88.78%)
Mutual labels:  decompiler
react-native-decompiler
Decompile React Native Android/IOS Bundle.
Stars: ✭ 78 (-74.26%)
Mutual labels:  decompiler
Cpp2IL
Work-in-progress tool to reverse unity's IL2CPP toolchain.
Stars: ✭ 689 (+127.39%)
Mutual labels:  decompiler
wasm.cljc
Spec compliant WebAssembly compiler, decompiler, and generator
Stars: ✭ 178 (-41.25%)
Mutual labels:  decompiler
MadMax
Ethereum Static Vulnerability Detector for Gas-Focussed Vulnerabilities
Stars: ✭ 96 (-68.32%)
Mutual labels:  decompiler
Boomerang
Boomerang Decompiler - Fighting the code-rot :)
Stars: ✭ 265 (-12.54%)
Mutual labels:  decompiler
anvill
anvill forges beautiful LLVM bitcode out of raw machine code
Stars: ✭ 228 (-24.75%)
Mutual labels:  decompiler
redscript
Compiler/decompiler toolkit for redscript
Stars: ✭ 191 (-36.96%)
Mutual labels:  decompiler
IDR
Interactive Delphi Reconstructor (Pascal version)
Stars: ✭ 40 (-86.8%)
Mutual labels:  decompiler
quiltflower
Modern Java decompiler aiming to be as accurate as possible, with an emphasis on output quality. Fork of the Fernflower decompiler.
Stars: ✭ 330 (+8.91%)
Mutual labels:  decompiler
BEFA-Library
High-level library for executable binary file analysis
Stars: ✭ 14 (-95.38%)
Mutual labels:  decompiler
tools.decompiler
A decompiler for clojure, in clojure
Stars: ✭ 66 (-78.22%)
Mutual labels:  decompiler
apk-decompiler
Small Rust utility to decompile Android apks
Stars: ✭ 48 (-84.16%)
Mutual labels:  decompiler
ethdasm
Tool for auditing Ethereum contracts
Stars: ✭ 52 (-82.84%)
Mutual labels:  decompiler
OSRSUpdater
A simple (and outdated) Old-School RuneScape decompiler/deobfuscator. Performs field and method analysis which uses ASM and bytecode patterns for identification. Identified fields could be used for creating bot clients or QoL clients. For educational use only.
Stars: ✭ 13 (-95.71%)
Mutual labels:  decompiler
Wasmdec
WebAssembly to C decompiler
Stars: ✭ 290 (-4.29%)
Mutual labels:  decompiler
Luadec51
Lua Decompiler for Lua version 5.1
Stars: ✭ 257 (-15.18%)
Mutual labels:  decompiler
ti recover
Appcelerator Titanium APK source code recovery tool
Stars: ✭ 17 (-94.39%)
Mutual labels:  decompiler

|TravisCI| |CircleCI|

decompyle3

A native Python cross-version decompiler and fragment decompiler. A reworking of uncompyle6_.

Introduction

decompyle3 translates Python bytecode back into equivalent Python source code. It accepts bytecodes from Python version 3.7 on.

For decompilation of older Python bytecode see uncompyle6_.

Why this?

Uncompyle6 is awesome, but it has has a fundamental problem in the way it handles control flow. In the early days of Python when there was 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.

Over the years more code optimization, specifically around handling jumps has made it harder to support detecting control flow strictly 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 in a satisfactory way.

The initial attempt to fix to this problem was to add markers in the instruction stream, initially this was a COME_FROM instruction, and then use that in pattern detection.

Over the years, I've extended that to be more specific, so COME_FROM_LOOP and COME_FROM_WITH were added. And I added checks at grammar-reduce time to make try to make sure jumps match with supposed COME_FROM targets.

However all of this is complicated, not robust, has greatly slowed down deparsing and is not really tenable.

So in this project we started rewriting and refactoring the grammar.

However it is clear that even this isn't enough. Control flow needs to be addressed by using dominators and reverse-dominators which the python-control-flow_ project can give.

This hasn't started yet. It is a lot of work. And currently there isn't any funding for this or the other decompiler. So it may take time and is on the back burner. And if it were worked on, I expect it will be a while before an approach using control flow is as good as this is for Python 3.7. But if decompilation is to have a future and work in Python 3.9, I think this work is necessary.

Requirements

The code here can be run on Python versions 3.7 or later. The bytecode files it can read have been tested on Python bytecodes from versions 3.7 and later.

Installation

This uses setup.py, so it follows the standard Python routine:

::

pip install -e .  # set up to run from source tree
                  # Or if you want to install instead
python setup.py install # may need sudo

A GNU makefile is also provided so :code:make install (possibly as root or sudo) will do the steps above.

Running Tests

::

make check

A GNU makefile has been added to smooth over setting running the right command, and running tests from fastest to slowest.

If you have remake_ installed, you can see the list of all tasks including tests via :code:remake --tasks

Usage

Run

::

$ decompyle3 compiled-python-file-pyc-or-pyo

For usage help:

::

$ decompyle3 -h

Verification

If you want Python syntax verification of the correctness of the decompilation process, add the --syntax-verify option. However since Python syntax changes, you should use this option if the bytecode is the right bytecode for the Python interpreter that will be checking the syntax.

You can also cross compare the results with another python decompiler like unpyc37_ . Since they work differently, bugs here often aren't in that, and vice versa.

There is an interesting class of these programs that is readily available give stronger verification: those programs that when run test themselves. Our test suite includes these.

And Python comes with another a set of programs like this: its test suite for the standard library. We have some code in test/stdlib to facilitate this kind of checking too.

Known Bugs/Restrictions

We support only released versions, not candidate versions. Note however that the magic of a released version is usually the same as the last candidate version prior to release.

We also don't handle PJOrion_ or otherwise obfuscated code. For PJOrion try: PJOrion Deobfuscator_ to unscramble the bytecode to get valid bytecode before trying this tool. This program can't decompile Microsoft Windows EXE files created by Py2EXE_, although we can probably decompile the code after you extract the bytecode properly. Handling pathologically long lists of expressions or statements is slow. We don't handle Cython_ or MicroPython_ which don't use bytecode.

There are numerous bugs in decompilation. And that's true for every other CPython decompiler I have encountered, even the ones that claimed to be "perfect" on some particular version like 2.4.

As Python progresses decompilation also gets harder because the compilation is more sophisticated and the language itself is more sophisticated. I suspect that attempts there will be fewer ad-hoc attempts like unpyc37_ (which is based on a 3.3 decompiler) simply because it is harder to do so. The good news, at least from my standpoint, is that I think I understand what's needed to address the problems in a more robust way. But right now until such time as project is better funded, I do not intend to make any serious effort to support Python versions 3.8 or 3.9, including bugs that might come in. I imagine at some point I may be interested in it.

You can easily find bugs by running the tests against the standard test suite that Python uses to check itself. At any given time, there are dozens of known problems that are pretty well isolated and that could be solved if one were to put in the time to do so. The problem is that there aren't that many people who have been working on bug fixing.

You may run across a bug, that you want to report. Please do so. But be aware that it might not get my attention for a while. If you sponsor or support the project in some way, I'll prioritize your issues above the queue of other things I might be doing instead.

See Also

.. _Cython: https://en.wikipedia.org/wiki/Cython .. _MicroPython: https://micropython.org .. _uncompyle6: https://pypi.python.org/pypi/uncompyle6 .. _python-control-flow: https://github.com/rocky/python-control-flow .. _trepan: https://pypi.python.org/pypi/trepan2 .. _compiler: https://pypi.python.org/pypi/spark_parser .. _HISTORY: https://github.com/rocky/python-decompile3/blob/master/HISTORY.md .. _debuggers: https://pypi.python.org/pypi/trepan3k .. _remake: https://bashdb.sf.net/remake .. _unpyc37: https://github.com/andrew-tavera/unpyc37/ .. _this: https://github.com/rocky/python-decompile3/wiki/Deparsing-technology-and-its-use-in-exact-location-reporting .. |TravisCI| image:: https://travis-ci.org/rocky/python-decompile3.svg :target: https://travis-ci.org/rocky/python-decompile3 .. |CircleCI| image:: https://circleci.com/gh/rocky/python-decompile3.svg?style=svg :target: https://circleci.com/gh/rocky/python-decompile3

.. _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 .. _Deobfuscator: https://github.com/extremecoders-re/PjOrion-Deobfuscator .. _Py2EXE: https://en.wikipedia.org/wiki/Py2exe .. |Supported Python Versions| image:: https://img.shields.io/pypi/pyversions/decompyle3.svg .. |Latest Version| image:: https://badge.fury.io/py/decompyle3.svg :target: https://badge.fury.io/py/decompyle3

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].