serge1 / ELFIO

ELFIO - ELF (Executable and Linkable Format) reader and producer implemented as a header only C++ library
http://serge1.github.io/ELFIO
MIT License
720 stars 155 forks source link

Edit/Remove Sections #48

Closed git-dimiz closed 4 years ago

git-dimiz commented 4 years ago

Hi,

Really appreciate your ELFIO and the great documentation! As far as I can see there is no API to remove a section or edit a section? Is this possible or am I overlooking something?

serge1 commented 4 years ago

Hi,

The primarily design of the library is to use 'elfio' object as a read-only reader or as a writer for newly created ELF object or executable files. In both such scenarios, modification of existing section data is not required.

Saying this, there are couple of ways to alternate the section data. One of the ways is demonstrated in 'anonymizer' example. An external file is modified on base of the parsed information. The second way is just alternating raw memory pointed by section->get_data(). An example of this can be found in the newly implemented generic_set_entry_rel() function in elfio_relocation.hpp file.

Please be warned: read/modify/write scenario may or may not work - there are too many cross references inside the format and it is easy to damage them. This will lead to incorrect object/executable file.

Best regards, Serge