Reputation: 598
I know you can easily patch the ELF with a value of the same size. But, what if I want to change it for a bigger value? Is there a way to un-pack and re-pack the ELF?
I'm not interested in patching the binary in memory.
Upvotes: 1
Views: 1648
Reputation: 213957
But, what if I want to change it for a bigger value?
You apparently want a longer string, not a bigger value.
is there a way to un-pack and re-pack the ELF?
Depends on what kind of ELF
you are asking about. If you have a relocatable object file of type ET_REL
(usually .o
), then modification is fairly trivial: you simply append a new section to the end of the file (usually string contents reside in .rodata
section, so you would make a (larger) copy of it, and then update corresponding section header's .sh_offset
and .sh_size
to point to the right place in the file.
On the other hand, for a linked ELF
binary (ET_DYN
or ET_EXEC
), the task is so complicated as to be very hard (nearly impossible), because multiple pointers would need to be updated, and the placement in memory is not arbitrary.
Upvotes: 4