Add support for WUMS, support for handling and resolving exports

This commit is contained in:
Maschell
2020-05-17 21:14:27 +02:00
parent 2ee3011ae8
commit 51fc349237
12 changed files with 201 additions and 16 deletions

View File

@@ -0,0 +1,30 @@
#pragma once
#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->address = address;
}
const wums_entry_type_t getType() const {
return type;
}
const void *getAddress() const {
return address;
}
const std::string getName() const {
return name;
}
private:
wums_entry_type_t type;
std::string name;
const void *address;
};

View File

@@ -22,6 +22,7 @@
#include <map>
#include "RelocationData.h"
#include "SectionInfo.h"
#include "ExportData.h"
class ModuleData {
public:
@@ -61,6 +62,14 @@ public:
return relocation_data_list;
}
void addExportData(const ExportData &data) {
export_data_list.push_back(data);
}
const std::vector<ExportData> &getExportDataList() const {
return export_data_list;
}
void addSectionInfo(const SectionInfo &sectionInfo) {
section_info_list[sectionInfo.getName()] = sectionInfo;
}
@@ -106,10 +115,21 @@ public:
std::string toString() const;
void setExportName(const std::string &name) {
this->export_name = name;
}
std::string getExportName() const {
return this->export_name;
}
private:
std::vector<RelocationData> relocation_data_list;
std::vector<ExportData> export_data_list;
std::map<std::string, SectionInfo> section_info_list;
std::string export_name;
uint32_t bssAddr = 0;
uint32_t bssSize = 0;
uint32_t sbssAddr = 0;

View File

@@ -19,11 +19,13 @@
#include <vector>
#include <map>
#include <coreinit/cache.h>
#include <wums.h>
#include "ModuleDataFactory.h"
#include "elfio/elfio.hpp"
#include "utils/utils.h"
#include "ElfUtils.h"
#include "SectionInfo.h"
#include "ExportData.h"
using namespace ELFIO;
@@ -104,7 +106,6 @@ std::optional<ModuleData> ModuleDataFactory::load(std::string path, uint32_t des
moduleData.addSectionInfo(SectionInfo(psec->get_name(), destination, sectionSize));
DEBUG_FUNCTION_LINE("Saved %s section info. Location: %08X size: %08X", psec->get_name().c_str(), destination, sectionSize);
totalSize += sectionSize;
if (endAddress < destination + sectionSize) {
@@ -133,8 +134,55 @@ std::optional<ModuleData> ModuleDataFactory::load(std::string path, uint32_t des
moduleData.addRelocationData(reloc);
}
DCFlushRange((void *) destination_address, totalSize);
ICInvalidateRange((void *) destination_address, totalSize);
std::optional<SectionInfo> secInfo = moduleData.getSectionInfo(".wums.exports");
if (secInfo && secInfo->getSize() > 0) {
size_t entries_count = secInfo->getSize() / sizeof(wums_entry_t);
wums_entry_t *entries = (wums_entry_t *) secInfo->getAddress();
if (entries != NULL) {
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);
ExportData export_data(exp->type, exp->name, exp->address);
moduleData.addExportData(export_data);
}
}
}
secInfo = moduleData.getSectionInfo(".wums.meta");
if (secInfo && secInfo->getSize() > 0) {
wums_entry_t *entries = (wums_entry_t *) secInfo->getAddress();
if (entries != NULL) {
char *curEntry = (char *) secInfo->getAddress();
while ((uint32_t) curEntry < (uint32_t) secInfo->getAddress() + secInfo->getSize()) {
if (*curEntry == '\0') {
curEntry++;
continue;
}
auto firstFound = std::string(curEntry).find_first_of("=");
if (firstFound != std::string::npos) {
curEntry[firstFound] = '\0';
std::string key(curEntry);
std::string value(curEntry + firstFound + 1);
if (key.compare("export_name") == 0) {
DEBUG_FUNCTION_LINE("export_name = %s", value.c_str());
moduleData.setExportName(value);
}else if (key.compare("wums") == 0) {
if (value.compare("0.1") != 0) {
DEBUG_FUNCTION_LINE("Warning: Ignoring module - Unsupported WUMS version: %s.\n", value.c_str());
return std::nullopt;
}
}
}
curEntry += strlen(curEntry) + 1;
}
}
}
DCFlushRange((void*)destination_address, totalSize);
ICInvalidateRange((void*)destination_address, totalSize);
free(destinations);

View File

@@ -26,6 +26,27 @@ bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformati
}
}
std::vector<ExportData> exportData = module.getExportDataList();
for (auto const &curExport : exportData) {
bool found = false;
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 == NULL) {
export_entry->type = curExport.getType();
strncpy(export_entry->name, curExport.getName().c_str(), EXPORT_MAXIMUM_NAME_LENGTH);
export_entry->address = (uint32_t) curExport.getAddress();
found = true;
break;
}
}
if (!found) {
DEBUG_FUNCTION_LINE("Failed to found enough exports slots");
}
}
strncpy(module_data->module_export_name, module.getExportName().c_str(), MAXIMUM_EXPORT_MODULE_NAME_LENGTH);
module_data->bssAddr = module.getBSSAddr();
module_data->bssSize = module.getBSSSize();
module_data->sbssAddr = module.getSBSSAddr();
@@ -67,6 +88,14 @@ std::vector<ModuleData> ModuleDataPersistence::loadModuleData(module_information
moduleData.setStartAddress(module_data->startAddress);
moduleData.setEndAddress(module_data->endAddress);
for (uint32_t j = 0; j < EXPORT_ENTRY_LIST_LENGTH; i++) {
export_data_t *export_entry = &(module_data->export_entries[j]);
if (export_entry->address == NULL) {
continue;
}
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 < DYN_LINK_RELOCATION_LIST_LENGTH; j++) {
dyn_linking_relocation_entry_t *linking_entry = &(module_data->linking_entries[j]);
if (linking_entry->destination == NULL) {