Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tool for modifying dynamic section of an ELF binary

Tags:

c

linux

elf

Is there a tool for modifying the shared library entries in the dynamic section of an ELF binary? I would like to explicitly modify the shared library dependencies in my binary (i.e. replace path to existing library with a custom path)

like image 715
zer0stimulus Avatar asked Jul 08 '10 17:07

zer0stimulus


1 Answers

replace path to existing library with a custom path

If this is your own library, then you probably linking it like that:

$ cc -o prog1 -l/full/path/to/libABC.so prog1.o

instead of the proper:

$ cc -o prog1 -L/full/path/to/ -lABC prog1.o

The first approach tells Linux linker that application needs precisely that library, only that library and no override should be possible. Second approach tells that application needs the library which would be installed somewhere on the system, either in the default library path or one pointed by the $LD_LIBRARY_PATH (would be looked up during run-time). -L is used only during link-time.

Otherwise, instead of patching the ELF, first check if you can substitute the library using a symlink. This is the usual trick: it is hard to modify executable afterward, but it is very easy to change where to the symlink points.

like image 144
Dummy00001 Avatar answered Sep 28 '22 23:09

Dummy00001