diff --git a/relocator/Makefile b/relocator/Makefile index be39451..29074e7 100644 --- a/relocator/Makefile +++ b/relocator/Makefile @@ -31,7 +31,7 @@ export OBJCOPY := $(PREFIX)objcopy TARGET := relocator BUILD := build BUILD_DBG := $(TARGET)_dbg -SOURCES := src +SOURCES := src src/utils DATA := data diff --git a/relocator/src/DynamicLinkingHelper.cpp b/relocator/src/DynamicLinkingHelper.cpp index 640563f..66319a0 100644 --- a/relocator/src/DynamicLinkingHelper.cpp +++ b/relocator/src/DynamicLinkingHelper.cpp @@ -2,7 +2,7 @@ #include #include #include -#include "logger.h" +#include "utils/logger.h" #include "../../source/common/module_defines.h" dyn_linking_function_t * DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_linking_relocation_data_t * data, const char* functionName) { diff --git a/relocator/src/DynamicLinkingHelper.h b/relocator/src/DynamicLinkingHelper.h index a9a5a78..7f69345 100644 --- a/relocator/src/DynamicLinkingHelper.h +++ b/relocator/src/DynamicLinkingHelper.h @@ -1,9 +1,9 @@ #pragma once #include "../../source/common/dynamic_linking_defines.h" -#include "logger.h" +#include "utils/logger.h" #include #include -#include "RelocationData.h" +#include "../../source/module/RelocationData.h" class DynamicLinkingHelper { public: diff --git a/relocator/src/ElfUtils.cpp b/relocator/src/ElfUtils.cpp index 2f38dfd..f2b301c 100644 --- a/relocator/src/ElfUtils.cpp +++ b/relocator/src/ElfUtils.cpp @@ -2,7 +2,7 @@ #include #include -#include "logger.h" +#include "utils/logger.h" #include "ElfUtils.h" // See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144 diff --git a/relocator/src/ImportRPLInformation.h b/relocator/src/ImportRPLInformation.h deleted file mode 100644 index 8d00d77..0000000 --- a/relocator/src/ImportRPLInformation.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2018 Maschell - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - ****************************************************************************/ - -#pragma once - -#include -#include "logger.h" - -class ImportRPLInformation { - -public: - ImportRPLInformation(std::string name, bool isData = false) { - this->name = name; - this->_isData = isData; - } - - ~ImportRPLInformation() { - - } - - static ImportRPLInformation * createImportRPLInformation(std::string rawSectionName) { - std::string fimport = ".fimport_"; - std::string dimport = ".dimport_"; - - bool data = false; - - std::string rplName = ""; - - if(rawSectionName.size() < fimport.size()) { - return NULL; - } else if (std::equal(fimport.begin(), fimport.end(), rawSectionName.begin())) { - rplName = rawSectionName.substr(fimport.size()); - } else if (std::equal(dimport.begin(), dimport.end(), rawSectionName.begin())) { - rplName = rawSectionName.substr(dimport.size()); - data = true; - } else { - DEBUG_FUNCTION_LINE("invalid section name\n"); - return NULL; - } - DEBUG_FUNCTION_LINE("Adding %s of section index %02X. isData: %d\n",rplName.c_str(),data); - return new ImportRPLInformation(rplName, data); - } - - std::string getName() { - return name; - } - - bool isData() { - return _isData; - } - -private: - std::string name; - bool _isData = false; -}; diff --git a/relocator/src/ModuleData.h b/relocator/src/ModuleData.h deleted file mode 100644 index 157c551..0000000 --- a/relocator/src/ModuleData.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2018 Maschell - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - ****************************************************************************/ - -#pragma once - -#include -#include -#include "RelocationData.h" - -class ModuleData { -public: - ModuleData() { - } - - ~ModuleData() { - for (auto const& reloc : relocation_data_list) { - if(reloc != NULL) { - delete reloc; - } - } - } - - void setBSSLocation(uint32_t addr, uint32_t size) { - this->bssAddr = addr; - this->bssSize = size; - } - - void setSBSSLocation(uint32_t addr, uint32_t size) { - this->sbssAddr = addr; - this->sbssSize = size; - } - - void setEntrypoint(uint32_t addr) { - this->entrypoint = addr; - } - - void addRelocationData(RelocationData * relocation_data) { - relocation_data_list.push_back(relocation_data); - } - - std::vector getRelocationDataList() { - return relocation_data_list; - } - - uint32_t getBSSAddr() { - return bssAddr; - } - - uint32_t getBSSSize() { - return bssSize; - } - - uint32_t getSBSSAddr() { - return sbssAddr; - } - - uint32_t getSBSSSize() { - return sbssSize; - } - - uint32_t getEntrypoint() { - return entrypoint; - } -private: - std::vector relocation_data_list; - - uint32_t bssAddr = 0; - uint32_t bssSize = 0; - uint32_t sbssAddr = 0; - uint32_t sbssSize = 0; - uint32_t entrypoint = 0; -}; diff --git a/relocator/src/ModuleDataPersistence.cpp b/relocator/src/ModuleDataPersistence.cpp index 4cdf92b..07f78b3 100644 --- a/relocator/src/ModuleDataPersistence.cpp +++ b/relocator/src/ModuleDataPersistence.cpp @@ -1,8 +1,8 @@ #include "ModuleDataPersistence.h" #include "DynamicLinkingHelper.h" #include "../../source/common/module_defines.h" -#include "ModuleData.h" -#include "RelocationData.h" +#include "../../source/module/ModuleData.h" +#include "../../source/module/RelocationData.h" #include bool ModuleDataPersistence::saveModuleData(module_information_t * moduleInformation, ModuleData * module) { diff --git a/relocator/src/ModuleDataPersistence.h b/relocator/src/ModuleDataPersistence.h index fa8147f..89a27fb 100644 --- a/relocator/src/ModuleDataPersistence.h +++ b/relocator/src/ModuleDataPersistence.h @@ -1,7 +1,7 @@ #pragma once #include "../../source/common/module_defines.h" -#include "ModuleData.h" +#include "../../source/module/ModuleData.h" class ModuleDataPersistence { public: diff --git a/relocator/src/RelocationData.h b/relocator/src/RelocationData.h deleted file mode 100644 index 851ed41..0000000 --- a/relocator/src/RelocationData.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2018 Maschell - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - ****************************************************************************/ - -#pragma once - -#include -#include "ImportRPLInformation.h" - -class RelocationData { - -public: - RelocationData(char type, size_t offset, int32_t addend, void *destination, std::string name, ImportRPLInformation * rplInfo) { - this->type = type; - this->offset = offset; - this->addend = addend; - this->destination = destination; - this->name = name; - this->rplInfo = rplInfo; - } - - ~RelocationData() { - if(rplInfo != NULL) { - delete rplInfo; - } - } - - char getType() { - return type; - } - - size_t getOffset() { - return offset; - } - - int32_t getAddend() { - return addend; - } - - void * getDestination() { - return destination; - } - - std::string getName() { - return name; - } - - ImportRPLInformation * getImportRPLInformation() { - return rplInfo; - } -private: - char type; - size_t offset; - int32_t addend; - void *destination; - std::string name; - ImportRPLInformation * rplInfo; -}; diff --git a/relocator/src/entry.cpp b/relocator/src/entry.cpp index c9db158..0b33a6b 100644 --- a/relocator/src/entry.cpp +++ b/relocator/src/entry.cpp @@ -7,18 +7,17 @@ #include #include "../../source/common/dynamic_linking_defines.h" #include "../../source/common/module_defines.h" -#include "RelocationData.h" -#include "ModuleData.h" +#include "../../source/module/RelocationData.h" +#include "../../source/module/ModuleData.h" #include "ModuleDataPersistence.h" #include "ElfUtils.h" #include "../../source/common/relocation_defines.h" -#include "logger.h" -#include "dynamic.h" +#include "utils/logger.h" +#include "utils/dynamic.h" #define gModuleData ((module_information_t *) (0x00880000)) - extern "C" void doStart(int argc, char **argv); // We need to wrap it to make sure the main function is called AFTER our code. // The compiler tries to optimize this otherwise and calling the main function earlier @@ -51,7 +50,6 @@ bool doRelocation(std::vector &relocData, relocation_trampolin DEBUG_FUNCTION_LINE("Relocation failed\n"); return false; } - } DCFlushRange(tramp_data, tramp_length * sizeof(relocation_trampolin_entry_t)); diff --git a/relocator/src/dynamic.c b/relocator/src/utils/dynamic.c similarity index 100% rename from relocator/src/dynamic.c rename to relocator/src/utils/dynamic.c diff --git a/relocator/src/dynamic.h b/relocator/src/utils/dynamic.h similarity index 100% rename from relocator/src/dynamic.h rename to relocator/src/utils/dynamic.h diff --git a/relocator/src/import_stub.S b/relocator/src/utils/import_stub.S similarity index 100% rename from relocator/src/import_stub.S rename to relocator/src/utils/import_stub.S diff --git a/relocator/src/imports.h b/relocator/src/utils/imports.h similarity index 100% rename from relocator/src/imports.h rename to relocator/src/utils/imports.h diff --git a/relocator/src/logger.c b/relocator/src/utils/logger.c similarity index 100% rename from relocator/src/logger.c rename to relocator/src/utils/logger.c diff --git a/relocator/src/logger.h b/relocator/src/utils/logger.h similarity index 100% rename from relocator/src/logger.h rename to relocator/src/utils/logger.h diff --git a/relocator/src/memory.c b/relocator/src/utils/memory.c similarity index 100% rename from relocator/src/memory.c rename to relocator/src/utils/memory.c diff --git a/relocator/src/memory.h b/relocator/src/utils/memory.h similarity index 100% rename from relocator/src/memory.h rename to relocator/src/utils/memory.h