There is an executable ELF file "glinkd". I need to supplement the implementation of certain functions by intercepting them. I came across a handy tool LD_PRELOAD . It works fine on any elf files, but unfortunately the patch file needed for me, he refused. This is expressed in the fact that when my library is loaded into “glinkd”, nothing simply happens, as if this file has some kind of protection.
I didn’t find anything in Google about protection from LD_PRELOAD .
How do I patch elf files:
testso.cpp :
#include <cstdio> void __attribute__ ((constructor)) module_load(void); void __attribute__ ((destructor)) module_unload(void); void module_load(void) { printf("hello from .so!\n"); } void module_unload(void) { }I compile:
g ++ -fPIC -c testso.cpp -o testso.o -m32 -std = c ++ 0x g ++ -shared -Wl, -soname, libtestso.so -o libtestso.so testso.o -m32 -std = c ++ 0x
test_prog.cpp:
#include <cstdio> int main() { printf("Hello from executable!\n"); }I compile:
g ++ -o test_prog test_prog.cpp -m32
Patches test_prog :
root@ubuntu:/home/glinkd# LD_PRELOAD=/home/glinkd/libtestso.so ./test_prog hello from .so! Hello from executable! root@ubuntu:/home/glinkd#Patch glinkd :
root@ubuntu:/home/glinkd# LD_PRELOAD=/home/glinkd/libtestso.so ./glinkd Usage: ./glinkd configurefile section_num root@ubuntu:/home/glinkd#
As you can see, our .so simply ignored. Any idea what this protection is, and how can it be removed?