2020-06-01 16:35:34 +02:00
|
|
|
#include <wums.h>
|
|
|
|
#include "hooks.h"
|
2020-06-06 22:12:18 +02:00
|
|
|
#include "globals.h"
|
2020-06-01 16:35:34 +02:00
|
|
|
|
|
|
|
static const char **hook_names = (const char *[]) {
|
|
|
|
"WUMS_HOOK_INIT",
|
|
|
|
"WUMS_HOOK_APPLICATION_STARTS",
|
|
|
|
"WUMS_HOOK_APPLICATION_ENDS",
|
|
|
|
"WUMS_HOOK_INIT_WUT",
|
2020-06-10 16:20:20 +02:00
|
|
|
"WUMS_HOOK_FINI_WUT",
|
|
|
|
"WUMS_HOOK_RELOCATIONS_DONE"};
|
2020-06-01 16:35:34 +02:00
|
|
|
|
|
|
|
void CallHook(const std::vector<ModuleData> &modules, wums_hook_type_t type) {
|
2020-06-03 19:37:32 +02:00
|
|
|
DEBUG_FUNCTION_LINE("Calling hook of type %s [%d] for all modules\n", hook_names[type], type);
|
2020-06-01 16:35:34 +02:00
|
|
|
for (auto &curModule: modules) {
|
2020-06-03 19:37:32 +02:00
|
|
|
CallHook(curModule, type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CallHook(const ModuleData &module, wums_hook_type_t type) {
|
|
|
|
for (auto &curHook : module.getHookDataList()) {
|
2020-12-01 13:06:40 +01:00
|
|
|
auto func_ptr = (uint32_t) curHook.getTarget();
|
2020-06-06 22:12:18 +02:00
|
|
|
if (func_ptr == 0) {
|
|
|
|
DEBUG_FUNCTION_LINE("Hook ptr was NULL\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == curHook.getType()) {
|
2020-06-07 13:59:02 +02:00
|
|
|
if ((type == WUMS_HOOK_APPLICATION_STARTS ||
|
2020-06-06 22:12:18 +02:00
|
|
|
type == WUMS_HOOK_APPLICATION_ENDS ||
|
|
|
|
type == WUMS_HOOK_INIT_WUT ||
|
|
|
|
type == WUMS_HOOK_FINI_WUT)) {
|
2020-06-03 19:37:32 +02:00
|
|
|
DEBUG_FUNCTION_LINE("Calling hook of type %s [%d] %d for %s \n", hook_names[type], type, curHook.getType(), module.getExportName().c_str());
|
2020-12-01 13:06:40 +01:00
|
|
|
((void (*)()) ((uint32_t *) func_ptr))();
|
2020-06-10 16:20:20 +02:00
|
|
|
break;
|
|
|
|
} else if (type == WUMS_HOOK_INIT ||
|
|
|
|
type == WUMS_HOOK_RELOCATIONS_DONE) {
|
2020-06-06 22:12:18 +02:00
|
|
|
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;
|
2020-06-07 13:59:02 +02:00
|
|
|
((void (*)(wums_app_init_args_t *)) ((uint32_t *) func_ptr))(&args);
|
2020-06-01 16:35:34 +02:00
|
|
|
}
|
2020-06-06 22:12:18 +02:00
|
|
|
break;
|
2020-06-01 16:35:34 +02:00
|
|
|
}
|
|
|
|
}
|
2020-06-06 22:12:18 +02:00
|
|
|
}
|