Use switch-case for hook calling

This commit is contained in:
Maschell 2022-10-03 16:27:28 +02:00
parent 616fc832d1
commit 178085750d

View File

@ -46,42 +46,47 @@ void CallHook(const std::unique_ptr<PluginContainer> &plugin, wups_loader_hook_t
DEBUG_FUNCTION_LINE_VERBOSE("Calling hook of type %s for plugin %s [%d]", hook_names[hook->getType()], plugin->metaInformation->getName().c_str(), hook_type); DEBUG_FUNCTION_LINE_VERBOSE("Calling hook of type %s for plugin %s [%d]", hook_names[hook->getType()], plugin->metaInformation->getName().c_str(), hook_type);
void *func_ptr = hook->getFunctionPointer(); void *func_ptr = hook->getFunctionPointer();
if (func_ptr != nullptr) { if (func_ptr != nullptr) {
if (hook_type == WUPS_LOADER_HOOK_INIT_PLUGIN || switch (hook_type) {
hook_type == WUPS_LOADER_HOOK_DEINIT_PLUGIN || case WUPS_LOADER_HOOK_INIT_WUT_MALLOC:
hook_type == WUPS_LOADER_HOOK_APPLICATION_STARTS || case WUPS_LOADER_HOOK_FINI_WUT_MALLOC:
hook_type == WUPS_LOADER_HOOK_APPLICATION_ENDS || case WUPS_LOADER_HOOK_INIT_WUT_NEWLIB:
hook_type == WUPS_LOADER_HOOK_APPLICATION_REQUESTS_EXIT || case WUPS_LOADER_HOOK_FINI_WUT_NEWLIB:
hook_type == WUPS_LOADER_HOOK_INIT_WUT_MALLOC || case WUPS_LOADER_HOOK_INIT_WUT_STDCPP:
hook_type == WUPS_LOADER_HOOK_FINI_WUT_MALLOC || case WUPS_LOADER_HOOK_FINI_WUT_STDCPP:
hook_type == WUPS_LOADER_HOOK_INIT_WUT_NEWLIB || case WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB:
hook_type == WUPS_LOADER_HOOK_FINI_WUT_NEWLIB || case WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB:
hook_type == WUPS_LOADER_HOOK_INIT_WUT_STDCPP || case WUPS_LOADER_HOOK_INIT_WUT_SOCKETS:
hook_type == WUPS_LOADER_HOOK_FINI_WUT_STDCPP || case WUPS_LOADER_HOOK_FINI_WUT_SOCKETS:
hook_type == WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB || case WUPS_LOADER_HOOK_INIT_WRAPPER:
hook_type == WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB || case WUPS_LOADER_HOOK_FINI_WRAPPER:
hook_type == WUPS_LOADER_HOOK_INIT_WUT_SOCKETS || case WUPS_LOADER_HOOK_GET_CONFIG:
hook_type == WUPS_LOADER_HOOK_FINI_WUT_SOCKETS || case WUPS_LOADER_HOOK_CONFIG_CLOSED:
hook_type == WUPS_LOADER_HOOK_INIT_WRAPPER || case WUPS_LOADER_HOOK_INIT_PLUGIN:
hook_type == WUPS_LOADER_HOOK_FINI_WRAPPER || case WUPS_LOADER_HOOK_DEINIT_PLUGIN:
hook_type == WUPS_LOADER_HOOK_GET_CONFIG || case WUPS_LOADER_HOOK_APPLICATION_STARTS:
hook_type == WUPS_LOADER_HOOK_CONFIG_CLOSED || case WUPS_LOADER_HOOK_RELEASE_FOREGROUND:
hook_type == WUPS_LOADER_HOOK_RELEASE_FOREGROUND || case WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND:
hook_type == WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND) { case WUPS_LOADER_HOOK_APPLICATION_REQUESTS_EXIT:
// clang-format off case WUPS_LOADER_HOOK_APPLICATION_ENDS:
((void(*)())((uint32_t *) func_ptr))(); // clang-format off
// clang-format on ((void(*)())((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_INIT_STORAGE) { // clang-format on
wups_loader_init_storage_args_t args; break;
args.open_storage_ptr = &StorageUtils::OpenStorage; case WUPS_LOADER_HOOK_INIT_STORAGE: {
args.close_storage_ptr = &StorageUtils::CloseStorage; wups_loader_init_storage_args_t args;
args.plugin_id = plugin->getMetaInformation()->getStorageId().c_str(); args.open_storage_ptr = &StorageUtils::OpenStorage;
// clang-format off args.close_storage_ptr = &StorageUtils::CloseStorage;
((void(*)(wups_loader_init_storage_args_t))((uint32_t *) func_ptr))(args); args.plugin_id = plugin->getMetaInformation()->getStorageId().c_str();
// clang-format on // clang-format off
} else { ((void(*)(wups_loader_init_storage_args_t))((uint32_t *) func_ptr))(args);
DEBUG_FUNCTION_LINE_ERR("######################################"); // clang-format on
DEBUG_FUNCTION_LINE_ERR("Hook is not implemented %s [%d]", hook_names[hook_type], hook_type); break;
DEBUG_FUNCTION_LINE_ERR("######################################"); }
default: {
DEBUG_FUNCTION_LINE_ERR("######################################");
DEBUG_FUNCTION_LINE_ERR("Hook is not implemented %s [%d]", hook_names[hook_type], hook_type);
DEBUG_FUNCTION_LINE_ERR("######################################");
}
} }
} else { } else {
DEBUG_FUNCTION_LINE_ERR("Failed to call hook. It was not defined"); DEBUG_FUNCTION_LINE_ERR("Failed to call hook. It was not defined");