MatthieuDartiailh / bytecode

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

read .pyc #123

Closed Majingnan36 closed 1 year ago

Majingnan36 commented 1 year ago

Does it support reading .pyc files? Get all bytecode instructions in .pyc by similar to Bytecode.from_code(code_obj)

MatthieuDartiailh commented 1 year ago

No currently bytecode only operate on code objects.

I never tried to open a pyc and unmarshall it, but you could try that and grab the module code object to use with bytecode.

P403n1x87 commented 1 year ago

Would something like this work for you?

from pkgutil import read_code

with open("path/to.pyc", "rb") as f
    bc = Bytecode.from_code(read_code(f))
Majingnan36 commented 1 year ago

Thanks for your answers, it's very helpful for me