playing around with LD_LIBRARY_PATH
-
04-06-2021 - |
Domanda
I read this article recently, and I tried overriding the libc printf function with a doing the following for fun :-
- Create an executable that uses printf to print
this is a test
(printer.c) - Create an c file with a custom puts to print
muhahaha, this is a test
(custom.c) - Create an object file
gcc -fPIC -g -c -Wall custom.c
- Create an so file
gcc -shared -Wl,-soname,libmystuff.so.1 -o libmystuff.so.1.0.1 custom.o
- I add the directory which contains the so file into the LD_PRELOAD environment variable.
export LD_PRELOAD=$(pwd)
- Try running printer
I'd imagine that muhahaha, this is a test
would be printed out but it seems like im doing something wrong. Have I got some concept wrong? Or am I just doing something wrong?
[EDIT]
The code snippets involved are :-
// printer.c
int main() {
printf("this is a test");
return 0;
}
// custom.c
void printf(char *t) {
puts("muhahaha, this is a test");
}
Soluzione
You're supposed to name the library in the LD_PRELOAD environment variable, not the directory.
export LD_PRELOAD=/path/to/libmystuff.so.1.0.1
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow