pycdc icon indicating copy to clipboard operation
pycdc copied to clipboard

Support Python 3.12 decompilation

Open zrax opened this issue 1 year ago • 9 comments

Tasks

  • [X] Bytecode support (pycdas)
  • [ ] Handle new opcodes in AST builder
    • [ ] INTERPRETER_EXIT
    • [X] END_FOR
    • [ ] END_SEND
    • [ ] RESERVED
    • [ ] BINARY_SLICE
    • [ ] STORE_SLICE
    • [ ] CLEANUP_THROW
    • [X] POP_JUMP_IF_FALSE
    • [X] POP_JUMP_IF_TRUE
    • [X] RETURN_CONST
    • [ ] LOAD_FAST_CHECK
    • [ ] POP_JUMP_IF_NOT_NONE
    • [ ] POP_JUMP_IF_NONE
    • [ ] LOAD_SUPER_ATTR
    • [ ] LOAD_FAST_AND_CLEAR
    • [ ] YIELD_VALUE
    • [ ] CALL_INTRINSIC_1
    • [ ] CALL_INTRINSIC_2
    • [ ] LOAD_FROM_DICT_OR_GLOBALS
    • [ ] LOAD_FROM_DICT_OR_DEREF
    • [ ] INSTRUMENTED_LOAD_SUPER_ATTR
    • [ ] INSTRUMENTED_POP_JUMP_IF_NONE
    • [ ] INSTRUMENTED_POP_JUMP_IF_NOT_NONE
    • [X] INSTRUMENTED_RESUME
    • [X] INSTRUMENTED_CALL
    • [X] INSTRUMENTED_RETURN_VALUE
    • [X] INSTRUMENTED_YIELD_VALUE
    • [ ] INSTRUMENTED_CALL_FUNCTION_EX
    • [X] INSTRUMENTED_JUMP_FORWARD
    • [ ] INSTRUMENTED_JUMP_BACKWARD
    • [X] INSTRUMENTED_RETURN_CONST
    • [X] INSTRUMENTED_FOR_ITER
    • [X] INSTRUMENTED_POP_JUMP_IF_FALSE
    • [X] INSTRUMENTED_POP_JUMP_IF_TRUE
    • [ ] INSTRUMENTED_END_FOR
    • [ ] INSTRUMENTED_END_SEND
    • [ ] INSTRUMENTED_INSTRUCTION
    • [ ] INSTRUMENTED_LINE
  • [X] All jumps are now relative

zrax avatar Feb 21 '24 22:02 zrax

Added support for the following POP_JUMP_IF_NOT_NONE POP_JUMP_IF_NONE CALL_INTRINSIC_1 (only INTRINSIC_IMPORT_STAR)

patch.txt

EDIT: Fixed logging for unsupported intrinsic_1

I have no idea how to implement the other intrinsics, I found no obvious mapping to prior opcodes like with IMPORT_STAR and since I have no code to test it against either, this is all I can do rn. The script I wanted decompiled is successfully decompiled now, so thanks a lot for this project!

Seneral avatar Apr 25 '24 15:04 Seneral

Warning: In my test file, it seems it's inverted - POP_JUMP_IF_NOT_NONE_A needed to be come if xxx is None: for the decompiled behaviour to match the original. No occurences of POP_JUMP_IF_NONE_A to double-check sadly. Not sure if this is a general error, cpython seems to treat POP_JUMP_IF_NOT_NONE_A as expected, and the opcodes also match the ones found here. This will need proper verification.

Seneral avatar May 26 '24 14:05 Seneral

pycdc crashes for some pyc files when parsing JUMP_BACKWARD_A(140) in python 3.11, could you examine what the error is?

rockingdice avatar Jul 22 '24 12:07 rockingdice

JUMP_BACKWARD is still not in main branch, you could try to play with this PR: https://github.com/zrax/pycdc/pull/472

greenozon avatar Jul 22 '24 13:07 greenozon

JUMP_BACKWARD is still not in main branch, you could try to play with this PR: #472

Thanks for the pr!

rockingdice avatar Jul 22 '24 14:07 rockingdice

Anything new about LOAD_FAST_AND_CLEAR?

DEMON1A avatar Jul 29 '24 01:07 DEMON1A