Skip to content

Add/append/replace binary data #756

Answered by romainthomas
floitsch asked this question in Q&A
Discussion options

You must be logged in to vote

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:

import lief

target = lief.parse("...")
sym = target.get_symbol("__bytecode_data")
target.patch_address(sym.value, [your new bytecode])
target.write("out.bin")

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@floitsch
Comment options

@floitsch
Comment options

Answer selected by floitsch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants