Trouble using Libelf/Elfio libraries : ELF not executable anymore
Hi everyone,
I'm using Libelf and Elfio to try and add a new section to ELF files. I would like it to be executable, just like .text.
This is my problem : with Libelf, as soon as I load (elf_begin()), update (elf_update()) and release (elf_end()) my ELF, it stops to be executable (seg fault when launching). readelf -S displays the sections but returns also the error : readelf: Warning: the .dynamic section is not contained within the dynamic segment. I didn't find any function in Libelf to "add" the .dynamic section to the DYNAMIC segment.
But I can do that with Elfio (with the segment->add_section_index() function), but then I have to manually add every other section to every other segment, as Elfio seems to overwrite them when loading the ELF. After doing that and trying to execute the ELF, the process crashes with exit code 137. Shell says "Processus arrêté" (it's french) which literally means "Process stopped", could be "Process killed".
Has anyone any experience with those libraries ?
My final goal is to be able to create a new executable section in the ELF, and modify its entry point to jump and execute directly that new section, in order to create a packer.
Any suggestions/other way to do so appreciated !
Thank you for your answers !
|