mirror of
https://github.com/wiiu-env/WiiUPluginLoaderBackend.git
synced 2026-08-12 04:36:15 -05:00
Formatting and cleanup
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
#include "DynamicLinkingHelper.h"
|
||||
#include <cstring>
|
||||
#include "../utils/logger.h"
|
||||
|
||||
dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_linking_relocation_data_t *data, const char *functionName) {
|
||||
if (data == nullptr) {
|
||||
@@ -10,19 +9,18 @@ dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_li
|
||||
return nullptr;
|
||||
}
|
||||
dyn_linking_function_t *result = nullptr;
|
||||
for (int32_t i = 0; i < DYN_LINK_FUNCTION_LIST_LENGTH; i++) {
|
||||
dyn_linking_function_t *curEntry = &(data->functions[i]);
|
||||
if (strlen(curEntry->functionName) == 0) {
|
||||
for (auto & curEntry : data->functions) {
|
||||
if (strlen(curEntry.functionName) == 0) {
|
||||
if (strlen(functionName) > DYN_LINK_FUNCTION_NAME_LENGTH) {
|
||||
DEBUG_FUNCTION_LINE("Failed to add function name, it's too long.");
|
||||
return nullptr;
|
||||
}
|
||||
strncpy(curEntry->functionName, functionName, DYN_LINK_FUNCTION_NAME_LENGTH);
|
||||
result = curEntry;
|
||||
strncpy(curEntry.functionName, functionName, DYN_LINK_FUNCTION_NAME_LENGTH);
|
||||
result = &curEntry;
|
||||
break;
|
||||
}
|
||||
if (strncmp(curEntry->functionName, functionName, DYN_LINK_FUNCTION_NAME_LENGTH) == 0) {
|
||||
result = curEntry;
|
||||
if (strncmp(curEntry.functionName, functionName, DYN_LINK_FUNCTION_NAME_LENGTH) == 0) {
|
||||
result = &curEntry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -42,31 +40,33 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocatio
|
||||
return nullptr;
|
||||
}
|
||||
dyn_linking_import_t *result = nullptr;
|
||||
for (int32_t i = 0; i < DYN_LINK_IMPORT_LIST_LENGTH; i++) {
|
||||
dyn_linking_import_t *curEntry = &(data->imports[i]);
|
||||
if (strlen(curEntry->importName) == 0) {
|
||||
for (auto & curEntry : data->imports) {
|
||||
if (strlen(curEntry.importName) == 0) {
|
||||
if (strlen(importName) > DYN_LINK_IMPORT_NAME_LENGTH) {
|
||||
DEBUG_FUNCTION_LINE("Failed to add Import, it's too long.");
|
||||
return nullptr;
|
||||
}
|
||||
strncpy(curEntry->importName, importName, DYN_LINK_IMPORT_NAME_LENGTH);
|
||||
curEntry->isData = isData;
|
||||
result = curEntry;
|
||||
strncpy(curEntry.importName, importName, DYN_LINK_IMPORT_NAME_LENGTH);
|
||||
curEntry.isData = isData;
|
||||
result = &curEntry;
|
||||
break;
|
||||
}
|
||||
if (strncmp(curEntry->importName, importName, DYN_LINK_IMPORT_NAME_LENGTH) == 0 && (curEntry->isData == isData)) {
|
||||
return curEntry;
|
||||
if (strncmp(curEntry.importName, importName, DYN_LINK_IMPORT_NAME_LENGTH) == 0 && (curEntry.isData == isData)) {
|
||||
return &curEntry;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, const RelocationData &relocationData) {
|
||||
return addReloationEntry(linking_data, linking_entries, linking_entry_length, relocationData.getType(), relocationData.getOffset(), relocationData.getAddend(), relocationData.getDestination(), relocationData.getName(),
|
||||
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length,
|
||||
const RelocationData &relocationData) {
|
||||
return addReloationEntry(linking_data, linking_entries, linking_entry_length, relocationData.getType(), relocationData.getOffset(), relocationData.getAddend(), relocationData.getDestination(),
|
||||
relocationData.getName(),
|
||||
relocationData.getImportRPLInformation());
|
||||
}
|
||||
|
||||
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination,
|
||||
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset,
|
||||
int32_t addend, const void *destination,
|
||||
const std::string &name, const ImportRPLInformation &rplInfo) {
|
||||
dyn_linking_import_t *importInfoGbl = DynamicLinkingHelper::getOrAddImport(linking_data, rplInfo.getName().c_str(), rplInfo.isData());
|
||||
if (importInfoGbl == nullptr) {
|
||||
@@ -83,7 +83,8 @@ bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *link
|
||||
return addReloationEntry(linking_entries, linking_entry_length, type, offset, addend, destination, functionInfo, importInfoGbl);
|
||||
}
|
||||
|
||||
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination, dyn_linking_function_t *functionName,
|
||||
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination,
|
||||
dyn_linking_function_t *functionName,
|
||||
dyn_linking_import_t *importInfo) {
|
||||
for (uint32_t i = 0; i < linking_entry_length; i++) {
|
||||
dyn_linking_relocation_entry_t *curEntry = &(linking_entries[i]);
|
||||
|
||||
@@ -49,10 +49,12 @@ public:
|
||||
static bool addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, const RelocationData &relocationData);
|
||||
|
||||
static bool
|
||||
addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination, const std::string &name,
|
||||
addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend,
|
||||
const void *destination, const std::string &name,
|
||||
const ImportRPLInformation &rplInfo);
|
||||
|
||||
static bool addReloationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination, dyn_linking_function_t *functionName,
|
||||
static bool addReloationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination,
|
||||
dyn_linking_function_t *functionName,
|
||||
dyn_linking_import_t *importInfo);
|
||||
|
||||
private:
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
class FunctionData {
|
||||
|
||||
public:
|
||||
FunctionData(void *paddress, void *vaddress, const std::string &name, function_replacement_library_type_t library, void *replaceAddr, void *replaceCall, FunctionPatcherTargetProcess targetProcess) {
|
||||
FunctionData(void *paddress, void *vaddress, const std::string &name, function_replacement_library_type_t library, void *replaceAddr, void *replaceCall,
|
||||
FunctionPatcherTargetProcess targetProcess) {
|
||||
this->paddress = paddress;
|
||||
this->vaddress = vaddress;
|
||||
this->name = name;
|
||||
|
||||
@@ -6,9 +6,6 @@
|
||||
#include "PluginContainerPersistence.h"
|
||||
#include "PluginDataPersistence.h"
|
||||
#include "DynamicLinkingHelper.h"
|
||||
#include "../common/plugin_defines.h"
|
||||
#include "PluginInformation.h"
|
||||
#include "RelocationData.h"
|
||||
|
||||
bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformation, PluginContainer &plugin) {
|
||||
int32_t plugin_count = pluginInformation->number_used_plugins;
|
||||
@@ -69,7 +66,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
|
||||
|
||||
// Relocation
|
||||
std::vector<RelocationData> relocationData = pluginInfo.getRelocationDataList();
|
||||
for (auto &reloc : relocationData) {
|
||||
for (auto &reloc: relocationData) {
|
||||
if (!DynamicLinkingHelper::addReloationEntry(&(pluginInformation->linking_data), plugin_data->info.linking_entries, PLUGIN_DYN_LINK_RELOCATION_LIST_LENGTH, reloc)) {
|
||||
DEBUG_FUNCTION_LINE("Failed to add a relocation entry");
|
||||
return false;
|
||||
@@ -95,7 +92,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
|
||||
|
||||
/* Store function replacement information */
|
||||
uint32_t i = 0;
|
||||
for (auto &curFunction : pluginInfo.getFunctionDataList()) {
|
||||
for (auto &curFunction: pluginInfo.getFunctionDataList()) {
|
||||
function_replacement_data_t *function_data = &plugin_data->info.functions[i];
|
||||
if (strlen(curFunction.getName().c_str()) > MAXIMUM_FUNCTION_NAME_LENGTH - 1) {
|
||||
DEBUG_FUNCTION_LINE("Could not add function \"%s\" for plugin \"%s\" function name is too long.", curFunction.getName().c_str(), pluginName.c_str());
|
||||
@@ -119,7 +116,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
|
||||
}
|
||||
|
||||
i = 0;
|
||||
for (auto &curHook : pluginInfo.getHookDataList()) {
|
||||
for (auto &curHook: pluginInfo.getHookDataList()) {
|
||||
replacement_data_hook_t *hook_data = &plugin_data->info.hooks[i];
|
||||
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Set hook for plugin \"%s\" of type %08X to target %08X", plugin_data->meta.name, curHook.getType(), (void *) curHook.getFunctionPointer());
|
||||
@@ -132,20 +129,20 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
|
||||
}
|
||||
|
||||
/* Saving SectionInfos */
|
||||
for (auto &curSection : pluginInfo.getSectionInfoList()) {
|
||||
for (auto &curSection: pluginInfo.getSectionInfoList()) {
|
||||
bool foundFreeSlot = false;
|
||||
uint32_t slot = 0;
|
||||
for (uint32_t i = 0; i < MAXIMUM_PLUGIN_SECTION_LENGTH; i++) {
|
||||
plugin_section_info_t *sectionInfo = &(plugin_data->info.sectionInfos[i]);
|
||||
for (uint32_t j = 0; j < MAXIMUM_PLUGIN_SECTION_LENGTH; j++) {
|
||||
plugin_section_info_t *sectionInfo = &(plugin_data->info.sectionInfos[j]);
|
||||
if (sectionInfo->addr == 0 && sectionInfo->size == 0) {
|
||||
foundFreeSlot = true;
|
||||
slot = i;
|
||||
slot = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (foundFreeSlot) {
|
||||
plugin_section_info_t *sectionInfo = &(plugin_data->info.sectionInfos[slot]);
|
||||
if (strlen(curSection.first.c_str()) > MAXIMUM_PLUGIN_SECTION_NAME_LENGTH - 1) {
|
||||
if (curSection.first.length() > MAXIMUM_PLUGIN_SECTION_NAME_LENGTH - 1) {
|
||||
DEBUG_FUNCTION_LINE("Could not add section info \"%s\" for plugin \"%s\" section name is too long.", curSection.first.c_str(), pluginName.c_str());
|
||||
break;
|
||||
}
|
||||
@@ -180,7 +177,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
|
||||
std::vector<PluginContainer> PluginContainerPersistence::loadPlugins(plugin_information_t *pluginInformation) {
|
||||
std::vector<PluginContainer> result;
|
||||
if (pluginInformation == nullptr) {
|
||||
DEBUG_FUNCTION_LINE("pluginInformation == NULL");
|
||||
DEBUG_FUNCTION_LINE("pluginInformation == nullptr");
|
||||
return result;
|
||||
}
|
||||
DCFlushRange((void *) pluginInformation, sizeof(plugin_information_t));
|
||||
@@ -216,7 +213,7 @@ std::vector<PluginContainer> PluginContainerPersistence::loadPlugins(plugin_info
|
||||
curPluginInformation.allocatedTextMemoryAddress = plugin_data->info.allocatedTextMemoryAddress;
|
||||
curPluginInformation.allocatedDataMemoryAddress = plugin_data->info.allocatedDataMemoryAddress;
|
||||
|
||||
for (auto & curItem : plugin_data->info.sectionInfos) {
|
||||
for (auto &curItem: plugin_data->info.sectionInfos) {
|
||||
plugin_section_info_t *sectionInfo = &curItem;
|
||||
if (sectionInfo->addr == 0 && sectionInfo->size == 0) {
|
||||
continue;
|
||||
@@ -250,38 +247,30 @@ std::vector<PluginContainer> PluginContainerPersistence::loadPlugins(plugin_info
|
||||
|
||||
for (uint32_t j = 0; j < functionReplaceCount; j++) {
|
||||
function_replacement_data_t *entry = &(plugin_data->info.functions[j]);
|
||||
FunctionData func((void *) entry->physicalAddr, (void *) entry->virtualAddr, entry->function_name, (function_replacement_library_type_t) entry->library, (void *) entry->replaceAddr, (void *) entry->replaceCall, entry->targetProcess);
|
||||
FunctionData func((void *) entry->physicalAddr, (void *) entry->virtualAddr, entry->function_name, (function_replacement_library_type_t) entry->library, (void *) entry->replaceAddr,
|
||||
(void *) entry->replaceCall, entry->targetProcess);
|
||||
curPluginInformation.addFunctionData(func);
|
||||
}
|
||||
|
||||
/* load relocation data */
|
||||
for (auto & linking_entrie : plugin_data->info.linking_entries) {
|
||||
dyn_linking_relocation_entry_t *linking_entry = &linking_entrie;
|
||||
if (linking_entry->destination == nullptr) {
|
||||
for (auto &linking_entry: plugin_data->info.linking_entries) {
|
||||
if (linking_entry.destination == nullptr) {
|
||||
break;
|
||||
}
|
||||
dyn_linking_import_t *importEntry = linking_entry->importEntry;
|
||||
dyn_linking_import_t *importEntry = linking_entry.importEntry;
|
||||
if (importEntry == nullptr) {
|
||||
DEBUG_FUNCTION_LINE("importEntry was NULL, skipping relocation entry");
|
||||
DEBUG_FUNCTION_LINE("importEntry was nullptr, skipping relocation entry");
|
||||
continue;
|
||||
}
|
||||
if (importEntry->importName == nullptr) {
|
||||
DEBUG_FUNCTION_LINE("importEntry->importName was NULL, skipping relocation entry");
|
||||
continue;
|
||||
}
|
||||
dyn_linking_function_t *functionEntry = linking_entry->functionEntry;
|
||||
dyn_linking_function_t *functionEntry = linking_entry.functionEntry;
|
||||
|
||||
if (functionEntry == nullptr) {
|
||||
DEBUG_FUNCTION_LINE("functionEntry was NULL, skipping relocation entry");
|
||||
continue;
|
||||
}
|
||||
if (functionEntry->functionName == nullptr) {
|
||||
DEBUG_FUNCTION_LINE("functionEntry->functionName was NULL, skipping relocation entry");
|
||||
DEBUG_FUNCTION_LINE("functionEntry was nullptr, skipping relocation entry");
|
||||
continue;
|
||||
}
|
||||
ImportRPLInformation rplInfo(importEntry->importName, importEntry->isData);
|
||||
std::string functionName(functionEntry->functionName);
|
||||
RelocationData reloc(linking_entry->type, linking_entry->offset, linking_entry->addend, linking_entry->destination, functionName, rplInfo);
|
||||
RelocationData reloc(linking_entry.type, linking_entry.offset, linking_entry.addend, linking_entry.destination, functionName, rplInfo);
|
||||
curPluginInformation.addRelocationData(reloc);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,10 +31,10 @@ void PluginData::freeMemory() {
|
||||
}
|
||||
}
|
||||
|
||||
PluginData::PluginData(const std::vector<uint8_t>& buffer) : PluginData(buffer, nullptr, eMemTypeMEM2) {
|
||||
PluginData::PluginData(const std::vector<uint8_t> &buffer) : PluginData(buffer, nullptr, eMemTypeMEM2) {
|
||||
}
|
||||
|
||||
PluginData::PluginData(const std::vector<uint8_t>& input, MEMHeapHandle heapHandle, eMemoryTypes memoryType) :
|
||||
PluginData::PluginData(const std::vector<uint8_t> &input, MEMHeapHandle heapHandle, eMemoryTypes memoryType) :
|
||||
heapHandle(heapHandle),
|
||||
memoryType(memoryType),
|
||||
length(input.size()) {
|
||||
|
||||
@@ -33,7 +33,7 @@ enum eMemoryTypes {
|
||||
|
||||
class PluginData {
|
||||
public:
|
||||
~PluginData()= default;
|
||||
~PluginData() = default;
|
||||
|
||||
void freeMemory();
|
||||
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
private:
|
||||
explicit PluginData(const std::vector<uint8_t> &buffer);
|
||||
|
||||
PluginData(const std::vector<uint8_t>& input, MEMHeapHandle heapHandle, eMemoryTypes memoryType);
|
||||
PluginData(const std::vector<uint8_t> &input, MEMHeapHandle heapHandle, eMemoryTypes memoryType);
|
||||
|
||||
friend class PluginDataFactory;
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#include "PluginInformation.h"
|
||||
|
||||
PluginInformation::PluginInformation(const PluginInformation &other) {
|
||||
for (const auto &i : other.hook_data_list) {
|
||||
for (const auto &i: other.hook_data_list) {
|
||||
hook_data_list.push_back(i);
|
||||
}
|
||||
for (const auto &i : other.function_data_list) {
|
||||
for (const auto &i: other.function_data_list) {
|
||||
function_data_list.push_back(i);
|
||||
}
|
||||
for (const auto &i : other.relocation_data_list) {
|
||||
for (const auto &i: other.relocation_data_list) {
|
||||
relocation_data_list.push_back(i);
|
||||
}
|
||||
section_info_list = other.section_info_list;
|
||||
|
||||
@@ -21,21 +21,17 @@
|
||||
#include <coreinit/cache.h>
|
||||
#include <coreinit/memexpheap.h>
|
||||
#include <wups.h>
|
||||
#include <whb/file.h>
|
||||
#include "PluginData.h"
|
||||
#include "PluginInformationFactory.h"
|
||||
#include "HookData.h"
|
||||
#include "SectionInfo.h"
|
||||
#include "../elfio/elfio.hpp"
|
||||
#include "../utils/utils.h"
|
||||
#include "../utils/ElfUtils.h"
|
||||
#include "../utils/StringTools.h"
|
||||
|
||||
using namespace ELFIO;
|
||||
|
||||
std::optional<PluginInformation> PluginInformationFactory::load(const PluginData &pluginData, MEMHeapHandle heapHandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId) {
|
||||
std::optional<PluginInformation>
|
||||
PluginInformationFactory::load(const PluginData &pluginData, MEMHeapHandle heapHandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId) {
|
||||
if (pluginData.buffer == nullptr) {
|
||||
DEBUG_FUNCTION_LINE("Buffer was NULL");
|
||||
DEBUG_FUNCTION_LINE("Buffer was nullptr");
|
||||
return std::nullopt;
|
||||
}
|
||||
elfio reader;
|
||||
@@ -62,7 +58,7 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
|
||||
|
||||
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
|
||||
uint32_t sectionSize = psec->get_size();
|
||||
uint32_t address = (uint32_t) psec->get_address();
|
||||
auto address = (uint32_t) psec->get_address();
|
||||
if ((address >= 0x02000000) && address < 0x10000000) {
|
||||
text_size += sectionSize;
|
||||
} else if ((address >= 0x10000000) && address < 0xC0000000) {
|
||||
@@ -89,8 +85,6 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
|
||||
}
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Allocated %d kb from ExpHeap", data_size / 1024);
|
||||
|
||||
uint32_t entrypoint = (uint32_t) text_data + (uint32_t) reader.get_entry() - 0x02000000;
|
||||
|
||||
for (uint32_t i = 0; i < sec_num; ++i) {
|
||||
section *psec = reader.sections[i];
|
||||
if (psec->get_type() == 0x80000002) {
|
||||
@@ -99,7 +93,7 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
|
||||
|
||||
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
|
||||
uint32_t sectionSize = psec->get_size();
|
||||
uint32_t address = (uint32_t) psec->get_address();
|
||||
auto address = (uint32_t) psec->get_address();
|
||||
|
||||
uint32_t destination = address;
|
||||
if ((address >= 0x02000000) && address < 0x10000000) {
|
||||
@@ -160,7 +154,7 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
|
||||
}
|
||||
std::vector<RelocationData> relocationData = getImportRelocationData(reader, destinations);
|
||||
|
||||
for (auto const &reloc : relocationData) {
|
||||
for (auto const &reloc: relocationData) {
|
||||
pluginInfo.addRelocationData(reloc);
|
||||
}
|
||||
|
||||
@@ -173,8 +167,6 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
|
||||
|
||||
pluginInfo.setTrampolinId(trampolinId);
|
||||
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Saved entrypoint as %08X", entrypoint);
|
||||
|
||||
std::optional<SectionInfo> secInfo = pluginInfo.getSectionInfo(".wups.hooks");
|
||||
if (secInfo && secInfo->getSize() > 0) {
|
||||
size_t entries_count = secInfo->getSize() / sizeof(wups_loader_hook_t);
|
||||
@@ -193,12 +185,15 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
|
||||
if (secInfo && secInfo->getSize() > 0) {
|
||||
size_t entries_count = secInfo->getSize() / sizeof(wups_loader_entry_t);
|
||||
auto *entries = (wups_loader_entry_t *) secInfo->getAddress();
|
||||
if (entries != NULL) {
|
||||
if (entries != nullptr) {
|
||||
for (size_t j = 0; j < entries_count; j++) {
|
||||
wups_loader_entry_t *cur_function = &entries[j];
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Saving function \"%s\" of plugin . PA:%08X VA:%08X Library: %08X, target: %08X, call_addr: %08X", cur_function->_function.name/*,pluginData.getPluginInformation()->getName().c_str()*/,
|
||||
cur_function->_function.physical_address, cur_function->_function.virtual_address, cur_function->_function.library, cur_function->_function.target, (void *) cur_function->_function.call_addr);
|
||||
FunctionData function_data((void *) cur_function->_function.physical_address, (void *) cur_function->_function.virtual_address, cur_function->_function.name, (function_replacement_library_type_t) cur_function->_function.library,
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Saving function \"%s\" of plugin . PA:%08X VA:%08X Library: %08X, target: %08X, call_addr: %08X",
|
||||
cur_function->_function.name/*,pluginData.getPluginInformation()->getName().c_str()*/,
|
||||
cur_function->_function.physical_address, cur_function->_function.virtual_address, cur_function->_function.library, cur_function->_function.target,
|
||||
(void *) cur_function->_function.call_addr);
|
||||
FunctionData function_data((void *) cur_function->_function.physical_address, (void *) cur_function->_function.virtual_address, cur_function->_function.name,
|
||||
(function_replacement_library_type_t) cur_function->_function.library,
|
||||
(void *) cur_function->_function.target, (void *) cur_function->_function.call_addr, (FunctionPatcherTargetProcess) cur_function->_function.targetProcess);
|
||||
pluginInfo.addFunctionData(function_data);
|
||||
}
|
||||
@@ -212,7 +207,7 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
|
||||
return pluginInfo;
|
||||
}
|
||||
|
||||
std::vector<RelocationData> PluginInformationFactory::getImportRelocationData(const elfio & reader, uint8_t **destinations) {
|
||||
std::vector<RelocationData> PluginInformationFactory::getImportRelocationData(const elfio &reader, uint8_t **destinations) {
|
||||
std::vector<RelocationData> result;
|
||||
|
||||
std::map<uint32_t, std::string> infoMap;
|
||||
@@ -244,7 +239,7 @@ std::vector<RelocationData> PluginInformationFactory::getImportRelocationData(co
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t adjusted_sym_value = (uint32_t) sym_value;
|
||||
auto adjusted_sym_value = (uint32_t) sym_value;
|
||||
if (adjusted_sym_value < 0xC0000000) {
|
||||
continue;
|
||||
}
|
||||
@@ -254,7 +249,7 @@ std::vector<RelocationData> PluginInformationFactory::getImportRelocationData(co
|
||||
|
||||
bool isData = false;
|
||||
|
||||
std::string rplName = "";
|
||||
std::string rplName;
|
||||
std::string rawSectionName = infoMap[sym_section_index];
|
||||
|
||||
if (rawSectionName.size() < fimport.size()) {
|
||||
@@ -274,14 +269,15 @@ std::vector<RelocationData> PluginInformationFactory::getImportRelocationData(co
|
||||
|
||||
uint32_t section_index = psec->get_info();
|
||||
|
||||
result.push_back(RelocationData(type, offset - 0x02000000, addend, (void *) (destinations[section_index]), sym_name, rplInfo));
|
||||
result.emplace_back(type, offset - 0x02000000, addend, (void *) (destinations[section_index]), sym_name, rplInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
|
||||
bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data,
|
||||
uint32_t trampolin_data_length,
|
||||
uint8_t trampolinId) {
|
||||
uint32_t sec_num = reader.sections.size();
|
||||
|
||||
@@ -303,7 +299,7 @@ bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t adjusted_sym_value = (uint32_t) sym_value;
|
||||
auto adjusted_sym_value = (uint32_t) sym_value;
|
||||
if ((adjusted_sym_value >= 0x02000000) && adjusted_sym_value < 0x10000000) {
|
||||
adjusted_sym_value -= 0x02000000;
|
||||
adjusted_sym_value += base_text;
|
||||
@@ -321,7 +317,7 @@ bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t adjusted_offset = (uint32_t) offset;
|
||||
auto adjusted_offset = (uint32_t) offset;
|
||||
if ((offset >= 0x02000000) && offset < 0x10000000) {
|
||||
adjusted_offset -= 0x02000000;
|
||||
} else if ((adjusted_offset >= 0x10000000) && adjusted_offset < 0xC0000000) {
|
||||
@@ -336,9 +332,8 @@ bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section
|
||||
DEBUG_FUNCTION_LINE("NOT IMPLEMENTED: %04X", sym_section_index);
|
||||
return false;
|
||||
}
|
||||
if (false) {
|
||||
DEBUG_FUNCTION_LINE("sym_value %08X adjusted_sym_value %08X offset %08X adjusted_offset %08X", (uint32_t) sym_value, adjusted_sym_value, (uint32_t) offset, adjusted_offset);
|
||||
}
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("sym_value %08X adjusted_sym_value %08X offset %08X adjusted_offset %08X", (uint32_t) sym_value, adjusted_sym_value, (uint32_t) offset, adjusted_offset);
|
||||
|
||||
if (!ElfUtils::elfLinkOne(type, adjusted_offset, addend, destination, adjusted_sym_value, trampolin_data, trampolin_data_length, RELOC_TYPE_FIXED, trampolinId)) {
|
||||
DEBUG_FUNCTION_LINE("Link failed");
|
||||
return false;
|
||||
|
||||
@@ -29,9 +29,12 @@
|
||||
|
||||
class PluginInformationFactory {
|
||||
public:
|
||||
static std::optional<PluginInformation> load(const PluginData &pluginData, MEMHeapHandle heaphandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId);
|
||||
static std::optional<PluginInformation>
|
||||
load(const PluginData &pluginData, MEMHeapHandle heaphandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId);
|
||||
|
||||
static bool linkSection(const elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId);
|
||||
static bool
|
||||
linkSection(const elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
|
||||
uint8_t trampolinId);
|
||||
|
||||
static std::vector<RelocationData> getImportRelocationData(const elfio &reader, uint8_t **destinations);
|
||||
};
|
||||
|
||||
@@ -24,38 +24,38 @@ class PluginMetaInformation {
|
||||
public:
|
||||
PluginMetaInformation(const PluginMetaInformation &other);
|
||||
|
||||
[[nodiscard]] std::string getName() const {
|
||||
[[nodiscard]] const std::string &getName() const {
|
||||
return name;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string getAuthor() const {
|
||||
[[nodiscard]] const std::string &getAuthor() const {
|
||||
return this->author;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string getVersion() const {
|
||||
[[nodiscard]] const std::string &getVersion() const {
|
||||
return this->version;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string getLicense() const {
|
||||
[[nodiscard]] const std::string &getLicense() const {
|
||||
return this->license;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string getBuildTimestamp() const {
|
||||
[[nodiscard]] const std::string &getBuildTimestamp() const {
|
||||
return this->buildtimestamp;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string getDescription() const {
|
||||
[[nodiscard]] const std::string &getDescription() const {
|
||||
return this->description;
|
||||
}
|
||||
|
||||
[[nodiscard]] const std::string &getId() const {
|
||||
return this->id;
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t getSize() const {
|
||||
return this->size;
|
||||
}
|
||||
|
||||
[[nodiscard]] const std::string getId() const {
|
||||
return this->id;
|
||||
}
|
||||
|
||||
private:
|
||||
PluginMetaInformation() = default;
|
||||
|
||||
@@ -87,8 +87,8 @@ private:
|
||||
this->size = _size;
|
||||
}
|
||||
|
||||
void setId(const std::string &id) {
|
||||
this->id = id;
|
||||
void setId(const std::string &_id) {
|
||||
this->id = _id;
|
||||
}
|
||||
|
||||
std::string name;
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
using namespace ELFIO;
|
||||
|
||||
std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(const PluginData &pluginData) {
|
||||
if (pluginData.buffer == NULL) {
|
||||
DEBUG_FUNCTION_LINE("Buffer was NULL");
|
||||
if (pluginData.buffer == nullptr) {
|
||||
DEBUG_FUNCTION_LINE("Buffer was nullptr");
|
||||
return std::nullopt;
|
||||
}
|
||||
elfio reader;
|
||||
@@ -59,7 +59,7 @@ std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(ch
|
||||
return loadPlugin(reader);
|
||||
}
|
||||
|
||||
std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(const elfio& reader) {
|
||||
std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(const elfio &reader) {
|
||||
size_t pluginSize = 0;
|
||||
|
||||
PluginMetaInformation pluginInfo;
|
||||
@@ -72,7 +72,7 @@ std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(co
|
||||
// Calculate total size:
|
||||
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
|
||||
uint32_t sectionSize = psec->get_size();
|
||||
uint32_t address = (uint32_t) psec->get_address();
|
||||
auto address = (uint32_t) psec->get_address();
|
||||
if ((address >= 0x02000000) && address < 0x10000000) {
|
||||
pluginSize += sectionSize;
|
||||
} else if ((address >= 0x10000000) && address < 0xC0000000) {
|
||||
@@ -98,22 +98,22 @@ std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(co
|
||||
std::string key(curEntry);
|
||||
std::string value(curEntry + firstFound + 1);
|
||||
|
||||
if (key.compare("name") == 0) {
|
||||
if (key == "name") {
|
||||
pluginInfo.setName(value);
|
||||
} else if (key.compare("author") == 0) {
|
||||
} else if (key == "author") {
|
||||
pluginInfo.setAuthor(value);
|
||||
} else if (key.compare("version") == 0) {
|
||||
} else if (key == "version") {
|
||||
pluginInfo.setVersion(value);
|
||||
} else if (key.compare("license") == 0) {
|
||||
} else if (key == "license") {
|
||||
pluginInfo.setLicense(value);
|
||||
} else if (key.compare("buildtimestamp") == 0) {
|
||||
} else if (key == "buildtimestamp") {
|
||||
pluginInfo.setBuildTimestamp(value);
|
||||
} else if (key.compare("description") == 0) {
|
||||
} else if (key == "description") {
|
||||
pluginInfo.setDescription(value);
|
||||
} else if (key.compare("id") == 0) {
|
||||
} else if (key == "id") {
|
||||
pluginInfo.setId(value);
|
||||
} else if (key.compare("wups") == 0) {
|
||||
if (value.compare("0.6") != 0) {
|
||||
} else if (key == "wups") {
|
||||
if (value != "0.6") {
|
||||
DEBUG_FUNCTION_LINE("Warning: Ignoring plugin - Unsupported WUPS version: %s.", value.c_str());
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@@ -31,5 +31,5 @@ public:
|
||||
|
||||
static std::optional<PluginMetaInformation> loadPlugin(char *buffer, size_t size);
|
||||
|
||||
static std::optional<PluginMetaInformation> loadPlugin(const elfio& reader);
|
||||
static std::optional<PluginMetaInformation> loadPlugin(const elfio &reader);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user