|
Example hijacking getpid(2) to add a side-effect: Compiling and execution:Hijacking functions with LD_PRELOAD
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
pid_t getpid(void)
{
printf("Hello, world!\n");
return syscall(SYS_getpid);
}
$ gcc -Wall -fPIC -shared -o getpid.so getpid.c
$ LD_PRELOAD=./getpid.so bash -c 'echo $$'
Hello, world!
3358