MatthieuDartiailh / bytecode

Python module to modify bytecode
https://bytecode.readthedocs.io/
MIT License
302 stars 38 forks source link

Modify Existing bytecode #151

Open PythonLinks opened 3 weeks ago

PythonLinks commented 3 weeks ago

The documentation says that

bytecode is a Python module to ... modify bytecode.

What I would like to do is to modify existing bytecode.

Load a file, read the bytecode, modify it, save it out.

Can I do that with this package? Is this package only for creating code?

P403n1x87 commented 3 weeks ago

In #123 you can find a suggestion about how to read a pyc file https://github.com/MatthieuDartiailh/bytecode/issues/123. The part of writing it out is in https://github.com/P403n1x87/spasmlang/blob/d868ce2557e17fc3dd5a71fc7b155f3250a3aeb5/spasm/__main__.py#L23

MatthieuDartiailh commented 3 weeks ago

The reference given by @P403n1x87 is likely to be the best. Other usage of bytecode I am aware of tend to work mostly in memory or at least retrieve code from live objects.