codetransformer
codetransformer copied to clipboard
Finish Decompiler
Currently Handles:
- [x] For-Loops
- [x] While-Loops
- [x] All Binary Operators except
or
andand
. - [x] Dict/Set/Tuple/Number/String/Name Constants
- [x] Function Definitions
- [x] Chained Assignments
- [x] Unpacking Assignments
- [x] With-Blocks
- [x] Global and Nonlocal Declarations
- [x] Imports
Does Not Currently Handle:
- [ ] Python != 3.4.3
- [x] If-Statements
- [x]
or
andand
- [x] ternary expressions
- [ ] Class Definitions
- [ ] Comprehensions
- [x] Lambdas
- [ ] Try-Except-Finally Blocks
- [ ] Raise Statements
- [ ] Assert Statements
- [ ] Comparisons
There is an issue with if
statements:
In [5]: def f():
...: if a:
...: return 1
...: else:
...: return 2
...:
In [6]: dis(f)
2 0 LOAD_GLOBAL 0 (a)
3 POP_JUMP_IF_FALSE 10
3 6 LOAD_CONST 1 (1)
9 RETURN_VALUE
5 >> 10 LOAD_CONST 2 (2)
13 RETURN_VALUE
14 LOAD_CONST 0 (None)
17 RETURN_VALUE
This currently raises: DecompilationError: Expected a JUMP_FORWARD instruction at end of if-block. Got RETURN_VALUE.
This makes finding the end of an else really hard/impossible; however, I think we can totally get rid of the else if the if
ends in a return. This code ends up being the same as:
def f():
if a:
return 1
return 2
Adding on top of that : Python 3.6 has no CALL_FUNCTION_VAR
anymore.
Right now we are just trying to finish the 3.4.3 decompiler, when we get that mostly complete we will work on expanding to 3.5 and 3.6