Created
April 21, 2023 16:13
-
-
Save baldurk/9a93d0514d4f2de40971ff119b5641e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
struct Global { | |
Global() { | |
printf("a %s %s\n", getenv("HOME"), getenv("BLAH")); | |
setenv("BLAH", "blah", 1); | |
printf("b %s %s\n", getenv("HOME"), getenv("BLAH")); | |
} | |
} global; | |
extern "C" int close(int) { | |
printf("close %s %s\n", getenv("HOME"), getenv("BLAH")); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ g++ lib.cpp -shared -fPIC -o libtest.so | |
$ LD_PRELOAD=$(pwd)/libtest.so bash -c "echo hi" | |
a /home/baldurk (null) | |
b (null) blah | |
close (null) blah | |
hi | |
$ LD_PRELOAD=$(pwd)/libtest.so python -c "print('hi')" | |
a /home/baldurk (null) | |
b /home/baldurk blah | |
close /home/baldurk blah | |
# more identical close prints | |
close /home/baldurk blah | |
hi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment