Format the code via clang-format

This commit is contained in:
Maschell
2022-02-04 21:44:03 +01:00
parent 66e5d5b9f3
commit 00dec53199
61 changed files with 528 additions and 427 deletions

View File

@@ -1,9 +1,9 @@
#include "DynamicLinkingHelper.h"
#include "utils/logger.h"
#include <coreinit/dynload.h>
#include <cstdio>
#include <cstring>
#include <vector>
#include <coreinit/dynload.h>
#include "utils/logger.h"
dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_linking_relocation_data_t *data, const char *functionName) {
if (data == nullptr) {
@@ -13,7 +13,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) {
@@ -45,7 +45,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) {
@@ -54,7 +54,7 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocatio
}
strncpy(curEntry->importName, importName, DYN_LINK_IMPORT_NAME_LENGTH);
curEntry->isData = isData;
result = curEntry;
result = curEntry;
break;
}
if (strncmp(curEntry->importName, importName, DYN_LINK_IMPORT_NAME_LENGTH) == 0 && (curEntry->isData == isData)) {
@@ -98,12 +98,12 @@ bool DynamicLinkingHelper::addRelocationEntry(dyn_linking_relocation_entry_t *li
if (curEntry->functionEntry != nullptr) {
continue;
}
curEntry->type = type;
curEntry->offset = offset;
curEntry->addend = addend;
curEntry->destination = destination;
curEntry->type = type;
curEntry->offset = offset;
curEntry->addend = addend;
curEntry->destination = destination;
curEntry->functionEntry = functionName;
curEntry->importEntry = importInfo;
curEntry->importEntry = importInfo;
return true;
}

View File

@@ -1,10 +1,10 @@
#pragma once
#include <wums.h>
#include "RelocationData.h"
#include "utils/logger.h"
#include <string>
#include <vector>
#include "RelocationData.h"
#include <wums.h>
class DynamicLinkingHelper {
public:

View File

@@ -1,13 +1,14 @@
#pragma once
#pragma once
#include <string>
#include <wums.h>
class ExportData {
public:
ExportData(wums_entry_type_t type, const std::string &name, const void *address) {
this->type = type;
this->name = name;
this->type = type;
this->name = name;
this->address = address;
}

View File

@@ -24,16 +24,15 @@ class FunctionSymbolData {
public:
FunctionSymbolData(const FunctionSymbolData &o2) = default;
FunctionSymbolData(const char *name, void *address, uint32_t size) :
name(name),
address(address),
size(size) {
FunctionSymbolData(const char *name, void *address, uint32_t size) : name(name),
address(address),
size(size) {
}
virtual ~FunctionSymbolData() = default;
bool operator<(const FunctionSymbolData &rhs) const {
return (uint32_t) address < (uint32_t) rhs.address; //assume that you compare the record based on a
return (uint32_t) address < (uint32_t) rhs.address; //assume that you compare the record based on a
}
[[nodiscard]] const char *getName() const {

View File

@@ -5,7 +5,7 @@
class HookData {
public:
HookData(wums_hook_type_t type, const void *target) {
this->type = type;
this->type = type;
this->target = target;
}

View File

@@ -17,16 +17,17 @@
#pragma once
#include <string>
#include <optional>
#include <utility>
#include "utils/logger.h"
#include <memory>
#include <optional>
#include <string>
#include <utility>
class ImportRPLInformation {
public:
explicit ImportRPLInformation(std::string name, bool isData = false) {
this->name = std::move(name);
this->name = std::move(name);
this->_isData = isData;
}
@@ -46,7 +47,7 @@ public:
rplName = rawSectionName.substr(fimport.size());
} else if (std::equal(dimport.begin(), dimport.end(), rawSectionName.begin())) {
rplName = rawSectionName.substr(dimport.size());
data = true;
data = true;
} else {
DEBUG_FUNCTION_LINE("invalid section name\n");
return std::nullopt;

View File

@@ -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;

View File

@@ -17,15 +17,15 @@
#pragma once
#include <string>
#include <vector>
#include <map>
#include <set>
#include "ExportData.h"
#include "FunctionSymbolData.h"
#include "HookData.h"
#include "RelocationData.h"
#include "SectionInfo.h"
#include "ExportData.h"
#include "HookData.h"
#include "FunctionSymbolData.h"
#include <map>
#include <set>
#include <string>
#include <vector>
struct FunctionSymbolDataComparator {
bool operator()(const std::shared_ptr<FunctionSymbolData> &lhs,
@@ -164,6 +164,7 @@ public:
}
bool relocationsDone = false;
private:
std::vector<std::shared_ptr<RelocationData>> relocation_data_list;
std::vector<std::shared_ptr<ExportData>> export_data_list;
@@ -173,13 +174,13 @@ private:
std::string export_name;
uint32_t bssAddr = 0;
uint32_t bssSize = 0;
uint32_t sbssAddr = 0;
uint32_t sbssSize = 0;
uint32_t startAddress = 0;
uint32_t endAddress = 0;
uint32_t entrypoint = 0;
uint32_t bssAddr = 0;
uint32_t bssSize = 0;
uint32_t sbssAddr = 0;
uint32_t sbssSize = 0;
uint32_t startAddress = 0;
uint32_t endAddress = 0;
uint32_t entrypoint = 0;
bool initBeforeRelocationDoneHook = false;
bool skipInitFini = false;
bool skipInitFini = false;
};

View File

@@ -15,15 +15,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include <string>
#include <vector>
#include <map>
#include <coreinit/cache.h>
#include <wums.h>
#include "ModuleDataFactory.h"
#include "utils/utils.h"
#include "ElfUtils.h"
#include "FunctionSymbolData.h"
#include "utils/utils.h"
#include <coreinit/cache.h>
#include <map>
#include <string>
#include <vector>
#include <wums.h>
using namespace ELFIO;
@@ -49,7 +49,7 @@ ModuleDataFactory::load(const std::string &path, uint32_t *destination_address_p
uint32_t entrypoint = offset_text + (uint32_t) reader.get_entry() - 0x02000000;
uint32_t totalSize = 0;
uint32_t totalSize = 0;
uint32_t endAddress = 0;
for (uint32_t i = 0; i < sec_num; ++i) {
@@ -133,18 +133,18 @@ ModuleDataFactory::load(const std::string &path, uint32_t *destination_address_p
}
auto relocationData = getImportRelocationData(reader, destinations);
for (auto const &reloc: relocationData) {
for (auto const &reloc : relocationData) {
moduleData->addRelocationData(reloc);
}
auto secInfo = moduleData->getSectionInfo(".wums.exports");
if (secInfo && secInfo.value()->getSize() > 0) {
size_t entries_count = secInfo.value()->getSize() / sizeof(wums_entry_t);
auto *entries = (wums_entry_t *) secInfo.value()->getAddress();
auto *entries = (wums_entry_t *) secInfo.value()->getAddress();
if (entries != nullptr) {
for (size_t j = 0; j < entries_count; j++) {
wums_entry_t *exp = &entries[j];
DEBUG_FUNCTION_LINE("Saving export of type %08X, name %s, target: %08X"/*,pluginData.getPluginInformation()->getName().c_str()*/, exp->type, exp->name, (void *) exp->address);
DEBUG_FUNCTION_LINE("Saving export of type %08X, name %s, target: %08X" /*,pluginData.getPluginInformation()->getName().c_str()*/, exp->type, exp->name, (void *) exp->address);
auto exportData = std::make_shared<ExportData>(exp->type, exp->name, exp->address);
moduleData->addExportData(exportData);
}
@@ -154,11 +154,11 @@ ModuleDataFactory::load(const std::string &path, uint32_t *destination_address_p
secInfo = moduleData->getSectionInfo(".wums.hooks");
if (secInfo && secInfo.value()->getSize() > 0) {
size_t entries_count = secInfo.value()->getSize() / sizeof(wums_hook_t);
auto *hooks = (wums_hook_t *) secInfo.value()->getAddress();
auto *hooks = (wums_hook_t *) secInfo.value()->getAddress();
if (hooks != nullptr) {
for (size_t j = 0; j < entries_count; j++) {
wums_hook_t *hook = &hooks[j];
DEBUG_FUNCTION_LINE("Saving hook of type %08X, target: %08X"/*,pluginData.getPluginInformation()->getName().c_str()*/, hook->type, hook->target);
DEBUG_FUNCTION_LINE("Saving hook of type %08X, target: %08X" /*,pluginData.getPluginInformation()->getName().c_str()*/, hook->type, hook->target);
auto hookData = std::make_shared<HookData>(hook->type, hook->target);
moduleData->addHookData(hookData);
}
@@ -212,7 +212,7 @@ ModuleDataFactory::load(const std::string &path, uint32_t *destination_address_p
}
}
char *strTable = (char *) endAddress;
char *strTable = (char *) endAddress;
uint32_t strOffset = 0;
// Get the symbol for functions.
@@ -225,16 +225,16 @@ ModuleDataFactory::load(const std::string &path, uint32_t *destination_address_p
if (sym_no > 0) {
for (Elf_Half j = 0; j < sym_no; ++j) {
std::string name;
Elf64_Addr value = 0;
Elf_Xword size = 0;
unsigned char bind = 0;
unsigned char type = 0;
Elf_Half section = 0;
Elf64_Addr value = 0;
Elf_Xword size = 0;
unsigned char bind = 0;
unsigned char type = 0;
Elf_Half section = 0;
unsigned char other = 0;
if (symbols.get_symbol(j, name, value, size, bind, type, section, other)) {
if (type == STT_FUNC) { // We only care about functions.
auto sectionVal = reader.sections[section];
auto offsetVal = value - sectionVal->get_address();
auto offsetVal = value - sectionVal->get_address();
auto sectionOpt = moduleData->getSectionInfo(sectionVal->get_name());
if (!sectionOpt.has_value()) {
continue;

View File

@@ -17,12 +17,12 @@
#pragma once
#include <string>
#include <vector>
#include <map>
#include <wums.h>
#include "ModuleData.h"
#include "elfio/elfio.hpp"
#include <map>
#include <string>
#include <vector>
#include <wums.h>
class ModuleDataFactory {
public:

View File

@@ -1,6 +1,6 @@
#include <coreinit/cache.h>
#include "ModuleDataPersistence.h"
#include "DynamicLinkingHelper.h"
#include <coreinit/cache.h>
bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformation, const std::shared_ptr<ModuleData> &module) {
int32_t module_count = moduleInformation->number_used_modules;
@@ -15,7 +15,7 @@ bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformati
DEBUG_FUNCTION_LINE("Saving relocation data for module at %08X", module->getEntrypoint());
// Relocation
auto 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");
@@ -24,15 +24,15 @@ bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformati
}
auto 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.type = curExport->getType();
export_entry.name[0] = '\0';
strncat(export_entry.name, curExport->getName().c_str(), sizeof(export_entry.name) - 1);
export_entry.address = (uint32_t) curExport->getAddress();
found = true;
found = true;
break;
}
}
@@ -43,13 +43,13 @@ bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformati
}
auto 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.type = curHook->getType();
hook_entry.target = (uint32_t) curHook->getTarget();
found = true;
found = true;
break;
}
}
@@ -63,36 +63,36 @@ bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformati
uint32_t entryCount = module->getFunctionSymbolDataList().size();
if (entryCount > 0) {
auto ptr = &moduleInformation->function_symbols[moduleInformation->number_used_function_symbols];
auto ptr = &moduleInformation->function_symbols[moduleInformation->number_used_function_symbols];
module_data->function_symbol_entries = ptr;
uint32_t sym_offset = 0;
for (auto &curFuncSym: module->getFunctionSymbolDataList()) {
for (auto &curFuncSym : module->getFunctionSymbolDataList()) {
if (moduleInformation->number_used_function_symbols >= FUNCTION_SYMBOL_LIST_LENGTH) {
DEBUG_FUNCTION_LINE("Function symbol list is full");
break;
}
module_data->function_symbol_entries[sym_offset].address = curFuncSym->getAddress();
module_data->function_symbol_entries[sym_offset].name = (char *) curFuncSym->getName();
module_data->function_symbol_entries[sym_offset].size = curFuncSym->getSize();
module_data->function_symbol_entries[sym_offset].name = (char *) curFuncSym->getName();
module_data->function_symbol_entries[sym_offset].size = curFuncSym->getSize();
sym_offset++;
moduleInformation->number_used_function_symbols++;
}
module_data->number_used_function_symbols = sym_offset;
} else {
module_data->function_symbol_entries = nullptr;
module_data->function_symbol_entries = nullptr;
module_data->number_used_function_symbols = 0;
}
module_data->bssAddr = module->getBSSAddr();
module_data->bssSize = module->getBSSSize();
module_data->sbssAddr = module->getSBSSAddr();
module_data->sbssSize = module->getSBSSSize();
module_data->startAddress = module->getStartAddress();
module_data->endAddress = module->getEndAddress();
module_data->entrypoint = module->getEntrypoint();
module_data->skipInitFini = module->isSkipInitFini();
module_data->bssAddr = module->getBSSAddr();
module_data->bssSize = module->getBSSSize();
module_data->sbssAddr = module->getSBSSAddr();
module_data->sbssSize = module->getSBSSSize();
module_data->startAddress = module->getStartAddress();
module_data->endAddress = module->getEndAddress();
module_data->entrypoint = module->getEntrypoint();
module_data->skipInitFini = module->isSkipInitFini();
module_data->initBeforeRelocationDoneHook = module->isInitBeforeRelocationDoneHook();
moduleInformation->number_used_modules++;
@@ -120,7 +120,7 @@ std::vector<std::shared_ptr<ModuleData>> ModuleDataPersistence::loadModuleData(m
for (int32_t i = 0; i < module_count; i++) {
// Copy data from struct.
module_information_single_t *module_data = &(moduleInformation->module_data[i]);
auto moduleData = std::make_shared<ModuleData>();
auto moduleData = std::make_shared<ModuleData>();
moduleData->setBSSLocation(module_data->bssAddr, module_data->bssSize);
moduleData->setSBSSLocation(module_data->sbssAddr, module_data->sbssSize);
moduleData->setEntrypoint(module_data->entrypoint);
@@ -130,7 +130,7 @@ std::vector<std::shared_ptr<ModuleData>> ModuleDataPersistence::loadModuleData(m
moduleData->setSkipInitFini(module_data->skipInitFini);
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;
@@ -139,7 +139,7 @@ std::vector<std::shared_ptr<ModuleData>> ModuleDataPersistence::loadModuleData(m
moduleData->addExportData(exportData);
}
for (auto &hook_entry: module_data->hook_entries) {
for (auto &hook_entry : module_data->hook_entries) {
if (hook_entry.target == 0) {
continue;
}
@@ -147,7 +147,7 @@ std::vector<std::shared_ptr<ModuleData>> ModuleDataPersistence::loadModuleData(m
moduleData->addHookData(hookData);
}
for (auto &linking_entry: module_data->linking_entries) {
for (auto &linking_entry : module_data->linking_entries) {
if (linking_entry.destination == nullptr) {
break;
}
@@ -163,14 +163,14 @@ std::vector<std::shared_ptr<ModuleData>> ModuleDataPersistence::loadModuleData(m
continue;
}
auto rplInfo = std::make_shared<ImportRPLInformation>(importEntry->importName, importEntry->isData);
auto reloc = std::make_shared<RelocationData>(linking_entry.type, linking_entry.offset, linking_entry.addend, linking_entry.destination, functionEntry->functionName, rplInfo);
auto reloc = std::make_shared<RelocationData>(linking_entry.type, linking_entry.offset, linking_entry.addend, linking_entry.destination, functionEntry->functionName, rplInfo);
moduleData->addRelocationData(reloc);
}
if (module_data->function_symbol_entries != nullptr && module_data->number_used_function_symbols > 0) {
for (uint32_t j = 0; j < module_data->number_used_function_symbols; j++) {
auto symbol = &module_data->function_symbol_entries[j];
auto symbol = &module_data->function_symbol_entries[j];
auto functionSymbolData = std::make_shared<FunctionSymbolData>(symbol->name, symbol->address, symbol->size);
moduleData->addFunctionSymbolData(functionSymbolData);
}

View File

@@ -1,7 +1,7 @@
#pragma once
#include <wums.h>
#include "ModuleData.h"
#include <wums.h>
class ModuleDataPersistence {
public:

View File

@@ -17,20 +17,20 @@
#pragma once
#include <string>
#include <memory>
#include <utility>
#include "ImportRPLInformation.h"
#include <memory>
#include <string>
#include <utility>
class RelocationData {
public:
RelocationData(char type, size_t offset, int32_t addend, void *destination, std::string name, std::shared_ptr<ImportRPLInformation> rplInfo) : rplInfo(std::move(rplInfo)) {
this->type = type;
this->offset = offset;
this->addend = addend;
this->type = type;
this->offset = offset;
this->addend = addend;
this->destination = destination;
this->name = std::move(name);
this->name = std::move(name);
}
~RelocationData() = default;

View File

@@ -23,18 +23,16 @@
class SectionInfo {
public:
SectionInfo(std::string name, uint32_t address, uint32_t sectionSize) :
name(std::move(name)),
address(address),
sectionSize(sectionSize) {
SectionInfo(std::string name, uint32_t address, uint32_t sectionSize) : name(std::move(name)),
address(address),
sectionSize(sectionSize) {
}
SectionInfo() = default;
SectionInfo(const SectionInfo &o2) :
name(o2.name),
address(o2.address),
sectionSize(o2.sectionSize) {
SectionInfo(const SectionInfo &o2) : name(o2.name),
address(o2.address),
sectionSize(o2.sectionSize) {
}
SectionInfo &operator=(const SectionInfo &other) = default;