diff --git a/relocator/src/entry.cpp b/relocator/src/entry.cpp index 21f1673..86339ec 100644 --- a/relocator/src/entry.cpp +++ b/relocator/src/entry.cpp @@ -20,8 +20,6 @@ #include "globals.h" #include "hooks.h" -#define gModuleData ((module_information_t *) (0x00880000)) - uint8_t gFunctionsPatched __attribute__((section(".data"))) = 0; uint8_t gInitCalled __attribute__((section(".data"))) = 0; diff --git a/relocator/src/globals.h b/relocator/src/globals.h index f096fa7..2d95f62 100644 --- a/relocator/src/globals.h +++ b/relocator/src/globals.h @@ -3,4 +3,6 @@ #include extern uint32_t MemoryMappingEffectiveToPhysicalPTR; -extern uint32_t MemoryMappingPhysicalToEffectivePTR; \ No newline at end of file +extern uint32_t MemoryMappingPhysicalToEffectivePTR; + +#define gModuleData ((module_information_t *) (0x00880000)) \ No newline at end of file diff --git a/relocator/src/hooks.cpp b/relocator/src/hooks.cpp index 1e1ad6f..07b3d08 100644 --- a/relocator/src/hooks.cpp +++ b/relocator/src/hooks.cpp @@ -1,6 +1,7 @@ #include #include "hooks.h" #include "utils/logger.h" +#include "globals.h" static const char **hook_names = (const char *[]) { "WUMS_HOOK_INIT", @@ -19,19 +20,26 @@ void CallHook(const std::vector &modules, wums_hook_type_t type) { void CallHook(const ModuleData &module, wums_hook_type_t type) { for (auto &curHook : module.getHookDataList()) { - if ((type == WUMS_HOOK_INIT || - type == WUMS_HOOK_APPLICATION_STARTS || - type == WUMS_HOOK_APPLICATION_ENDS || - type == WUMS_HOOK_INIT_WUT || - type == WUMS_HOOK_FINI_WUT) && - type == curHook.getType()) { - uint32_t func_ptr = (uint32_t) curHook.getTarget(); - if (func_ptr == 0) { - DEBUG_FUNCTION_LINE("Hook ptr was NULL\n"); - } else { + uint32_t func_ptr = (uint32_t) curHook.getTarget(); + if (func_ptr == 0) { + DEBUG_FUNCTION_LINE("Hook ptr was NULL\n"); + break; + } + + if (type == curHook.getType()) { + if ((type == WUMS_HOOK_APPLICATION_STARTS|| + type == WUMS_HOOK_APPLICATION_ENDS || + type == WUMS_HOOK_INIT_WUT || + type == WUMS_HOOK_FINI_WUT)) { DEBUG_FUNCTION_LINE("Calling hook of type %s [%d] %d for %s \n", hook_names[type], type, curHook.getType(), module.getExportName().c_str()); ((void (*)(void)) ((uint32_t *) func_ptr))(); + } else if (type == WUMS_HOOK_INIT) { + DEBUG_FUNCTION_LINE("Calling hook of type %s [%d] %d for %s\n", hook_names[type], type, curHook.getType(), module.getExportName().c_str(), gModuleData); + wums_app_init_args_t args; + args.module_information = gModuleData; + ((void (*)(wums_app_init_args_t*)) ((uint32_t *) func_ptr))(&args); } + break; } } -} +} \ No newline at end of file