Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Sep 18, 2021
1 parent a968fb3 commit ed79271
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 42 deletions.
57 changes: 20 additions & 37 deletions source/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,43 +62,26 @@ void CallHookEx(plugin_information_t *pluginInformation, wups_loader_hook_type_t
void *func_ptr = hook_data->func_pointer;
if (func_ptr != nullptr) {
//DEBUG_FUNCTION_LINE("function pointer is %08x",func_ptr);
if (hook_type == WUPS_LOADER_HOOK_INIT_PLUGIN) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_DEINIT_PLUGIN) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_APPLICATION_STARTS) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_FUNCTIONS_PATCHED) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_APPLICATION_ENDS) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_APPLICATION_REQUESTS_EXIT) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_INIT_WUT_MALLOC) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_FINI_WUT_MALLOC) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_INIT_WUT_NEWLIB) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_FINI_WUT_NEWLIB) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_INIT_WUT_STDCPP) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_FINI_WUT_STDCPP) {
((void (*)()) ((uint32_t *) func_ptr))();
} 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))();
} else if (hook_type == WUPS_LOADER_HOOK_INIT_WUT_SOCKETS) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_FINI_WUT_SOCKETS) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_RELEASE_FOREGROUND) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_VSYNC) {
if (hook_type == WUPS_LOADER_HOOK_INIT_PLUGIN ||
hook_type == WUPS_LOADER_HOOK_DEINIT_PLUGIN ||
hook_type == WUPS_LOADER_HOOK_APPLICATION_STARTS ||
hook_type == WUPS_LOADER_HOOK_FUNCTIONS_PATCHED ||
hook_type == WUPS_LOADER_HOOK_APPLICATION_ENDS ||
hook_type == WUPS_LOADER_HOOK_APPLICATION_REQUESTS_EXIT ||
hook_type == WUPS_LOADER_HOOK_INIT_WUT_MALLOC ||
hook_type == WUPS_LOADER_HOOK_FINI_WUT_MALLOC ||
hook_type == WUPS_LOADER_HOOK_INIT_WUT_NEWLIB ||
hook_type == WUPS_LOADER_HOOK_FINI_WUT_NEWLIB ||
hook_type == WUPS_LOADER_HOOK_INIT_WUT_STDCPP ||
hook_type == WUPS_LOADER_HOOK_FINI_WUT_STDCPP ||
hook_type == WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB ||
hook_type == WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB ||
hook_type == WUPS_LOADER_HOOK_INIT_WUT_SOCKETS ||
hook_type == WUPS_LOADER_HOOK_FINI_WUT_SOCKETS ||
hook_type == WUPS_LOADER_HOOK_RELEASE_FOREGROUND ||
hook_type == WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND ||
hook_type == WUPS_LOADER_HOOK_VSYNC
){
((void (*)()) ((uint32_t *) func_ptr))();
} else {
DEBUG_FUNCTION_LINE("######################################");
Expand Down
6 changes: 3 additions & 3 deletions source/utils/ElfUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
// }
auto distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
if (distance > 0x1FFFFFC || distance < -0x1FFFFFC) {
if (trampolin_data == NULL) {
if (trampolin_data == nullptr) {
DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampolin isn't provided");
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, distance);
return false;
} else {
relocation_trampolin_entry_t *freeSlot = NULL;
relocation_trampolin_entry_t *freeSlot = nullptr;
for (uint32_t i = 0; i < trampolin_data_length; i++) {
// We want to override "old" relocations of imports
// Pending relocations have the status RELOC_TRAMP_IMPORT_IN_PROGRESS.
Expand All @@ -96,7 +96,7 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
break;
}
}
if (freeSlot == NULL) {
if (freeSlot == nullptr) {
DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampolin data list is full");
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, target - (uint32_t) &(freeSlot->trampolin[0]));
return false;
Expand Down
4 changes: 2 additions & 2 deletions source/utils/exports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extern "C" int32_t WUPSLoadAndLinkByDataHandle(const plugin_data_handle *plugin_
if (plugin_data_handle_list != nullptr && plugin_data_handle_list_size != 0) {
for (uint32_t i = 0; i < plugin_data_handle_list_size; i++) {
plugin_data_handle handle = plugin_data_handle_list[i];
PluginData *pluginData = (PluginData *) handle;
auto *pluginData = (PluginData *) handle;
DEBUG_FUNCTION_LINE("Saving plugin data %08X", pluginData);
PluginDataPersistence::save(&gLinkOnReload.plugin_data[gLinkOnReload.number_used_plugins], *pluginData);

Expand All @@ -44,7 +44,7 @@ extern "C" int32_t WUPSDeletePluginContainer(const plugin_container_handle *hand
if (handle_list != nullptr && handle_list_size != 0) {
for (uint32_t i = 0; i < handle_list_size; i++) {
auto handle = handle_list[i];
PluginContainer *pluginContainer = (PluginContainer *) handle;
auto *pluginContainer = (PluginContainer *) handle;
DEBUG_FUNCTION_LINE("Delete plugin container: %08X", pluginContainer);
delete pluginContainer;
}
Expand Down

0 comments on commit ed79271

Please sign in to comment.