int main() { void *original1, *original2; // Getting addres of our shared lib dl_iterate_phdr(callback, NULL); // Return if lib address not found if (!libaddr){ puts("Library address not found!"); return 1; } testCallRedirSample(); puts("\n"); // Setup redirect original1 = elf_hook(LIB_PATH, libaddr, "malloc", fakeMalloc); original2 = elf_hook(LIB_PATH, libaddr, "free", fakeFree); testCallRedirSample(); // Remove redirect original1 = elf_hook(LIB_PATH, libaddr, "malloc", original1); original2 = elf_hook(LIB_PATH, libaddr, "free", original2); puts("\n"); testCallRedirSample(); return 0; }
int hook_libdl(const char *libpath) { void *handle, *original; handle = dlopen(libpath, RTLD_LAZY); if(handle == NULL) return -1; // original = elf_hook(libpath, LIBRARY_ADDRESS_BY_HANDLE(handle), "dlopen", (const void *) hook_dlopen); if(original == NULL) return -1; // original = elf_hook(libpath, LIBRARY_ADDRESS_BY_HANDLE(handle), "dlsym", (const void *) hook_dlsym); if(original == NULL) return -1; // return 0; }
int hook_lib_generic(const char *libpath, void *handle, const char *name, void *func) { void *original; if(handle == NULL) return -1; original = elf_hook(libpath, LIBRARY_ADDRESS_BY_HANDLE(handle), name, (const void *) func); if(original == NULL) return -1; ga_error("hook library - %s:%s success.\n", libpath, name); return 0; }