diff --git a/relocator/src/DynamicLinkingHelper.cpp b/relocator/src/DynamicLinkingHelper.cpp index 0812586..0a9aec8 100644 --- a/relocator/src/DynamicLinkingHelper.cpp +++ b/relocator/src/DynamicLinkingHelper.cpp @@ -1,19 +1,16 @@ #include "DynamicLinkingHelper.h" -#include -#include -#include -#include "utils/logger.h" +#include dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_linking_relocation_data_t *data, const char *functionName) { - if (data == NULL) { - return NULL; + if (data == nullptr) { + return nullptr; } if (functionName == NULL) { return NULL; } dyn_linking_function_t *result = NULL; - for (int32_t i = 0; i < DYN_LINK_FUNCTION_LIST_LENGTH; i++) { - dyn_linking_function_t *curEntry = &(data->functions[i]); + for (auto & function : data->functions) { + dyn_linking_function_t *curEntry = &function; if (strlen(curEntry->functionName) == 0) { if (strlen(functionName) > DYN_LINK_FUNCTION_NAME_LENGTH) { DEBUG_FUNCTION_LINE("Failed to add function name, it's too long.\n"); @@ -44,8 +41,8 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocatio return NULL; } dyn_linking_import_t *result = NULL; - for (int32_t i = 0; i < DYN_LINK_IMPORT_LIST_LENGTH; i++) { - dyn_linking_import_t *curEntry = &(data->imports[i]); + for (auto & import : data->imports) { + dyn_linking_import_t *curEntry = &import; if (strlen(curEntry->importName) == 0) { if (strlen(importName) > DYN_LINK_IMPORT_NAME_LENGTH) { DEBUG_FUNCTION_LINE("Failed to add Import, it's too long.\n"); @@ -69,7 +66,7 @@ bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *link } bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination, - std::string name, const ImportRPLInformation &rplInfo) { + const std::string& name, const ImportRPLInformation &rplInfo) { dyn_linking_import_t *importInfoGbl = DynamicLinkingHelper::getOrAddImport(linking_data, rplInfo.getName().c_str(), rplInfo.isData()); if (importInfoGbl == NULL) { DEBUG_FUNCTION_LINE("Getting import info failed. Probably maximum of %d rpl files to import reached.\n", DYN_LINK_IMPORT_LIST_LENGTH); @@ -89,7 +86,7 @@ bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_entry_t *lin dyn_linking_import_t *importInfo) { for (uint32_t i = 0; i < linking_entry_length; i++) { dyn_linking_relocation_entry_t *curEntry = &(linking_entries[i]); - if (curEntry->functionEntry != NULL) { + if (curEntry->functionEntry != nullptr) { continue; } curEntry->type = type; diff --git a/relocator/src/DynamicLinkingHelper.h b/relocator/src/DynamicLinkingHelper.h index 1938bc6..e8d2cc6 100644 --- a/relocator/src/DynamicLinkingHelper.h +++ b/relocator/src/DynamicLinkingHelper.h @@ -49,7 +49,7 @@ public: static bool addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, const RelocationData &relocationData); - static bool addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination, std::string name, + static bool addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination, const std::string& name, const ImportRPLInformation &rplInfo); static bool diff --git a/relocator/src/ElfUtils.cpp b/relocator/src/ElfUtils.cpp index ea47783..1e1a108 100644 --- a/relocator/src/ElfUtils.cpp +++ b/relocator/src/ElfUtils.cpp @@ -1,5 +1,3 @@ -#include -#include #include #include "utils/logger.h" diff --git a/relocator/src/hooks.cpp b/relocator/src/hooks.cpp index 6883660..b10786e 100644 --- a/relocator/src/hooks.cpp +++ b/relocator/src/hooks.cpp @@ -1,6 +1,5 @@ #include #include "hooks.h" -#include "utils/logger.h" #include "globals.h" static const char **hook_names = (const char *[]) { @@ -21,7 +20,7 @@ void CallHook(const std::vector &modules, wums_hook_type_t type) { void CallHook(const ModuleData &module, wums_hook_type_t type) { for (auto &curHook : module.getHookDataList()) { - uint32_t func_ptr = (uint32_t) curHook.getTarget(); + auto func_ptr = (uint32_t) curHook.getTarget(); if (func_ptr == 0) { DEBUG_FUNCTION_LINE("Hook ptr was NULL\n"); break; @@ -33,7 +32,7 @@ void CallHook(const ModuleData &module, wums_hook_type_t type) { type == WUMS_HOOK_INIT_WUT || type == WUMS_HOOK_FINI_WUT)) { 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))(); + ((void (*)()) ((uint32_t *) func_ptr))(); break; } else if (type == WUMS_HOOK_INIT || type == WUMS_HOOK_RELOCATIONS_DONE) { diff --git a/source/main.cpp b/source/main.cpp index e5272fd..c91676f 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,21 +1,16 @@ -#include -#include +#include #include #include #include #include #include -#include -#include +#include #include -#include #include #include #include "fs/DirList.h" -#include "utils/logger.h" -#include "utils/utils.h" #include "module/ModuleDataPersistence.h" #include "module/ModuleDataFactory.h" #include "ElfUtils.h" @@ -49,7 +44,7 @@ bool doRelocation(std::vector &relocData, relocation_trampolin_e std::string functionName = curReloc.getName(); std::string rplName = curReloc.getImportRPLInformation().getName(); int32_t isData = curReloc.getImportRPLInformation().isData(); - OSDynLoad_Module rplHandle = 0; + OSDynLoad_Module rplHandle = nullptr; OSDynLoad_Acquire(rplName.c_str(), &rplHandle); uint32_t functionAddress = 0; @@ -79,10 +74,10 @@ int main(int argc, char **argv) { setupModules.SortList(); for (int i = 0; i < setupModules.GetFilecount(); i++) { + uint32_t destination_address = ((uint32_t) gModuleData + (sizeof(module_information_t) + 0x0000FFFF)) & 0xFFFF0000; memset((void *) gModuleData, 0, sizeof(module_information_t)); DEBUG_FUNCTION_LINE("Trying to run %s", setupModules.GetFilepath(i)); - uint32_t destination_address = ((uint32_t) gModuleData + (sizeof(module_information_t) + 0x0000FFFF)) & 0xFFFF0000; - std::optional moduleData = ModuleDataFactory::load(setupModules.GetFilepath(i), &destination_address, MEMORY_REGION_USABLE_END - textSectionStart, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH); + std::optional moduleData = ModuleDataFactory::load(setupModules.GetFilepath(i), &destination_address, textSectionStart - destination_address, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH); if (!moduleData) { DEBUG_FUNCTION_LINE("Failed to load %s", setupModules.GetFilepath(i)); continue;