Add/append/replace binary data #756
-
Context: My hope is that I can link LIEF into the compiler and then update a copy of the interpreter to add/append/replace the bytecodes there. Initially I was planning to just append the bytecodes to the interpreter without even modifying the executable. I could then use a library like whereami to find my own executable and extract the bytecodes from there. I see two possibilities (depending on your recommendations):
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hello @floitsch, From what I understood of your problem, I think your second approach (creating an empty space for the bytecode) would be import lief
target = lief.parse("...")
sym = target.get_symbol("__bytecode_data")
target.patch_address(sym.value, [your new bytecode])
target.write("out.bin") |
Beta Was this translation helpful? Give feedback.
Hello @floitsch,
Firstly, I would say that the LIEF's PE support for modifying binaries is not really reliable compared to ELF/Mach-O. I plan to refactor this part by the end of the year but keep mind this aspect if you want to use it in a product.
From what I understood of your problem, I think your second approach (creating an empty space for the bytecode) would be
more reliable. Actually you can do that with this kind of code: