Last active
August 16, 2021 04:58
-
-
Save Jokeren/deeef6bc1764435d2f7014371dc8fc89 to your computer and use it in GitHub Desktop.
ld_preload + api
This file contains hidden or 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 <dlfcn.h> | |
#include "tool.h" | |
int main() { | |
//void *handle = dlopen("./tool.so", RTLD_NOW); | |
print_t func = (print_t)dlsym(RTLD_NEXT, "print"); | |
func(); | |
return 0; | |
} |
This file contains hidden or 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++ -ldl -shared -fPIC -o tool.so tool.cc | |
g++ ./main.cc -ldl | |
LD_PRELOAD=./tool.so ./a.out |
This file contains hidden or 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 "tool.h" | |
#include <cstdio> | |
extern "C" | |
void print() { | |
printf("tool.h\n"); | |
} |
This file contains hidden or 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
typedef void (*print_t)(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment