Add support for calling hooks of a single module

This commit is contained in:
Maschell 2020-06-03 19:37:32 +02:00
parent 94d40374f9
commit 62dd3cc0c5
2 changed files with 22 additions and 15 deletions

View File

@ -11,21 +11,27 @@ static const char **hook_names = (const char *[]) {
"WUMS_HOOK_FINI_WUT"};
void CallHook(const std::vector<ModuleData> &modules, wums_hook_type_t type) {
DEBUG_FUNCTION_LINE("Calling hook of type %s [%d]", hook_names[type], type);
DEBUG_FUNCTION_LINE("Calling hook of type %s [%d] for all modules\n", hook_names[type], type);
for (auto &curModule: modules) {
for (auto &curHook : curModule.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) && curHook.getType() == type) {
uint32_t func_ptr = (uint32_t) curHook.getTarget();
if (func_ptr == 0) {
DEBUG_FUNCTION_LINE("Hook ptr was NULL\n");
} else {
DEBUG_FUNCTION_LINE("Calling for module [%s]\n", curModule.getExportName().c_str());
((void (*)(void)) ((uint32_t *) func_ptr))();
}
CallHook(curModule, 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 {
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))();
}
}
}

View File

@ -5,4 +5,5 @@
#include <vector>
#include "../../source/module/ModuleData.h"
void CallHook(const std::vector<ModuleData> &modules, wums_hook_type_t type);
void CallHook(const std::vector<ModuleData> &modules, wums_hook_type_t type);
void CallHook(const ModuleData &module, wums_hook_type_t type);