Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux user-space ELF loader

I need to do a rather unusual thing: manually execute an elf executable. I.e. load all sections into right places, query main() and call it (and cleanup then). Executable will be statically linked, so there will be no need to link libraries. I also control base address, so no worries about possible conflicts.

So, is there are any libraries for that?

I found OSKit and its liboskit_exec, but project seems to be dead since 2002.

I'm OK with taking parts of projects (respecting licenses, of course) and tailoring them to my need, but as I'm quite a noob in the linux world, I dont even know where to find those parts! :)

PS. I need that for ARM platform.

UPD Well, the matter of loading elfs seems to require some good knowledge about it (sigh), so I'm out to read some specs and manuals. And I think I will stick to bionic/linker and libelfsh. Thanks guys!

Summarized findings:

  • libelf: http://directory.fsf.org/project/libelf/
  • elfsh and libelfsh (are now part of eresi): http://www.eresi-project.org/
  • elfio (another elf library): http://sourceforge.net/projects/elfio/
  • OSKit and liboskit_exec (outdated): http://www.cs.utah.edu/flux/oskit/
  • bionic/linker: https://android.googlesource.com/platform/bionic
like image 702
beetoom Avatar asked Nov 23 '09 16:11

beetoom


2 Answers

A quick apt-cache search suggests libelf1, libelfg0 and/or libelfsh0. I think the elfsh program (in the namesake package) might be an interesting practical example of how to use libelfsh0.

I haven't tried any myself, but I hope they might be helpful. Good luck :-)

like image 54
Jonas Kölker Avatar answered Nov 10 '22 15:11

Jonas Kölker


Google's Android, in it's "bionic" libc implementation, has a completely reimplemented ELF loader. It's reasonably clean, and probably a better source than gilbc if you're looking for something simple.

like image 20
Andy Ross Avatar answered Nov 10 '22 14:11

Andy Ross