Support Python 3.12 decompilation
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
Added support for the following POP_JUMP_IF_NOT_NONE POP_JUMP_IF_NONE CALL_INTRINSIC_1 (only INTRINSIC_IMPORT_STAR)
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!
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.
pycdc crashes for some pyc files when parsing JUMP_BACKWARD_A(140) in python 3.11, could you examine what the error is?
JUMP_BACKWARD is still not in main branch, you could try to play with this PR: https://github.com/zrax/pycdc/pull/472
JUMP_BACKWARD is still not in main branch, you could try to play with this PR: #472
Thanks for the pr!
Anything new about LOAD_FAST_AND_CLEAR?