Creating Shared Library Function Calls in Linux
1. Create programe code ngprogram.c
#include <stdio.h>
#include <unistd.h>
int main()
{
puts("aroundng dot com world!n");
return 0;
}
puts("aroundng dot com world!n");
return 0;
}
2. libaroundng.c file library code
#include <unistd.h>
#include <dlfcn.h>
int puts(const char *message)
{
int (*new_puts)(const char *message);
int result;
new_puts = dlsym(RTLD_NEXT, "puts");
if(strcmp(message, "aroundng dot com world!n") == 0)
{
result = new_puts("Goodbye, aroundng!\n");
}
else
{
result = new_puts(message);
}
return result;
}
3. Create and then export library :
$ gcc libaroundng.c -o libaroundng.so -fPIC -shared -ldl -D_GNU_SOURCE
$ export LD_PRELOAD="${PWD}/libexample.so"
Finally, Compile:
$ gcc ngprogram.c -o ngprogram
$ ./ngprogram
Goodbye, aroundng!
$
Here system call is puts(const char *message)
Feel free ask any queries
No comments:
Post a Comment