Friday, February 23, 2018

Create Shared Library Function Calls in Linux or Unix 3 steps

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;
}

2. libaroundng.c file library code

#include <stdio.h> 
#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:

"NCBN Nara chandrababu naidu" CEO Deals to grow Andhra Pradesh

CISCO network and andhra pradesh CEO Chandra babu  Microsoft Kaizala for andhra pradesh  Google Wi-fi for andhra pradesh CEO Micro...