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

.pyc Python disassembler #1165

Open
lab313ru opened this issue Oct 21, 2019 · 2 comments
Open

.pyc Python disassembler #1165

lab313ru opened this issue Oct 21, 2019 · 2 comments
Labels

Comments

@lab313ru
Copy link
Contributor

It would be great to add Python disassembler/decompiler to Ghidra.

@Andoryuuta
Copy link

Just to add my understanding of about what this would entail:

The .pyc format itself is a version number, timestamp, and a serialized code object.

The code object is serialized using Python's marshal module, which is "undocumented on purpose; [because] it may change between Python versions". This has previously changed across versions.

Additionally, within the (unmarshaled) code object, the co_code attribute contains the raw Python bytecode. In regards to the bytecode itself, the official docs state that there is no guarantee "that bytecode will not be added, removed, or changed between versions of Python", which has historically meant a couple of changes every minor version from 1.1 to 3.8.

Essentially, if you want to support more than one version of the Python bytecode, you are looking at custom unmarshaling logic and bytecode changes for each minor Python release.

Somebody has been maintaining a python disassembling library that implements a cross-version marshal and opcode tables for each version, xdis, which might be a good reference for anybody who decides to implement this.

@XVilka
Copy link
Contributor

XVilka commented Nov 20, 2020

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

No branches or pull requests

4 participants