codetransformer icon indicating copy to clipboard operation
codetransformer copied to clipboard

Finish Decompiler

Open ssanderson opened this issue 8 years ago • 3 comments

Currently Handles:

  • [x] For-Loops
  • [x] While-Loops
  • [x] All Binary Operators except or and and.
  • [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 and and
  • [x] ternary expressions
  • [ ] Class Definitions
  • [ ] Comprehensions
  • [x] Lambdas
  • [ ] Try-Except-Finally Blocks
  • [ ] Raise Statements
  • [ ] Assert Statements
  • [ ] Comparisons

ssanderson avatar Oct 27 '15 06:10 ssanderson

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

llllllllll avatar Feb 07 '17 08:02 llllllllll

Adding on top of that : Python 3.6 has no CALL_FUNCTION_VAR anymore.

Carreau avatar May 24 '17 21:05 Carreau

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

llllllllll avatar May 24 '17 22:05 llllllllll