bytecode icon indicating copy to clipboard operation
bytecode copied to clipboard

Modify Existing bytecode

Open PythonLinks opened this issue 1 year ago • 2 comments

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?

PythonLinks avatar Nov 03 '24 07:11 PythonLinks

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

P403n1x87 avatar Nov 03 '24 12:11 P403n1x87

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.

MatthieuDartiailh avatar Nov 05 '24 21:11 MatthieuDartiailh