Adopt the hook-call of WUMS_HOOK_INIT to provide a pointer to the module_information_t struct

This commit is contained in:
Maschell 2020-06-06 22:12:18 +02:00
parent 3f6f956b70
commit b46639975e
3 changed files with 22 additions and 14 deletions

View File

@ -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;

View File

@ -3,4 +3,6 @@
#include <cstdint>
extern uint32_t MemoryMappingEffectiveToPhysicalPTR;
extern uint32_t MemoryMappingPhysicalToEffectivePTR;
extern uint32_t MemoryMappingPhysicalToEffectivePTR;
#define gModuleData ((module_information_t *) (0x00880000))

View File

@ -1,6 +1,7 @@
#include <wums.h>
#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<ModuleData> &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;
}
}
}
}