diff --git a/relocator/src/DynamicLinkingHelper.cpp b/relocator/src/DynamicLinkingHelper.cpp index 1018c38..ff44f7b 100644 --- a/relocator/src/DynamicLinkingHelper.cpp +++ b/relocator/src/DynamicLinkingHelper.cpp @@ -9,7 +9,7 @@ dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_li return nullptr; } dyn_linking_function_t *result = nullptr; - for (auto & function : data->functions) { + for (auto &function: data->functions) { dyn_linking_function_t *curEntry = &function; if (strlen(curEntry->functionName) == 0) { if (strlen(functionName) > DYN_LINK_FUNCTION_NAME_LENGTH) { @@ -41,7 +41,7 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocatio return nullptr; } dyn_linking_import_t *result = nullptr; - for (auto & import : data->imports) { + for (auto &import: data->imports) { dyn_linking_import_t *curEntry = &import; if (strlen(curEntry->importName) == 0) { if (strlen(importName) > DYN_LINK_IMPORT_NAME_LENGTH) { @@ -60,15 +60,17 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocatio return result; } -bool DynamicLinkingHelper::addRelocationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, const RelocationData &relocationData) { +bool DynamicLinkingHelper::addRelocationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, + const RelocationData &relocationData) { return addRelocationEntry(linking_data, linking_entries, linking_entry_length, relocationData.getType(), relocationData.getOffset(), relocationData.getAddend(), relocationData.getDestination(), relocationData.getName(), relocationData.getImportRPLInformation()); } -bool DynamicLinkingHelper::addRelocationEntry(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) { +bool DynamicLinkingHelper::addRelocationEntry(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) { dyn_linking_import_t *importInfoGbl = DynamicLinkingHelper::getOrAddImport(linking_data, rplInfo.getName().c_str(), rplInfo.isData()); if (importInfoGbl == nullptr) { DEBUG_FUNCTION_LINE("Getting import info failed. Probably maximum of %d rpl files to import reached.\n", DYN_LINK_IMPORT_LIST_LENGTH); @@ -85,7 +87,8 @@ bool DynamicLinkingHelper::addRelocationEntry(dyn_linking_relocation_data_t *lin importInfoGbl); } -bool DynamicLinkingHelper::addRelocationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination, dyn_linking_function_t *functionName, +bool DynamicLinkingHelper::addRelocationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination, + dyn_linking_function_t *functionName, dyn_linking_import_t *importInfo) { for (uint32_t i = 0; i < linking_entry_length; i++) { dyn_linking_relocation_entry_t *curEntry = &(linking_entries[i]); diff --git a/relocator/src/DynamicLinkingHelper.h b/relocator/src/DynamicLinkingHelper.h index 3faf713..ce64b30 100644 --- a/relocator/src/DynamicLinkingHelper.h +++ b/relocator/src/DynamicLinkingHelper.h @@ -49,11 +49,14 @@ public: static bool addRelocationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, const RelocationData &relocationData); - static bool addRelocationEntry(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 + addRelocationEntry(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 - addRelocationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination, dyn_linking_function_t *functionName, dyn_linking_import_t *importInfo); + addRelocationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination, + dyn_linking_function_t *functionName, dyn_linking_import_t *importInfo); private: DynamicLinkingHelper() = default; diff --git a/relocator/src/ElfUtils.cpp b/relocator/src/ElfUtils.cpp index 03b3753..3edf605 100644 --- a/relocator/src/ElfUtils.cpp +++ b/relocator/src/ElfUtils.cpp @@ -4,7 +4,8 @@ #include "ElfUtils.h" // See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144 -bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, RelocationType reloc_type) { +bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, + RelocationType reloc_type) { if (type == R_PPC_NONE) { return true; } diff --git a/relocator/src/ElfUtils.h b/relocator/src/ElfUtils.h index 7a51ca0..586cd08 100644 --- a/relocator/src/ElfUtils.h +++ b/relocator/src/ElfUtils.h @@ -42,5 +42,6 @@ extern "C" { class ElfUtils { public: - static bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, RelocationType reloc_type); + static bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, + RelocationType reloc_type); }; diff --git a/relocator/src/ModuleDataPersistence.cpp b/relocator/src/ModuleDataPersistence.cpp index f28539f..9ea51ba 100644 --- a/relocator/src/ModuleDataPersistence.cpp +++ b/relocator/src/ModuleDataPersistence.cpp @@ -34,21 +34,21 @@ std::vector ModuleDataPersistence::loadModuleData(module_information moduleData.setExportName(module_data->module_export_name); - for (auto & export_entry : module_data->export_entries) { + for (auto &export_entry: module_data->export_entries) { if (export_entry.address == 0) { continue; } moduleData.addExportData(ExportData(static_cast(export_entry.type), export_entry.name, reinterpret_cast(export_entry.address))); } - for (auto & hook_entry : module_data->hook_entries) { + for (auto &hook_entry: module_data->hook_entries) { if (hook_entry.target == 0) { continue; } moduleData.addHookData(HookData(static_cast(hook_entry.type), reinterpret_cast(hook_entry.target))); } - for (auto & linking_entry : module_data->linking_entries) { + for (auto &linking_entry: module_data->linking_entries) { if (linking_entry.destination == nullptr) { break; } diff --git a/relocator/src/entry.cpp b/relocator/src/entry.cpp index 604192d..3f1d8f0 100644 --- a/relocator/src/entry.cpp +++ b/relocator/src/entry.cpp @@ -43,13 +43,13 @@ extern "C" int _start(int argc, char **argv) { DEBUG_FUNCTION_LINE_VERBOSE("Call real one\n"); log_deinit(); - + return ((int (*)(int, char **)) (*(unsigned int *) 0x1005E040))(argc, argv); } bool doRelocation(std::vector &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length, bool skipAllocReplacement) { std::map moduleCache; - for (auto const &curReloc : relocData) { + for (auto const &curReloc: relocData) { std::string functionName = curReloc.getName(); std::string rplName = curReloc.getImportRPLInformation().getName(); uint32_t functionAddress = 0; @@ -113,7 +113,7 @@ bool doRelocation(std::vector &relocData, relocation_trampolin_e bool ResolveRelocations(std::vector &loadedModules, bool skipMemoryMappingModule) { bool wasSuccessful = true; - for (auto &curModule : loadedModules) { + for (auto &curModule: loadedModules) { DEBUG_FUNCTION_LINE_VERBOSE("Let's do the relocations for %s\n", curModule.getExportName().c_str()); if (wasSuccessful) { std::vector relocData = curModule.getRelocationDataList(); @@ -155,7 +155,7 @@ extern "C" void doStart(int argc, char **argv) { std::vector loadedModules = OrderModulesByDependencies(loadedModulesUnordered); bool applicationEndHookLoaded = false; - for (auto &curModule : loadedModules) { + for (auto &curModule: loadedModules) { if (curModule.getExportName() == "homebrew_applicationendshook") { DEBUG_FUNCTION_LINE_VERBOSE("We have ApplicationEndsHook Module!\n"); applicationEndHookLoaded = true; @@ -164,8 +164,8 @@ extern "C" void doStart(int argc, char **argv) { } // Make sure WUMS_HOOK_APPLICATION_ENDS and WUMS_HOOK_FINI_WUT are called - for (auto &curModule : loadedModules) { - for (auto &curHook : curModule.getHookDataList()) { + for (auto &curModule: loadedModules) { + for (auto &curHook: curModule.getHookDataList()) { if (curHook.getType() == WUMS_HOOK_APPLICATION_ENDS || curHook.getType() == WUMS_HOOK_FINI_WUT_DEVOPTAB) { if (!applicationEndHookLoaded) { OSFatal_printf("%s requires module homebrew_applicationendshook", curModule.getExportName().c_str()); @@ -181,7 +181,7 @@ extern "C" void doStart(int argc, char **argv) { DEBUG_FUNCTION_LINE_VERBOSE("Resolve relocations without replacing alloc functions\n"); ResolveRelocations(loadedModules, true); - for (auto &curModule : loadedModules) { + for (auto &curModule: loadedModules) { if (curModule.isInitBeforeRelocationDoneHook()) { CallHook(curModule, WUMS_HOOK_INIT_WUT_MALLOC); CallHook(curModule, WUMS_HOOK_INIT_WUT_NEWLIB); @@ -209,7 +209,7 @@ extern "C" void doStart(int argc, char **argv) { } } - for (auto &curModule : loadedModules) { + for (auto &curModule: loadedModules) { if (!curModule.isInitBeforeRelocationDoneHook()) { CallHook(curModule, WUMS_HOOK_INIT_WUT_MALLOC); CallHook(curModule, WUMS_HOOK_INIT_WUT_NEWLIB); @@ -246,7 +246,7 @@ std::vector OrderModulesByDependencies(const std::vector while (true) { bool canBreak = true; bool weDidSomething = false; - for (auto const &curModule : loadedModules) { + for (auto const &curModule: loadedModules) { if (std::find(loadedModulesEntrypoints.begin(), loadedModulesEntrypoints.end(), curModule.getEntrypoint()) != loadedModulesEntrypoints.end()) { // DEBUG_FUNCTION_LINE("%s [%08X] is already loaded\n", curModule.getExportName().c_str(), curModule.getEntrypoint()); continue; @@ -254,7 +254,7 @@ std::vector OrderModulesByDependencies(const std::vector canBreak = false; DEBUG_FUNCTION_LINE_VERBOSE("Check if we can load %s\n", curModule.getExportName().c_str()); std::vector importsFromOtherModules; - for (const auto& curReloc: curModule.getRelocationDataList()) { + for (const auto &curReloc: curModule.getRelocationDataList()) { std::string curRPL = curReloc.getImportRPLInformation().getName(); if (curRPL.rfind("homebrew", 0) == 0) { if (std::find(importsFromOtherModules.begin(), importsFromOtherModules.end(), curRPL) != importsFromOtherModules.end()) { @@ -266,7 +266,7 @@ std::vector OrderModulesByDependencies(const std::vector } } bool canLoad = true; - for (auto &curImportRPL : importsFromOtherModules) { + for (auto &curImportRPL: importsFromOtherModules) { if (std::find(loadedModulesExportNames.begin(), loadedModulesExportNames.end(), curImportRPL) != loadedModulesExportNames.end()) { } else { diff --git a/relocator/src/hooks.cpp b/relocator/src/hooks.cpp index db42c1c..0447575 100644 --- a/relocator/src/hooks.cpp +++ b/relocator/src/hooks.cpp @@ -28,12 +28,12 @@ void CallHook(const std::vector &modules, wums_hook_type_t type) { } void CallHook(const ModuleData &module, wums_hook_type_t type) { - if(!module.relocationsDone){ + if (!module.relocationsDone) { DEBUG_FUNCTION_LINE("Hook not called because the relocations failed\n"); return; } - for (auto &curHook : module.getHookDataList()) { + for (auto &curHook: module.getHookDataList()) { auto func_ptr = (uint32_t) curHook.getTarget(); if (func_ptr == 0) { DEBUG_FUNCTION_LINE("Hook ptr was NULL\n"); diff --git a/relocator/src/utils/logger.c b/relocator/src/utils/logger.c index 0c37854..ddaf04d 100644 --- a/relocator/src/utils/logger.c +++ b/relocator/src/utils/logger.c @@ -35,31 +35,32 @@ static volatile int log_lock __attribute__((section(".data"))) = 0; typedef uint16_t sa_family_t; -struct in_addr -{ - unsigned int s_addr; +struct in_addr { + unsigned int s_addr; }; -struct sockaddr -{ - sa_family_t sa_family; - char sa_data[]; +struct sockaddr { + sa_family_t sa_family; + char sa_data[]; }; -struct sockaddr_in -{ - unsigned short sin_family; - unsigned short sin_port; - struct in_addr sin_addr; - char sin_zero[8]; +struct sockaddr_in { + unsigned short sin_family; + unsigned short sin_port; + struct in_addr sin_addr; + char sin_zero[8]; }; typedef uint32_t socklen_t; extern int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen); + extern int socket(int domain, int type, int protocol); + extern int socketclose(int sockfd); + extern int sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen); + extern uint32_t htonl(uint32_t val); void log_init() { @@ -77,11 +78,11 @@ void log_init() { } void log_deinit() { - if (log_socket < 0){ + if (log_socket < 0) { return; } - if(socketclose(log_socket) != 0) { - return; + if (socketclose(log_socket) != 0) { + return; } } diff --git a/source/ElfUtils.cpp b/source/ElfUtils.cpp index 867a3fc..54da647 100644 --- a/source/ElfUtils.cpp +++ b/source/ElfUtils.cpp @@ -108,7 +108,8 @@ uint32_t load_loader_elf(unsigned char *baseAddress, char *elf_data, uint32_t fi } // See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144 -bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, RelocationType reloc_type) { +bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, + RelocationType reloc_type) { if (type == R_PPC_NONE) { return true; } diff --git a/source/ElfUtils.h b/source/ElfUtils.h index ecf1959..44a3356 100644 --- a/source/ElfUtils.h +++ b/source/ElfUtils.h @@ -47,5 +47,6 @@ uint32_t load_loader_elf(unsigned char *baseAddress, char *elf_data, uint32_t fi class ElfUtils { public: - static bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, RelocationType reloc_type); + static bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, + RelocationType reloc_type); }; diff --git a/source/globals.h b/source/globals.h index 0f0153e..f468494 100644 --- a/source/globals.h +++ b/source/globals.h @@ -1,8 +1,9 @@ #pragma once + #include #include -#define MEMORY_REGION_START 0x00800000 +#define MEMORY_REGION_START 0x00800000 #define MEMORY_REGION_SIZE 0x00800000 #define MEMORY_REGION_USABLE_HEAP_START (MEMORY_REGION_START + 0x00080000) diff --git a/source/main.cpp b/source/main.cpp index f34bfd1..c2fdd3e 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -42,13 +42,13 @@ extern "C" uint32_t textStart(); extern "C" void _SYSLaunchMenuWithCheckingAccount(nn::act::SlotNo slot); bool doRelocation(std::vector &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length) { - for (auto const &curReloc : relocData) { + for (auto const &curReloc: relocData) { std::string functionName = curReloc.getName(); std::string rplName = curReloc.getImportRPLInformation().getName(); int32_t isData = curReloc.getImportRPLInformation().isData(); OSDynLoad_Module rplHandle = nullptr; - if(OSDynLoad_IsModuleLoaded(rplName.c_str(), &rplHandle) != OS_DYNLOAD_OK) { + if (OSDynLoad_IsModuleLoaded(rplName.c_str(), &rplHandle) != OS_DYNLOAD_OK) { // only acquire if not already loaded. OSDynLoad_Acquire(rplName.c_str(), &rplHandle); } @@ -83,7 +83,8 @@ int main(int argc, char **argv) { 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)); - std::optional moduleData = ModuleDataFactory::load(setupModules.GetFilepath(i), &destination_address, textSectionStart - destination_address, 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; @@ -117,7 +118,8 @@ int main(int argc, char **argv) { uint32_t destination_address = ((uint32_t) gModuleData + (sizeof(module_information_t) + 0x0000FFFF)) & 0xFFFF0000; for (int i = 0; i < modules.GetFilecount(); i++) { DEBUG_FUNCTION_LINE("Loading module %s", modules.GetFilepath(i)); - std::optional moduleData = ModuleDataFactory::load(modules.GetFilepath(i), &destination_address, MEMORY_REGION_USABLE_END - destination_address, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH); + std::optional moduleData = ModuleDataFactory::load(modules.GetFilepath(i), &destination_address, MEMORY_REGION_USABLE_END - destination_address, gModuleData->trampolines, + DYN_LINK_TRAMPOLIN_LIST_LENGTH); if (moduleData) { DEBUG_FUNCTION_LINE("Successfully loaded %s", modules.GetFilepath(i)); diff --git a/source/module/DynamicLinkingHelper.cpp b/source/module/DynamicLinkingHelper.cpp index da1e336..73899cd 100644 --- a/source/module/DynamicLinkingHelper.cpp +++ b/source/module/DynamicLinkingHelper.cpp @@ -64,12 +64,15 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocatio return result; } -bool DynamicLinkingHelper::addRelocationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, const RelocationData &relocationData) { - return addReloationEntry(linking_data, linking_entries, linking_entry_length, relocationData.getType(), relocationData.getOffset(), relocationData.getAddend(), relocationData.getDestination(), relocationData.getName(), +bool DynamicLinkingHelper::addRelocationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, + const RelocationData &relocationData) { + return addReloationEntry(linking_data, linking_entries, linking_entry_length, relocationData.getType(), relocationData.getOffset(), relocationData.getAddend(), relocationData.getDestination(), + relocationData.getName(), relocationData.getImportRPLInformation()); } -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, +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) { dyn_linking_import_t *importInfoGbl = DynamicLinkingHelper::getOrAddImport(linking_data, rplInfo.getName().c_str(), rplInfo.isData()); if (importInfoGbl == NULL) { @@ -87,7 +90,8 @@ bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *link importInfoGbl); } -bool DynamicLinkingHelper::addRelocationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination, dyn_linking_function_t *functionName, +bool DynamicLinkingHelper::addRelocationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination, + dyn_linking_function_t *functionName, dyn_linking_import_t *importInfo) { for (uint32_t i = 0; i < linking_entry_length; i++) { dyn_linking_relocation_entry_t *curEntry = &(linking_entries[i]); diff --git a/source/module/DynamicLinkingHelper.h b/source/module/DynamicLinkingHelper.h index 023e306..1ca1afd 100644 --- a/source/module/DynamicLinkingHelper.h +++ b/source/module/DynamicLinkingHelper.h @@ -49,11 +49,13 @@ public: static bool addRelocationEntry(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, std::string name, const ImportRPLInformation &rplInfo); static bool - addRelocationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination, dyn_linking_function_t *functionName, dyn_linking_import_t *importInfo); + addRelocationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination, + dyn_linking_function_t *functionName, dyn_linking_import_t *importInfo); private: DynamicLinkingHelper() = default; diff --git a/source/module/ModuleData.cpp b/source/module/ModuleData.cpp index e2f3047..bf648d4 100644 --- a/source/module/ModuleData.cpp +++ b/source/module/ModuleData.cpp @@ -3,7 +3,7 @@ std::string ModuleData::toString() const { std::string res = StringTools::strfmt("Entrypoint %08X, bss: %08X (%d), bss: %08X (%d)\n", getEntrypoint(), getBSSAddr(), getBSSSize(), getSBSSAddr(), getSBSSSize()); - for (auto const &reloc : relocation_data_list) { + for (auto const &reloc: relocation_data_list) { res += reloc.toString(); } return res; diff --git a/source/module/ModuleData.h b/source/module/ModuleData.h index 3a7f31d..080b27a 100644 --- a/source/module/ModuleData.h +++ b/source/module/ModuleData.h @@ -141,6 +141,7 @@ public: void setSkipEntrypoint(bool value) { this->skipEntrypoint = value; } + void setInitBeforeRelocationDoneHook(bool value) { this->initBeforeRelocationDoneHook = value; } diff --git a/source/module/ModuleDataFactory.cpp b/source/module/ModuleDataFactory.cpp index 312ce54..4963315 100644 --- a/source/module/ModuleDataFactory.cpp +++ b/source/module/ModuleDataFactory.cpp @@ -26,7 +26,8 @@ using namespace ELFIO; -std::optional ModuleDataFactory::load(const std::string& path, uint32_t *destination_address_ptr, uint32_t maximum_size, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length) { +std::optional +ModuleDataFactory::load(const std::string &path, uint32_t *destination_address_ptr, uint32_t maximum_size, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length) { elfio reader; ModuleData moduleData; @@ -60,7 +61,7 @@ std::optional ModuleDataFactory::load(const std::string& path, uint3 uint32_t sectionSize = psec->get_size(); totalSize += sectionSize; - if(totalSize > maximum_size){ + if (totalSize > maximum_size) { DEBUG_FUNCTION_LINE("Couldn't load setup module because it's too big."); return {}; } @@ -131,7 +132,7 @@ std::optional ModuleDataFactory::load(const std::string& path, uint3 } std::vector relocationData = getImportRelocationData(reader, destinations); - for (auto const &reloc : relocationData) { + for (auto const &reloc: relocationData) { moduleData.addRelocationData(reloc); } @@ -280,7 +281,8 @@ std::vector ModuleDataFactory::getImportRelocationData(elfio &re return result; } -bool ModuleDataFactory::linkSection(elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length) { +bool ModuleDataFactory::linkSection(elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data, + uint32_t trampolin_data_length) { uint32_t sec_num = reader.sections.size(); for (uint32_t i = 0; i < sec_num; ++i) { diff --git a/source/module/ModuleDataFactory.h b/source/module/ModuleDataFactory.h index 9f15faf..206a55b 100644 --- a/source/module/ModuleDataFactory.h +++ b/source/module/ModuleDataFactory.h @@ -26,9 +26,11 @@ class ModuleDataFactory { public: - static std::optional load(const std::string& path, uint32_t *destination_address_ptr, uint32_t maximum_size, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length); + static std::optional + load(const std::string &path, uint32_t *destination_address_ptr, uint32_t maximum_size, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length); - static bool linkSection(ELFIO::elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length); + static bool linkSection(ELFIO::elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data, + uint32_t trampolin_data_length); static std::vector getImportRelocationData(ELFIO::elfio &reader, uint8_t **destinations); }; diff --git a/source/module/ModuleDataPersistence.cpp b/source/module/ModuleDataPersistence.cpp index cdc5ecb..46cd94e 100644 --- a/source/module/ModuleDataPersistence.cpp +++ b/source/module/ModuleDataPersistence.cpp @@ -18,7 +18,7 @@ bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformati DEBUG_FUNCTION_LINE("Saving reloation data for module at %08X", module.getEntrypoint()); // Relocation std::vector relocationData = module.getRelocationDataList(); - for (auto const &reloc : relocationData) { + for (auto const &reloc: relocationData) { if (!DynamicLinkingHelper::addRelocationEntry(&(moduleInformation->linking_data), module_data->linking_entries, DYN_LINK_RELOCATION_LIST_LENGTH, reloc)) { DEBUG_FUNCTION_LINE("Failed to add relocation entry\n"); @@ -27,9 +27,9 @@ bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformati } std::vector exportData = module.getExportDataList(); - for (auto const &curExport : exportData) { + for (auto const &curExport: exportData) { bool found = false; - for (auto &export_entry : module_data->export_entries) { + for (auto &export_entry: module_data->export_entries) { if (export_entry.address == 0) { export_entry.type = curExport.getType(); export_entry.name[0] = '\0'; @@ -46,9 +46,9 @@ bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformati } std::vector hookData = module.getHookDataList(); - for (auto const &curHook : hookData) { + for (auto const &curHook: hookData) { bool found = false; - for (auto &hook_entry : module_data->hook_entries) { + for (auto &hook_entry: module_data->hook_entries) { if (hook_entry.target == 0) { hook_entry.type = curHook.getType(); hook_entry.target = (uint32_t) curHook.getTarget(); @@ -109,7 +109,7 @@ std::vector ModuleDataPersistence::loadModuleData(module_information moduleData.setSkipEntrypoint(module_data->skipEntrypoint); moduleData.setInitBeforeRelocationDoneHook(module_data->initBeforeRelocationDoneHook); - for (auto &export_entrie : module_data->export_entries) { + for (auto &export_entrie: module_data->export_entries) { export_data_t *export_entry = &export_entrie; if (export_entry->address == 0) { continue; @@ -117,14 +117,14 @@ std::vector ModuleDataPersistence::loadModuleData(module_information moduleData.addExportData(ExportData(static_cast(export_entry->type), export_entry->name, reinterpret_cast(export_entry->address))); } - for (auto &hook_entry : module_data->hook_entries) { + for (auto &hook_entry: module_data->hook_entries) { if (hook_entry.target == 0) { continue; } moduleData.addHookData(HookData(static_cast(hook_entry.type), reinterpret_cast(hook_entry.target))); } - for (auto &linking_entry : module_data->linking_entries) { + for (auto &linking_entry: module_data->linking_entries) { if (linking_entry.destination == nullptr) { break; } diff --git a/source/module/RelocationData.cpp b/source/module/RelocationData.cpp index 1099237..ce7b008 100644 --- a/source/module/RelocationData.cpp +++ b/source/module/RelocationData.cpp @@ -2,5 +2,6 @@ #include "utils/StringTools.h" std::string RelocationData::toString() const { - return StringTools::strfmt("%s destination: %08X offset: %08X type: %02X addend: %d rplName: %s isData: %d \n", name.c_str(), destination, offset, type, addend, rplInfo.getName().c_str(), rplInfo.isData()); + return StringTools::strfmt("%s destination: %08X offset: %08X type: %02X addend: %d rplName: %s isData: %d \n", name.c_str(), destination, offset, type, addend, rplInfo.getName().c_str(), + rplInfo.isData()); } diff --git a/source/module/SectionInfo.h b/source/module/SectionInfo.h index ad1f032..8c7d30a 100644 --- a/source/module/SectionInfo.h +++ b/source/module/SectionInfo.h @@ -37,7 +37,7 @@ public: sectionSize(o2.sectionSize) { } - SectionInfo& operator=(const SectionInfo& other) = default; + SectionInfo &operator=(const SectionInfo &other) = default; virtual ~SectionInfo() = default;