diff --git a/relocator/src/ModuleDataPersistence.cpp b/relocator/src/ModuleDataPersistence.cpp index 4379ff2..7d818fa 100644 --- a/relocator/src/ModuleDataPersistence.cpp +++ b/relocator/src/ModuleDataPersistence.cpp @@ -1,13 +1,11 @@ #include "ModuleDataPersistence.h" #include "DynamicLinkingHelper.h" -#include "../../source/module/ModuleData.h" -#include "../../source/module/RelocationData.h" #include #include std::vector ModuleDataPersistence::loadModuleData(module_information_t *moduleInformation) { std::vector result; - if (moduleInformation == NULL) { + if (moduleInformation == nullptr) { DEBUG_FUNCTION_LINE("moduleInformation == NULL\n"); return result; } @@ -37,48 +35,46 @@ std::vector ModuleDataPersistence::loadModuleData(module_information moduleData.setExportName(module_data->module_export_name); - for (uint32_t j = 0; j < EXPORT_ENTRY_LIST_LENGTH; j++) { - export_data_t *export_entry = &(module_data->export_entries[j]); - if (export_entry->address == 0) { + 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))); + moduleData.addExportData(ExportData(static_cast(export_entry.type), export_entry.name, reinterpret_cast(export_entry.address))); } - for (uint32_t j = 0; j < HOOK_ENTRY_LIST_LENGTH; j++) { - hook_data_t *hook_entry = &(module_data->hook_entries[j]); + for (auto & hook_entrie : module_data->hook_entries) { + hook_data_t *hook_entry = &hook_entrie; if (hook_entry->target == 0) { continue; } moduleData.addHookData(HookData(static_cast(hook_entry->type), reinterpret_cast(hook_entry->target))); } - for (uint32_t j = 0; j < DYN_LINK_RELOCATION_LIST_LENGTH; j++) { - dyn_linking_relocation_entry_t *linking_entry = &(module_data->linking_entries[j]); - if (linking_entry->destination == NULL) { + for (auto & linking_entry : module_data->linking_entries) { + if (linking_entry.destination == nullptr) { break; } - dyn_linking_import_t *importEntry = linking_entry->importEntry; - if (importEntry == NULL) { + dyn_linking_import_t *importEntry = linking_entry.importEntry; + if (importEntry == nullptr) { DEBUG_FUNCTION_LINE("importEntry was NULL, skipping relocation entry\n"); continue; } - if (importEntry->importName == NULL) { + if (importEntry->importName == nullptr) { DEBUG_FUNCTION_LINE("importEntry->importName was NULL, skipping relocation entry\n"); continue; } - dyn_linking_function_t *functionEntry = linking_entry->functionEntry; + dyn_linking_function_t *functionEntry = linking_entry.functionEntry; - if (functionEntry == NULL) { + if (functionEntry == nullptr) { DEBUG_FUNCTION_LINE("functionEntry was NULL, skipping relocation entry\n"); continue; } - if (functionEntry->functionName == NULL) { + if (functionEntry->functionName == nullptr) { DEBUG_FUNCTION_LINE("functionEntry->functionName was NULL, skipping relocation entry\n"); continue; } ImportRPLInformation rplInfo(importEntry->importName, importEntry->isData); - RelocationData reloc(linking_entry->type, linking_entry->offset, linking_entry->addend, linking_entry->destination, functionEntry->functionName, rplInfo); + RelocationData reloc(linking_entry.type, linking_entry.offset, linking_entry.addend, linking_entry.destination, functionEntry->functionName, rplInfo); moduleData.addRelocationData(reloc); } diff --git a/source/module/ModuleData.h b/source/module/ModuleData.h index 2e419fa..5c36839 100644 --- a/source/module/ModuleData.h +++ b/source/module/ModuleData.h @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (C) 2018 Maschell + * Copyright (C) 2018-2021 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 @@ -27,11 +27,9 @@ class ModuleData { public: - ModuleData() { - } + ModuleData() = default; - ~ModuleData() { - } + ~ModuleData() = default; void setBSSLocation(uint32_t addr, uint32_t size) { this->bssAddr = addr; @@ -51,15 +49,15 @@ public: this->startAddress = addr; } - void setEndAddress(uint32_t endAddress) { - this->endAddress = endAddress; + void setEndAddress(uint32_t _endAddress) { + this->endAddress = _endAddress; } void addRelocationData(const RelocationData &relocation_data) { relocation_data_list.push_back(relocation_data); } - const std::vector &getRelocationDataList() const { + [[nodiscard]] const std::vector &getRelocationDataList() const { return relocation_data_list; } @@ -67,7 +65,7 @@ public: export_data_list.push_back(data); } - const std::vector &getExportDataList() const { + [[nodiscard]] const std::vector &getExportDataList() const { return export_data_list; } @@ -75,7 +73,7 @@ public: hook_data_list.push_back(data); } - const std::vector &getHookDataList() const { + [[nodiscard]] const std::vector &getHookDataList() const { return hook_data_list; } @@ -83,60 +81,60 @@ public: section_info_list[sectionInfo.getName()] = sectionInfo; } - const std::map &getSectionInfoList() const { + [[nodiscard]] const std::map &getSectionInfoList() const { return section_info_list; } - std::optional getSectionInfo(const std::string §ionName) const { + [[nodiscard]] std::optional getSectionInfo(const std::string §ionName) const { if (getSectionInfoList().count(sectionName) > 0) { return section_info_list.at(sectionName); } return std::nullopt; } - uint32_t getBSSAddr() const { + [[nodiscard]] uint32_t getBSSAddr() const { return bssAddr; } - uint32_t getBSSSize() const { + [[nodiscard]] uint32_t getBSSSize() const { return bssSize; } - uint32_t getSBSSAddr() const { + [[nodiscard]] uint32_t getSBSSAddr() const { return sbssAddr; } - uint32_t getSBSSSize() const { + [[nodiscard]] uint32_t getSBSSSize() const { return sbssSize; } - uint32_t getEntrypoint() const { + [[nodiscard]] uint32_t getEntrypoint() const { return entrypoint; } - uint32_t getStartAddress() const { + [[nodiscard]] uint32_t getStartAddress() const { return startAddress; } - uint32_t getEndAddress() const { + [[nodiscard]] uint32_t getEndAddress() const { return endAddress; } - std::string toString() const; + [[nodiscard]] std::string toString() const; void setExportName(const std::string &name) { this->export_name = name; } - std::string getExportName() const { + [[nodiscard]] std::string getExportName() const { return this->export_name; } - bool isSkipEntrypoint() const { + [[nodiscard]] bool isSkipEntrypoint() const { return this->skipEntrypoint; } - bool isInitBeforeRelocationDoneHook() const { + [[nodiscard]] bool isInitBeforeRelocationDoneHook() const { return this->initBeforeRelocationDoneHook; }