Run function in a striped library in linux
Posted: Wed Oct 05, 2022 5:39 am
If a dynamically load a library in Linux that only has one function call as a entry point to it.
How do I call that function without any header files?
For example lets say somebody had compiled the following, just as an easy case to reason about...
int function(int a, int b){
return a + b ;
}
And it was compiled with...
gcc thefile.c -o thefile.so -fPIC -shared
And now you are going to run that function in Linux. And you only know that this elf can be loaded as a dynamically loaded shared library.
And the function name was altered and is unknown or stripped from the elf
So you want to load it with dlopen in Linux and run that function and print out the result in the terminal.
How would you go about to run this function in a C program in Linux?
And lets say that you suppose it returns a int and you want to print out that value with for example printf...
printf("return value: %d",fn(3,7));
So now you are first going to load that lib with dlopen.
And lets say now that this function can have any name, or that name is stripped away from that elf as supposed.
How would you go about to load it in a C program and run that function without altering the loaded elf?
How do I call that function without any header files?
For example lets say somebody had compiled the following, just as an easy case to reason about...
int function(int a, int b){
return a + b ;
}
And it was compiled with...
gcc thefile.c -o thefile.so -fPIC -shared
And now you are going to run that function in Linux. And you only know that this elf can be loaded as a dynamically loaded shared library.
And the function name was altered and is unknown or stripped from the elf
So you want to load it with dlopen in Linux and run that function and print out the result in the terminal.
How would you go about to run this function in a C program in Linux?
And lets say that you suppose it returns a int and you want to print out that value with for example printf...
printf("return value: %d",fn(3,7));
So now you are first going to load that lib with dlopen.
And lets say now that this function can have any name, or that name is stripped away from that elf as supposed.
How would you go about to load it in a C program and run that function without altering the loaded elf?