Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
#include <stdio.h>
#include <stdlib.h>
char const interp[] __attribute__((section(".interp"))) = "/lib/ld-linux.so.2";
//path to your dynamic linker (make sure that symbolic link refers to the real linker for your system)
void func(int i)
{
printf("func got %i\n", i);
}
int main()
{
func(0);
exit(0); //do not return, only exit!
}
#include <dlfcn.h>
void func(int);
int main()
{
void *handle = dlopen("libtest.so", RTLD_LAZY);
func(1);
dlclose(handle);
return 0;
}
bash$ gcc -fPIC -shared -Wl,-e,main -o libtest.so libtest.c #"-Wl,-e,main" to make a special named entry point
bash$ gcc -L$PWD -ltest -ldl -o test test.c
bash$ export LD_LIBRARY_PATH=$PWD:$LD_LIBRARY_PATH
bash$ ./test
func got 1
bash$ ./libtest.so
func got 0
Перенаправление функций в разделяемых ELF-библиотеках