zrax / pycdc

C++ python bytecode disassembler and decompiler
GNU General Public License v3.0
3.21k stars 621 forks source link

can we take part of disassembled bytecode and translate it back into pyc? #69

Open retsyo opened 8 years ago

retsyo commented 8 years ago

My question is composed by 2 aspects

  1. incompleted pyc is valid in python for example. I have tested the following a.py and b.py. After running a.py, we can find that b.pyc is created. But obviously, b.py is not a completed code since there is no defination of function "fib". So the bytecode of I-called incompleted pyc is valid too
  2. we can use pycdc to disassemble. But is there a way to find just the code of function (for example "fun") and convert it back into pyc? thanks

[code a.py] import b [/code]

[code b.py] n=10

def fun(x, y): return x+fib(y) [/code]

rocky commented 7 years ago

The question is a bit vague, but uncompyle6 has some support for decompiling parts of code. The deparse_code() function takes a code object, a python version number and some optional arguments and it will deparse that code object.