I'm trying to use LD_PRELOAD.
original.cpp
void myPuts() {
puts ("Hello myPuts");
}
int main() {
myPuts();
return 0;
}
hacked.cpp
void myPuts() {
std::cout >> "Hello hacked myPuts";
}
I compile original.cpp:
g++ original.cpp
And hacked.cpp:
g++ -shared -fPIC hacked.cpp
I try:
LD_PRELOAD=./hacked.so ./original.out
The string "Hello hacked myPuts" should be seen, by "Hello myPuts" appears. (If I try to "overwrite" the puts function, it works correctly)
What am I missing?
From man ld.so
LD_PRELOAD
A whitespace-separated list of additional, user-specified, ELF shared libraries to be loaded before all others. This can be used to selectively override functions in other shared libraries.
If myPuts was in shared library linked to main application it would work, but not when myPuts exists in the application and does not resolved in an external library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With