From c2cbf6e42d2f96353206dba92fbdecce41645d8a Mon Sep 17 00:00:00 2001 From: Frago9876543210 Date: Mon, 15 Jul 2019 22:46:05 +0300 Subject: [PATCH] Print symbol if error has occurred --- CMakeLists.txt | 2 +- include/modloader/hook.h | 4 +++- src/hook.cpp | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 37fa664..ae1f83d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ endif() set(CMAKE_POSITION_INDEPENDENT_CODE ON) -set(MODLOADER_VERSION "Preview 1") +set(MODLOADER_VERSION "Preview 2") add_subdirectory(dep/funchook) diff --git a/include/modloader/hook.h b/include/modloader/hook.h index 5dbffa8..e1cf6f9 100644 --- a/include/modloader/hook.h +++ b/include/modloader/hook.h @@ -9,6 +9,8 @@ extern "C" { typedef void modloader_hook_t; +void* modloader_dlsym_print_error(const char *sym); + modloader_hook_t* modloader_hook(void *sym, void *hook, void **orig); void modloader_destroy_hook(modloader_hook_t*); @@ -48,7 +50,7 @@ class AutoHook { } - AutoHook(const char *sym, void *hook, void **orig) : AutoHook(dlsym(RTLD_DEFAULT, sym), hook, orig) { + AutoHook(const char *sym, void *hook, void **orig) : AutoHook(modloader_dlsym_print_error(sym), hook, orig) { } // workaround for a warning diff --git a/src/hook.cpp b/src/hook.cpp index 2992199..e08f77f 100644 --- a/src/hook.cpp +++ b/src/hook.cpp @@ -9,6 +9,13 @@ using namespace modloader; extern "C" { +void *modloader_dlsym_print_error(const char *sym) { + void *ptr = dlsym(RTLD_DEFAULT, sym); + if (!ptr) + Log::error("Hook", "Unknown symbol %s", sym); + return ptr; +} + modloader_hook_t *modloader_hook(void *sym, void *hook, void **orig) { funchook_t *h = funchook_create(); if (!h)