Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Python 3.9 decompilation #450

Open
5 of 13 tasks
zrax opened this issue Feb 21, 2024 · 8 comments
Open
5 of 13 tasks

Support Python 3.9 decompilation #450

zrax opened this issue Feb 21, 2024 · 8 comments

Comments

@zrax
Copy link
Owner

zrax commented Feb 21, 2024

Tasks

  • Bytecode support (pycdas)
  • Handle new opcodes in AST builder
    • RERAISE
    • WITH_EXCEPT_START
    • LOAD_ASSERTION_ERROR
    • LIST_TO_TUPLE
    • IS_OP
    • CONTAINS_OP
    • JUMP_IF_NOT_EXC_MATCH
    • LIST_EXTEND
    • SET_UPDATE
    • DICT_MERGE
    • DICT_UPDATE
This was referenced Feb 21, 2024
@AndrewLiuZhangZong
Copy link

When to support it

@Bang1338
Copy link

Bang1338 commented Apr 2, 2024

When to support it

will support if you don't asking again

@AngeloD2022
Copy link

Thank you for maintaining this awesome project. ❤️

1 similar comment
@johnniesong
Copy link

Thank you for maintaining this awesome project. ❤️

@leqnam
Copy link

leqnam commented Apr 12, 2024

still waiting for JUMP_IF_NOT_EXC_MATCH

@Bang1338
Copy link

still waiting for JUMP_IF_NOT_EXC_MATCH

give them sometime.

@Ma5onic
Copy link

Ma5onic commented May 17, 2024

@zrax, I think that I found some hints on how to handle some of the missing optcodes for python 3.9:
https://github.com/greyblue9/unpyc37-3.10/blob/master/src/unpyc/unpyc3.py
https://github.com/greyblue9/unpyc37-3.10/blob/master/src/unpyc/opcodes.py

I was getting JUMP_IF_NOT_EXC_MATCH, WITH_EXCEPT_START & RERAISE errors on 3.10 with pycdc but the script that I linked supports those optcodes. It's written in python but it might help figure out how to implement it in C++

@Levak
Copy link

Levak commented Jun 18, 2024

Hi,

I do not bring good news: I have analyzed the bytecode of Python 3.8, 3.9, 3.10 and 3.11 in regard to try-except-finally blocks, which are super common in Python scripts, and they all change logic from one version to another. I am currently focusing on 3.9 on my spare time and needless to say, it's already a headache. I do not fully grasp pycdc's code base, but I did try other alternatives such as the one mentioned by @Ma5onic to no avail.

My first observation as for Python 3.9: JUMP_IF_NOT_EXC_MATCH rel_delta is equivalent to COMPARE_OP followed by POP_JUMP_IF_FALSE abs_delta.

My second observation as for Python 3.8/3.9: SETUP_FINALLY replaces both SETUP_FINALLY and SETUP_EXCEPT. An important detail is that in Python 3.9, the byte code for the finally block is duplicated: Meaning there will be junk to ignore at the end of the file when reconstructing code. In Python 3.10, the duplication of the finally block is even worse. In Python 3.11, they started using exception tables which radically changes the logic.

This is probably not going to come as a surprise to anybody but adding support for any of these versions in pycdc is IMHO "dead weight". It is already too late. The bytecode has evolved faster than decompilers could (not blaming their maintainers, this is just an observation) and if someone suddenly wants to write or update one, he isn't going to be trying to maintain all the skipped versions. He's going to go straight for 3.12 or higher, and increment the decompiler version major.

As an example, I am trying to decompile a .pyc made from Python 3.9 and it came to me that it was faster to decompile by hand than trying to adapt any decompiler.

Nonetheless, I will continue to tinker with pycdc on my side to try to make Python 3.9's try-except-finally block somehow work. I'm sure @zrax will understand the chest pain I'm having rn 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants