Skip to content

Instantly share code, notes, and snippets.

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