Skip to content

Instantly share code, notes, and snippets.

@weskerfoot
Last active September 11, 2020 22:19
Show Gist options
  • Save weskerfoot/77e880279bb9aad93ac65125f4322c8f to your computer and use it in GitHub Desktop.
Save weskerfoot/77e880279bb9aad93ac65125f4322c8f to your computer and use it in GitHub Desktop.
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdio.h>
typedef void* (*real_dlopen_t)(const char*, int);
void*
real_dlopen(const char *filename, int flags) {
return ((real_dlopen_t)dlsym(RTLD_NEXT, "dlopen"))(filename, flags);
}
void*
dlopen(const char *filename, int flags) {
printf("Loading library %s\n", filename);
void *result = real_dlopen(filename, RTLD_NOW);
char *error = dlerror();
if (error != NULL) {
printf(error);
}
return result;
}
@weskerfoot
Copy link
Author

weskerfoot commented Sep 11, 2020

compile with gcc -shared -fPIC -o logdlopen.so logdlopen.c and do LD_PRELOAD=./logdlopen.so my_command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment