1

I am looking for a way to replace the code / text segment of an ELF executable before executing it. Is this possible? If yes, are there any utilities or libraries that I can use to replace it?

1
  • 3
    What are you trying to achieve? Instead of replacing the text section, you could also simply start another ELF binary. If you want to reuse parts of an existing binary in another one for whatever weird reason, a tool like objcopy might be useful. But keep in mind that questions asking for libraries or utilities are generally not on topic on this site. Commented Jul 3, 2018 at 21:09

1 Answer 1

2

Its possible, but not trivial (I am warning you :) ). ELF contains lots of information about its content in the header files. text is just single section in a ELF file. I am also trying do it but not being successful so far.

I haven't tried objcopy to replace text segment but try this. I had few problem with this so i didn't continue this.

objcopy srcELF--dump-section .text=text.dump

objcopy dstELF --add-section .text=text.dump

My prefered way is to use libelf.

With libelf you can modify an ELF binary (add section, modify data in a section, etc). This tutorial provides a good start.

libelf-by-example

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.