Code cleanup

This commit is contained in:
Maschell 2021-02-19 17:01:21 +01:00
parent 07adc02d53
commit 4eff524ab3
2 changed files with 36 additions and 42 deletions

View File

@ -1,13 +1,11 @@
#include "ModuleDataPersistence.h"
#include "DynamicLinkingHelper.h"
#include "../../source/module/ModuleData.h"
#include "../../source/module/RelocationData.h"
#include <coreinit/cache.h>
#include <wums.h>
std::vector<ModuleData> ModuleDataPersistence::loadModuleData(module_information_t *moduleInformation) {
std::vector<ModuleData> result;
if (moduleInformation == NULL) {
if (moduleInformation == nullptr) {
DEBUG_FUNCTION_LINE("moduleInformation == NULL\n");
return result;
}
@ -37,48 +35,46 @@ std::vector<ModuleData> 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<wums_entry_type_t>(export_entry->type), export_entry->name, reinterpret_cast<const void *>(export_entry->address)));
moduleData.addExportData(ExportData(static_cast<wums_entry_type_t>(export_entry.type), export_entry.name, reinterpret_cast<const void *>(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<wums_hook_type_t>(hook_entry->type), reinterpret_cast<const void *>(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);
}

View File

@ -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<RelocationData> &getRelocationDataList() const {
[[nodiscard]] const std::vector<RelocationData> &getRelocationDataList() const {
return relocation_data_list;
}
@ -67,7 +65,7 @@ public:
export_data_list.push_back(data);
}
const std::vector<ExportData> &getExportDataList() const {
[[nodiscard]] const std::vector<ExportData> &getExportDataList() const {
return export_data_list;
}
@ -75,7 +73,7 @@ public:
hook_data_list.push_back(data);
}
const std::vector<HookData> &getHookDataList() const {
[[nodiscard]] const std::vector<HookData> &getHookDataList() const {
return hook_data_list;
}
@ -83,60 +81,60 @@ public:
section_info_list[sectionInfo.getName()] = sectionInfo;
}
const std::map<std::string, SectionInfo> &getSectionInfoList() const {
[[nodiscard]] const std::map<std::string, SectionInfo> &getSectionInfoList() const {
return section_info_list;
}
std::optional<SectionInfo> getSectionInfo(const std::string &sectionName) const {
[[nodiscard]] std::optional<SectionInfo> getSectionInfo(const std::string &sectionName) 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;
}