0

I'm working on a piece of code in which at some point I have to execute python bytecode, with exec python builtin.

However the bytecode I have to execute is containing some nullbytes, preventing from being executed.

Is there any way to change this ? For exemple adding an additionnal encoding that would remove raw null bytes but still allowing to be executed as bytecode ?

ibi0tux
  • 2,481
  • 4
  • 28
  • 49
  • Where do you get the python bytecode in the first place? IIRC, the format of the bytecode that python produces can change from one version to the next so it's only guaranteed to work if the current python interpreter wrote the bytecode in the first place... – mgilson Dec 07 '16 at 19:44
  • The bytecote is produced by another part of the app. It would be easier to use directly python code instead but at some point it has been decided that bytecode will be used and I have to deal with it. – ibi0tux Dec 07 '16 at 19:52
  • How is the bytecode produced? i.e. it would be really helpful if you could produce a [MCVE](http://stackoverflow.com/help/mcve) that demonstrates creation of bytecode and then an attempt to `exec` the code that fails. – mgilson Dec 07 '16 at 19:54
  • 1
    If the bytecode is invalid to begin with then the source of the problem is wherever that bytecode is generated. – Billy Dec 07 '16 at 19:55
  • From the inspect tool, `func_code`.`co_code` – ibi0tux Dec 07 '16 at 19:56

0 Answers0