2020-04-29 18:02:36 +02:00
|
|
|
#include "hooks.h"
|
|
|
|
#include "utils/logger.h"
|
|
|
|
|
2020-05-03 11:16:22 +02:00
|
|
|
void CallHook(plugin_information_t *pluginInformation, wups_loader_hook_type_t hook_type) {
|
|
|
|
CallHookEx(pluginInformation, hook_type, -1);
|
2020-04-29 18:02:36 +02:00
|
|
|
}
|
|
|
|
|
2020-05-03 11:16:22 +02:00
|
|
|
bool HasHookCallHook(plugin_information_t *pluginInformation, wups_loader_hook_type_t hook_type) {
|
|
|
|
for (int32_t plugin_index = 0; plugin_index < pluginInformation->number_used_plugins; plugin_index++) {
|
|
|
|
plugin_information_single_t *plugin_data = &pluginInformation->plugin_data[plugin_index];
|
2020-04-29 18:02:36 +02:00
|
|
|
|
2020-05-03 11:16:22 +02:00
|
|
|
for (uint32_t j = 0; j < plugin_data->info.number_used_hooks; j++) {
|
|
|
|
replacement_data_hook_t *hook_data = &plugin_data->info.hooks[j];
|
|
|
|
if (hook_data->type == hook_type) {
|
2020-04-29 18:02:36 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-03 11:16:22 +02:00
|
|
|
static const char **hook_names = (const char *[]) {
|
|
|
|
"WUPS_LOADER_HOOK_INIT_WUT_MALLOC",
|
|
|
|
"WUPS_LOADER_HOOK_FINI_WUT_MALLOC",
|
|
|
|
"WUPS_LOADER_HOOK_INIT_WUT_NEWLIB",
|
|
|
|
"WUPS_LOADER_HOOK_FINI_WUT_NEWLIB",
|
|
|
|
"WUPS_LOADER_HOOK_INIT_WUT_STDCPP",
|
|
|
|
"WUPS_LOADER_HOOK_FINI_WUT_STDCPP",
|
2021-03-16 17:55:32 +01:00
|
|
|
"WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB",
|
|
|
|
"WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB",
|
|
|
|
|
2020-05-03 11:16:22 +02:00
|
|
|
"WUPS_LOADER_HOOK_INIT_PLUGIN",
|
|
|
|
"WUPS_LOADER_HOOK_DEINIT_PLUGIN",
|
2021-03-16 17:55:32 +01:00
|
|
|
"WUPS_LOADER_HOOK_APPLICATION_STARTS",
|
2020-05-03 11:16:22 +02:00
|
|
|
"WUPS_LOADER_HOOK_FUNCTIONS_PATCHED",
|
|
|
|
"WUPS_LOADER_HOOK_RELEASE_FOREGROUND",
|
|
|
|
"WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND",
|
2021-03-16 17:55:32 +01:00
|
|
|
"WUPS_LOADER_HOOK_APPLICATION_REQUESTS_EXIT",
|
|
|
|
"WUPS_LOADER_HOOK_APPLICATION_ENDS",
|
|
|
|
"WUPS_LOADER_HOOK_VSYNC"};
|
2020-04-29 18:02:36 +02:00
|
|
|
|
2020-05-03 11:16:22 +02:00
|
|
|
void CallHookEx(plugin_information_t *pluginInformation, wups_loader_hook_type_t hook_type, int32_t plugin_index_needed) {
|
2020-08-09 18:14:58 +02:00
|
|
|
if(hook_type != WUPS_LOADER_HOOK_VSYNC) {
|
2021-02-19 19:41:04 +01:00
|
|
|
DEBUG_FUNCTION_LINE_VERBOSE("Calling hook of type %s [%d]", hook_names[hook_type], hook_type);
|
2020-08-09 18:14:58 +02:00
|
|
|
}
|
2020-05-03 11:16:22 +02:00
|
|
|
for (int32_t plugin_index = 0; plugin_index < pluginInformation->number_used_plugins; plugin_index++) {
|
|
|
|
plugin_information_single_t *plugin_data = &pluginInformation->plugin_data[plugin_index];
|
|
|
|
if (plugin_index_needed != -1 && plugin_index_needed != plugin_index) {
|
2020-04-29 18:02:36 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-12-28 14:40:53 +01:00
|
|
|
//DEBUG_FUNCTION_LINE("Checking hook functions for %s.",plugin_data->plugin_name);
|
|
|
|
//DEBUG_FUNCTION_LINE("Found hooks: %d",plugin_data->number_used_hooks);
|
2020-05-03 11:16:22 +02:00
|
|
|
for (uint32_t j = 0; j < plugin_data->info.number_used_hooks; j++) {
|
|
|
|
replacement_data_hook_t *hook_data = &plugin_data->info.hooks[j];
|
|
|
|
if (hook_data->type == hook_type) {
|
2020-08-09 18:14:58 +02:00
|
|
|
if(hook_data->type != WUPS_LOADER_HOOK_VSYNC){
|
|
|
|
DEBUG_FUNCTION_LINE("Calling hook of type %s for plugin %s [%d]", hook_names[hook_data->type], plugin_data->meta.name, hook_type);
|
|
|
|
}
|
2020-05-03 11:16:22 +02:00
|
|
|
void *func_ptr = hook_data->func_pointer;
|
2020-12-26 14:17:50 +01:00
|
|
|
if (func_ptr != nullptr) {
|
2020-12-28 14:40:53 +01:00
|
|
|
//DEBUG_FUNCTION_LINE("function pointer is %08x",func_ptr);
|
2020-05-03 11:16:22 +02:00
|
|
|
if (hook_type == WUPS_LOADER_HOOK_INIT_PLUGIN) {
|
2020-12-26 14:17:50 +01:00
|
|
|
((void (*)()) ((uint32_t *) func_ptr))();
|
2020-05-03 11:16:22 +02:00
|
|
|
} else if (hook_type == WUPS_LOADER_HOOK_DEINIT_PLUGIN) {
|
2020-12-26 14:17:50 +01:00
|
|
|
((void (*)()) ((uint32_t *) func_ptr))();
|
2021-03-16 17:55:32 +01:00
|
|
|
} else if (hook_type == WUPS_LOADER_HOOK_APPLICATION_STARTS) {
|
|
|
|
((void (*)()) ((uint32_t *) func_ptr))();
|
2020-05-03 11:16:22 +02:00
|
|
|
} else if (hook_type == WUPS_LOADER_HOOK_FUNCTIONS_PATCHED) {
|
2020-12-26 14:17:50 +01:00
|
|
|
((void (*)()) ((uint32_t *) func_ptr))();
|
2021-03-16 17:55:32 +01:00
|
|
|
} else if (hook_type == WUPS_LOADER_HOOK_APPLICATION_ENDS) {
|
|
|
|
((void (*)()) ((uint32_t *) func_ptr))();
|
|
|
|
} else if (hook_type == WUPS_LOADER_HOOK_APPLICATION_REQUESTS_EXIT) {
|
2020-12-26 14:17:50 +01:00
|
|
|
((void (*)()) ((uint32_t *) func_ptr))();
|
2020-05-03 12:30:15 +02:00
|
|
|
} else if (hook_type == WUPS_LOADER_HOOK_INIT_WUT_MALLOC) {
|
2020-12-26 14:17:50 +01:00
|
|
|
((void (*)()) ((uint32_t *) func_ptr))();
|
2020-05-03 11:16:22 +02:00
|
|
|
} else if (hook_type == WUPS_LOADER_HOOK_FINI_WUT_MALLOC) {
|
2020-12-26 14:17:50 +01:00
|
|
|
((void (*)()) ((uint32_t *) func_ptr))();
|
2020-05-03 11:16:22 +02:00
|
|
|
} else if (hook_type == WUPS_LOADER_HOOK_INIT_WUT_NEWLIB) {
|
2020-12-26 14:17:50 +01:00
|
|
|
((void (*)()) ((uint32_t *) func_ptr))();
|
2020-05-03 11:16:22 +02:00
|
|
|
} else if (hook_type == WUPS_LOADER_HOOK_FINI_WUT_NEWLIB) {
|
2020-12-26 14:17:50 +01:00
|
|
|
((void (*)()) ((uint32_t *) func_ptr))();
|
2020-05-03 11:16:22 +02:00
|
|
|
} else if (hook_type == WUPS_LOADER_HOOK_INIT_WUT_STDCPP) {
|
2020-12-26 14:17:50 +01:00
|
|
|
((void (*)()) ((uint32_t *) func_ptr))();
|
2020-05-03 11:16:22 +02:00
|
|
|
} else if (hook_type == WUPS_LOADER_HOOK_FINI_WUT_STDCPP) {
|
2020-12-26 14:17:50 +01:00
|
|
|
((void (*)()) ((uint32_t *) func_ptr))();
|
2021-03-16 17:55:32 +01:00
|
|
|
} else if (hook_type == WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB) {
|
|
|
|
((void (*)()) ((uint32_t *) func_ptr))();
|
|
|
|
} else if (hook_type == WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB) {
|
|
|
|
((void (*)()) ((uint32_t *) func_ptr))();
|
2020-08-09 18:01:18 +02:00
|
|
|
} else if (hook_type == WUPS_LOADER_HOOK_RELEASE_FOREGROUND) {
|
2020-12-26 14:17:50 +01:00
|
|
|
((void (*)()) ((uint32_t *) func_ptr))();
|
2020-08-09 18:01:18 +02:00
|
|
|
} else if (hook_type == WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND) {
|
2020-12-26 14:17:50 +01:00
|
|
|
((void (*)()) ((uint32_t *) func_ptr))();
|
2020-08-09 18:14:58 +02:00
|
|
|
} else if (hook_type == WUPS_LOADER_HOOK_VSYNC) {
|
2020-12-26 14:17:50 +01:00
|
|
|
((void (*)()) ((uint32_t *) func_ptr))();
|
2020-05-03 11:16:22 +02:00
|
|
|
} else {
|
2020-05-03 11:40:44 +02:00
|
|
|
DEBUG_FUNCTION_LINE("######################################");
|
|
|
|
DEBUG_FUNCTION_LINE("Hook is not implemented %s [%d]", hook_names[hook_type], hook_type);
|
|
|
|
DEBUG_FUNCTION_LINE("######################################");
|
2020-04-29 18:02:36 +02:00
|
|
|
}
|
|
|
|
} else {
|
2020-12-28 14:40:53 +01:00
|
|
|
DEBUG_FUNCTION_LINE("Failed to call hook. It was not defined");
|
2020-04-29 18:02:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|