diff --git a/relocator/src/ModuleDataPersistence.cpp b/relocator/src/ModuleDataPersistence.cpp index 794b1ea..6bdabf5 100644 --- a/relocator/src/ModuleDataPersistence.cpp +++ b/relocator/src/ModuleDataPersistence.cpp @@ -26,8 +26,8 @@ bool ModuleDataPersistence::saveModuleData(module_information_t * moduleInformat module_data->bssSize = module->getBSSSize(); module_data->sbssAddr = module->getSBSSAddr(); module_data->sbssSize = module->getSBSSSize(); - module_data->address = module->getAddress(); - module_data->size = module->getSize(); + module_data->endAddress = module->getStartAddress(); + module_data->startAddress = module->getEndAddress(); module_data->entrypoint = module->getEntrypoint(); @@ -65,8 +65,8 @@ std::vector ModuleDataPersistence::loadModuleData(module_informatio moduleData->setBSSLocation(module_data->bssAddr, module_data->bssSize); moduleData->setSBSSLocation(module_data->sbssAddr, module_data->sbssSize); moduleData->setEntrypoint(module_data->entrypoint); - moduleData->setAddress(module_data->address); - moduleData->setSize(module_data->size); + moduleData->setStartAddress(module_data->startAddress); + moduleData->setEndAddress(module_data->endAddress); for(uint32_t j = 0; j < DYN_LINK_RELOCATION_LIST_LENGTH; j++) { dyn_linking_relocation_entry_t * linking_entry = &(module_data->linking_entries[j]); diff --git a/source/common/module_defines.h b/source/common/module_defines.h index 6162b13..f44fe89 100644 --- a/source/common/module_defines.h +++ b/source/common/module_defines.h @@ -40,8 +40,8 @@ struct module_information_single_t { uint32_t sbssAddr; uint32_t sbssSize; uint32_t entrypoint; - uint32_t address; - uint32_t size; + uint32_t startAddress; + uint32_t endAddress; }; #define MAXIMUM_MODULES 8 diff --git a/source/common/relocation_defines.h b/source/common/relocation_defines.h index e1d7051..5efdf79 100644 --- a/source/common/relocation_defines.h +++ b/source/common/relocation_defines.h @@ -14,6 +14,7 @@ typedef enum RelocationType{ } RelocationType; typedef struct relocation_trampolin_entry_t { + uint32_t id; uint32_t trampolin[4]; RelocationTrampolinStatus status = RELOC_TRAMP_FREE; } relocation_trampolin_entry_t; diff --git a/source/main.cpp b/source/main.cpp index c68a137..325b595 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -81,13 +81,11 @@ int main(int argc, char **argv) { // Currently the size of the .init is ~ 0x24 bytes. We substract 0x100 to be safe. uint32_t textSectionStart = textStart() - 0x1000; - *gModuleData = {}; - DirList setupModules("fs:/vol/external01/wiiu/modules/setup", ".rpx", DirList::Files, 1); setupModules.SortList(); for(int i = 0; i < setupModules.GetFilecount(); i++) { - *gModuleData = {}; + memset((void*)gModuleData, 0, sizeof(module_information_t)); DEBUG_FUNCTION_LINE("Trying to run %s",setupModules.GetFilepath(i)); ModuleData * moduleData = ModuleDataFactory::load(setupModules.GetFilepath(i), 0x00900000, 0x01000000 - textSectionStart, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH); if(moduleData == NULL) { @@ -115,13 +113,12 @@ int main(int argc, char **argv) { delete moduleData; } - *gModuleData = {}; + memset((void*)gModuleData, 0, sizeof(module_information_t)); DirList modules("fs:/vol/external01/wiiu/modules", ".rpx", DirList::Files, 1); modules.SortList(); for(int i = 0; i < modules.GetFilecount(); i++) { - *gModuleData = {}; DEBUG_FUNCTION_LINE("Loading module %s",modules.GetFilepath(i)); ModuleData * moduleData = ModuleDataFactory::load(modules.GetFilepath(i), 0x00900000, 0x01000000 - textSectionStart, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH); @@ -130,7 +127,7 @@ int main(int argc, char **argv) { DEBUG_FUNCTION_LINE("Successfully loaded %s", modules.GetFilepath(i)); ModuleDataPersistence::saveModuleData(gModuleData, moduleData); delete moduleData; - }else{ + } else { DEBUG_FUNCTION_LINE("Failed to load %s", modules.GetFilepath(i)); } } diff --git a/source/module/ModuleData.h b/source/module/ModuleData.h index 59da3c1..eec61a7 100644 --- a/source/module/ModuleData.h +++ b/source/module/ModuleData.h @@ -48,12 +48,12 @@ public: this->entrypoint = addr; } - void setAddress(uint32_t addr) { - this->address = addr; + void setStartAddress(uint32_t addr) { + this->startAddress = addr; } - void setSize(uint32_t size) { - this->size = size; + void setEndAddress(uint32_t endAddress) { + this->endAddress = endAddress; } void addRelocationData(RelocationData * relocation_data) { @@ -84,12 +84,12 @@ public: return entrypoint; } - uint32_t getAddress() { - return address; + uint32_t getStartAddress() { + return startAddress; } - uint32_t getSize() { - return address; + uint32_t getEndAddress() { + return endAddress; } std::string toString(); @@ -100,7 +100,7 @@ private: uint32_t bssSize = 0; uint32_t sbssAddr = 0; uint32_t sbssSize = 0; - uint32_t address = 0; - uint32_t size = 0; + uint32_t startAddress = 0; + uint32_t endAddress = 0; uint32_t entrypoint = 0; }; diff --git a/source/module/ModuleDataFactory.cpp b/source/module/ModuleDataFactory.cpp index d70be0f..48dc34b 100644 --- a/source/module/ModuleDataFactory.cpp +++ b/source/module/ModuleDataFactory.cpp @@ -52,6 +52,8 @@ ModuleData * ModuleDataFactory::load(std::string path, uint32_t destination_addr uint32_t entrypoint = offset_text + (uint32_t) reader.get_entry() - 0x02000000; uint32_t totalSize = 0; + uint32_t endAddress = 0; + for(uint32_t i = 0; i < sec_num; ++i ) { section* psec = reader.sections[i]; @@ -104,6 +106,10 @@ ModuleData * ModuleDataFactory::load(std::string path, uint32_t destination_addr } totalSize += sectionSize; + if(endAddress < destination + sectionSize){ + endAddress = destination + sectionSize; + } + DCFlushRange((void*)destination, sectionSize); ICInvalidateRange((void*)destination, sectionSize); } @@ -133,14 +139,15 @@ ModuleData * ModuleDataFactory::load(std::string path, uint32_t destination_addr free(destinations); moduleData->setEntrypoint(entrypoint); - moduleData->setAddress(destination_address); - moduleData->setSize(totalSize); + moduleData->setStartAddress(destination_address); + moduleData->setEndAddress(endAddress); DEBUG_FUNCTION_LINE("Saved entrypoint as %08X", entrypoint); + DEBUG_FUNCTION_LINE("Saved startAddress as %08X", destination_address); + DEBUG_FUNCTION_LINE("Saved endAddress as %08X", endAddress); return moduleData; } - std::vector ModuleDataFactory::getImportRelocationData(elfio& reader, uint8_t ** destinations) { std::vector result; std::map infoMap; diff --git a/source/module/ModuleDataPersistence.cpp b/source/module/ModuleDataPersistence.cpp index 9808db4..9e29a40 100644 --- a/source/module/ModuleDataPersistence.cpp +++ b/source/module/ModuleDataPersistence.cpp @@ -30,8 +30,8 @@ bool ModuleDataPersistence::saveModuleData(module_information_t * moduleInformat module_data->bssSize = module->getBSSSize(); module_data->sbssAddr = module->getSBSSAddr(); module_data->sbssSize = module->getSBSSSize(); - module_data->address = module->getAddress(); - module_data->size = module->getSize(); + module_data->startAddress = module->getStartAddress(); + module_data->endAddress = module->getEndAddress(); module_data->entrypoint = module->getEntrypoint(); @@ -68,8 +68,8 @@ std::vector ModuleDataPersistence::loadModuleData(module_informatio moduleData->setBSSLocation(module_data->bssAddr, module_data->bssSize); moduleData->setSBSSLocation(module_data->sbssAddr, module_data->sbssSize); moduleData->setEntrypoint(module_data->entrypoint); - moduleData->setAddress(module_data->address); - moduleData->setSize(module_data->size); + moduleData->setStartAddress(module_data->startAddress); + moduleData->setEndAddress(module_data->endAddress); for(uint32_t j = 0; j < DYN_LINK_RELOCATION_LIST_LENGTH; j++) { dyn_linking_relocation_entry_t * linking_entry = &(module_data->linking_entries[j]);