Skip to content

Commit

Permalink
Merge pull request #2 from Frago9876543210/master
Browse files Browse the repository at this point in the history
Print symbol if error has occurred
  • Loading branch information
MCMrARM authored Jul 31, 2019
2 parents 35a7d75 + c2cbf6e commit a788e47
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion include/modloader/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*);
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a788e47

Please sign in to comment.