Format the code via clang-format

This commit is contained in:
Maschell
2022-02-04 16:25:44 +01:00
parent c21f9d8567
commit 2547c7edca
75 changed files with 637 additions and 554 deletions

View File

@@ -10,7 +10,7 @@ dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_li
return nullptr;
}
dyn_linking_function_t *result = nullptr;
for (auto &curEntry: data->functions) {
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.");
@@ -41,7 +41,7 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocatio
return nullptr;
}
dyn_linking_import_t *result = nullptr;
for (auto &curEntry: data->imports) {
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.");
@@ -49,7 +49,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)) {
@@ -92,12 +92,12 @@ bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_entry_t *lin
if (curEntry->functionEntry != nullptr) {
continue;
}
curEntry->type = type;
curEntry->offset = offset;
curEntry->addend = addend;
curEntry->destination = (void *) destination;
curEntry->type = type;
curEntry->offset = offset;
curEntry->addend = addend;
curEntry->destination = (void *) destination;
curEntry->functionEntry = functionName;
curEntry->importEntry = importInfo;
curEntry->importEntry = importInfo;
return true;
}
DEBUG_FUNCTION_LINE("Failed to find empty slot for saving relocations entry. We ned more than %d slots.", linking_entry_length);

View File

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

View File

@@ -16,22 +16,22 @@
****************************************************************************/
#pragma once
#include <wups.h>
#include <string>
#include <function_patcher/fpatching_defines.h>
#include <string>
#include <wups.h>
class FunctionData {
public:
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;
this->library = library;
this->paddress = paddress;
this->vaddress = vaddress;
this->name = name;
this->library = library;
this->targetProcess = targetProcess;
this->replaceAddr = replaceAddr;
this->replaceCall = replaceCall;
this->replaceAddr = replaceAddr;
this->replaceCall = replaceCall;
}
~FunctionData() = default;
@@ -73,4 +73,3 @@ private:
void *replaceAddr = nullptr;
void *replaceCall = nullptr;
};

View File

@@ -24,14 +24,13 @@ class FunctionSymbolData {
public:
FunctionSymbolData(const FunctionSymbolData &o2) = default;
FunctionSymbolData(std::string &name, void *address, uint32_t size) :
name(name),
address(address),
size(size) {
FunctionSymbolData(std::string &name, void *address, uint32_t size) : name(name),
address(address),
size(size) {
}
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
}
virtual ~FunctionSymbolData() = default;

View File

@@ -17,15 +17,15 @@
#pragma once
#include <wups.h>
#include <string>
#include <wups.h>
class HookData {
public:
HookData(void *function_pointer, wups_loader_hook_type_t type) {
this->function_pointer = function_pointer;
this->type = type;
this->type = type;
}
~HookData() = default;

View File

@@ -17,15 +17,15 @@
#pragma once
#include "../utils/logger.h"
#include <string>
#include <utility>
#include "../utils/logger.h"
class ImportRPLInformation {
public:
explicit ImportRPLInformation(std::string name, bool isData = false) {
this->name = std::move(name);
this->name = std::move(name);
this->_isData = isData;
}

View File

@@ -17,17 +17,17 @@
#pragma once
#include <memory>
#include "PluginData.h"
#include "PluginMetaInformation.h"
#include "PluginInformation.h"
#include "PluginMetaInformation.h"
#include <memory>
class PluginContainer {
public:
PluginContainer(const PluginContainer &other) {
this->pluginData = other.pluginData;
this->pluginData = other.pluginData;
this->pluginInformation = other.pluginInformation;
this->metaInformation = other.metaInformation;
this->metaInformation = other.metaInformation;
}
PluginContainer() = default;

View File

@@ -2,12 +2,12 @@
#include <memory>
#include "DynamicLinkingHelper.h"
#include "PluginContainer.h"
#include "PluginInformationFactory.h"
#include "PluginMetaInformationFactory.h"
#include "PluginContainerPersistence.h"
#include "PluginDataPersistence.h"
#include "DynamicLinkingHelper.h"
#include "PluginInformationFactory.h"
#include "PluginMetaInformationFactory.h"
bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformation, const std::shared_ptr<PluginContainer> &plugin, MEMHeapHandle heapHandle) {
int32_t plugin_count = pluginInformation->number_used_plugins;
@@ -25,7 +25,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
memset((void *) plugin_data, 0, sizeof(plugin_information_single_t));
const auto &pluginMetaInfo = plugin->getMetaInformation();
auto plugin_meta_data = &plugin_data->meta;
auto plugin_meta_data = &plugin_data->meta;
if (pluginMetaInfo->getName().size() >= MAXIMUM_PLUGIN_META_FIELD_LENGTH) {
DEBUG_FUNCTION_LINE("Warning: name will be truncated.");
@@ -68,7 +68,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
// Relocation
auto 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;
@@ -76,7 +76,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
}
auto function_data_list = pluginInfo->getFunctionDataList();
auto hook_data_list = pluginInfo->getHookDataList();
auto hook_data_list = pluginInfo->getHookDataList();
if (function_data_list.size() > MAXIMUM_FUNCTION_PER_PLUGIN) {
DEBUG_FUNCTION_LINE("Plugin %s would replace to many function (%d, maximum is %d). It won't be loaded.", pluginName.c_str(), function_data_list.size(), MAXIMUM_FUNCTION_PER_PLUGIN);
@@ -94,7 +94,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());
@@ -105,12 +105,12 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
strncpy(function_data->function_name, curFunction->getName().c_str(), MAXIMUM_FUNCTION_NAME_LENGTH - 1);
function_data->VERSION = FUNCTION_REPLACEMENT_DATA_STRUCT_VERSION;
function_data->library = (function_replacement_library_type_t) curFunction->getLibrary();
function_data->replaceAddr = (uint32_t) curFunction->getReplaceAddress();
function_data->replaceCall = (uint32_t) curFunction->getReplaceCall();
function_data->physicalAddr = (uint32_t) curFunction->getPhysicalAddress();
function_data->virtualAddr = (uint32_t) curFunction->getVirtualAddress();
function_data->VERSION = FUNCTION_REPLACEMENT_DATA_STRUCT_VERSION;
function_data->library = (function_replacement_library_type_t) curFunction->getLibrary();
function_data->replaceAddr = (uint32_t) curFunction->getReplaceAddress();
function_data->replaceCall = (uint32_t) curFunction->getReplaceCall();
function_data->physicalAddr = (uint32_t) curFunction->getPhysicalAddress();
function_data->virtualAddr = (uint32_t) curFunction->getVirtualAddress();
function_data->targetProcess = curFunction->getTargetProcess();
plugin_data->info.number_used_functions++;
@@ -118,27 +118,27 @@ 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());
hook_data->func_pointer = (void *) curHook->getFunctionPointer();
hook_data->type = curHook->getType();
hook_data->type = curHook->getType();
plugin_data->info.number_used_hooks++;
i++;
}
/* Saving SectionInfos */
for (auto &curSection: pluginInfo->getSectionInfoList()) {
for (auto &curSection : pluginInfo->getSectionInfoList()) {
bool foundFreeSlot = false;
uint32_t slot = 0;
uint32_t slot = 0;
for (uint32_t j = 0; j < MAXIMUM_PLUGIN_SECTION_LENGTH; j++) {
auto *sectionInfo = &(plugin_data->info.sectionInfos[j]);
if (sectionInfo->addr == 0 && sectionInfo->size == 0) {
foundFreeSlot = true;
slot = j;
slot = j;
break;
}
}
@@ -157,7 +157,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
return false;
}
}
plugin_data->info.trampolineId = pluginInfo->getTrampolineId();
plugin_data->info.trampolineId = pluginInfo->getTrampolineId();
plugin_data->info.allocatedTextMemoryAddress = pluginInfo->allocatedTextMemoryAddress;
plugin_data->info.allocatedDataMemoryAddress = pluginInfo->allocatedDataMemoryAddress;
@@ -165,7 +165,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
if (entryCount > 0) {
// Saving SectionInfos
uint32_t funcSymStringLen = 1;
for (auto &curFuncSym: pluginInfo->getFunctionSymbolDataList()) {
for (auto &curFuncSym : pluginInfo->getFunctionSymbolDataList()) {
funcSymStringLen += curFuncSym->getName().length() + 1;
}
@@ -186,25 +186,25 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
DEBUG_FUNCTION_LINE("Allocated %d for the function symbol data", entryCount * sizeof(plugin_function_symbol_data_t));
uint32_t curStringOffset = 0;
uint32_t curEntryIndex = 0;
for (auto &curFuncSym: pluginInfo->getFunctionSymbolDataList()) {
uint32_t curEntryIndex = 0;
for (auto &curFuncSym : pluginInfo->getFunctionSymbolDataList()) {
entryTable[curEntryIndex].address = curFuncSym->getAddress();
entryTable[curEntryIndex].name = &stringTable[curStringOffset];
entryTable[curEntryIndex].size = curFuncSym->getSize();
auto len = curFuncSym->getName().length() + 1;
entryTable[curEntryIndex].name = &stringTable[curStringOffset];
entryTable[curEntryIndex].size = curFuncSym->getSize();
auto len = curFuncSym->getName().length() + 1;
memcpy(stringTable + curStringOffset, curFuncSym->getName().c_str(), len);
curStringOffset += len;
curEntryIndex++;
}
plugin_data->info.allocatedFuncSymStringTableAddress = stringTable;
plugin_data->info.function_symbol_data = entryTable;
plugin_data->info.function_symbol_data = entryTable;
}
plugin_data->info.number_function_symbol_data = entryCount;
/* Copy plugin data */
auto pluginData = plugin->getPluginData();
auto pluginData = plugin->getPluginData();
auto plugin_data_data = &plugin_data->data;
PluginDataPersistence::save(plugin_data_data, pluginData);
@@ -257,7 +257,7 @@ std::vector<std::shared_ptr<PluginContainer>> PluginContainerPersistence::loadPl
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;
@@ -281,7 +281,7 @@ std::vector<std::shared_ptr<PluginContainer>> PluginContainerPersistence::loadPl
}
bool storageHasId = true;
for (auto const &value: curPluginInformation->getHookDataList()) {
for (auto const &value : curPluginInformation->getHookDataList()) {
if (value->getType() == WUPS_LOADER_HOOK_INIT_STORAGE &&
metaInformation->getStorageId().empty()) {
storageHasId = false;
@@ -302,14 +302,14 @@ std::vector<std::shared_ptr<PluginContainer>> PluginContainerPersistence::loadPl
for (uint32_t j = 0; j < functionReplaceCount; j++) {
function_replacement_data_t *entry = &(plugin_data->info.functions[j]);
auto func = std::make_shared<FunctionData>((void *) entry->physicalAddr, (void *) entry->virtualAddr, entry->function_name, (function_replacement_library_type_t) entry->library,
auto func = std::make_shared<FunctionData>((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_entry: plugin_data->info.linking_entries) {
for (auto &linking_entry : plugin_data->info.linking_entries) {
if (linking_entry.destination == nullptr) {
break;
}
@@ -332,9 +332,9 @@ std::vector<std::shared_ptr<PluginContainer>> PluginContainerPersistence::loadPl
/* load function symbol data */
for (uint32_t j = 0; j < plugin_data->info.number_function_symbol_data; j++) {
auto symbol_data = &plugin_data->info.function_symbol_data[j];
auto symbol_data = &plugin_data->info.function_symbol_data[j];
std::string symbol_name = symbol_data->name;
auto funSymbolData = std::make_shared<FunctionSymbolData>(symbol_name, (void *) symbol_data->address, symbol_data->size);
auto funSymbolData = std::make_shared<FunctionSymbolData>(symbol_name, (void *) symbol_data->address, symbol_data->size);
curPluginInformation->addFunctionSymbolData(funSymbolData);
}

View File

@@ -1,14 +1,14 @@
#include "PluginData.h"
#include <utility>
#include <malloc.h>
#include "../utils/logger.h"
#include <malloc.h>
#include <utility>
PluginData::PluginData(const PluginData &obj) {
this->buffer = obj.buffer;
this->buffer = obj.buffer;
this->heapHandle = obj.heapHandle;
this->memoryType = obj.memoryType;
this->length = obj.length;
this->length = obj.length;
}
void PluginData::freeMemory() {
@@ -34,10 +34,9 @@ void PluginData::freeMemory() {
PluginData::PluginData(const std::vector<uint8_t> &buffer) : PluginData(buffer, nullptr, eMemTypeMEM2) {
}
PluginData::PluginData(const std::vector<uint8_t> &input, MEMHeapHandle heapHandle, eMemoryTypes memoryType) :
heapHandle(heapHandle),
memoryType(memoryType),
length(input.size()) {
PluginData::PluginData(const std::vector<uint8_t> &input, MEMHeapHandle heapHandle, eMemoryTypes memoryType) : heapHandle(heapHandle),
memoryType(memoryType),
length(input.size()) {
void *data_copy = nullptr;
switch (memoryType) {
default:

View File

@@ -17,10 +17,10 @@
#pragma once
#include <coreinit/memexpheap.h>
#include <malloc.h>
#include <optional>
#include <vector>
#include <malloc.h>
#include <coreinit/memexpheap.h>
#include "../elfio/elfio.hpp"

View File

@@ -14,13 +14,13 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include <fcntl.h>
#include <sys/stat.h>
#include <dirent.h>
#include <memory>
#include "PluginDataFactory.h"
#include "../utils/logger.h"
#include "../utils/StringTools.h"
#include "../utils/logger.h"
#include <dirent.h>
#include <fcntl.h>
#include <memory>
#include <sys/stat.h>
std::vector<std::shared_ptr<PluginData>> PluginDataFactory::loadDir(const std::string &path, MEMHeapHandle heapHandle) {
@@ -39,7 +39,7 @@ std::vector<std::shared_ptr<PluginData>> PluginDataFactory::loadDir(const std::s
}
while ((dp = readdir(dfd)) != nullptr) {
struct stat stbuf{};
struct stat stbuf {};
std::string full_file_path = StringTools::strfmt("%s/%s", path.c_str(), dp->d_name);
StringTools::RemoveDoubleSlashs(full_file_path);
if (stat(full_file_path.c_str(), &stbuf) == -1) {

View File

@@ -17,11 +17,12 @@
#pragma once
#include "PluginData.h"
#include <coreinit/memexpheap.h>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include <coreinit/memexpheap.h>
#include "PluginData.h"
class PluginDataFactory {
public:

View File

@@ -1,15 +1,15 @@
#include <memory>
#include "../common/plugin_defines.h"
#include "PluginDataPersistence.h"
#include "../common/plugin_defines.h"
#include <memory>
bool PluginDataPersistence::save(plugin_data_t *pluginDataStruct, const std::shared_ptr<PluginData> &plugin) {
if (pluginDataStruct == nullptr) {
return false;
}
pluginDataStruct->buffer = (char *) plugin->buffer;
pluginDataStruct->buffer = (char *) plugin->buffer;
pluginDataStruct->bufferLength = plugin->length;
pluginDataStruct->memoryType = plugin->memoryType;
pluginDataStruct->heapHandle = (int) plugin->heapHandle;
pluginDataStruct->memoryType = plugin->memoryType;
pluginDataStruct->heapHandle = (int) plugin->heapHandle;
return true;
}
@@ -17,18 +17,18 @@ bool PluginDataPersistence::save(plugin_data_t *pluginDataStruct, PluginData *pl
if (pluginDataStruct == nullptr) {
return false;
}
pluginDataStruct->buffer = (char *) plugin->buffer;
pluginDataStruct->buffer = (char *) plugin->buffer;
pluginDataStruct->bufferLength = plugin->length;
pluginDataStruct->memoryType = plugin->memoryType;
pluginDataStruct->heapHandle = (int) plugin->heapHandle;
pluginDataStruct->memoryType = plugin->memoryType;
pluginDataStruct->heapHandle = (int) plugin->heapHandle;
return true;
}
std::shared_ptr<PluginData> PluginDataPersistence::load(plugin_data_t *pluginDataStruct) {
auto pluginData = std::make_shared<PluginData>();
pluginData->buffer = pluginDataStruct->buffer;
pluginData->length = pluginDataStruct->bufferLength;
pluginData->buffer = pluginDataStruct->buffer;
pluginData->length = pluginDataStruct->bufferLength;
pluginData->memoryType = (eMemoryTypes) pluginDataStruct->memoryType;
pluginData->heapHandle = (MEMHeapHandle) pluginDataStruct->heapHandle;
return pluginData;

View File

@@ -1,6 +1,8 @@
#pragma once
#include "../common/plugin_defines.h"
#include "PluginData.h"
#include <memory>
class PluginDataPersistence {

View File

@@ -1,20 +1,20 @@
#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);
}
for (const auto &i: other.symbol_data_list) {
for (const auto &i : other.symbol_data_list) {
symbol_data_list.insert(i);
}
section_info_list = other.section_info_list;
trampolineId = other.trampolineId;
section_info_list = other.section_info_list;
trampolineId = other.trampolineId;
allocatedTextMemoryAddress = other.allocatedTextMemoryAddress;
allocatedDataMemoryAddress = other.allocatedDataMemoryAddress;
}

View File

@@ -17,18 +17,18 @@
#pragma once
#include <map>
#include <set>
#include <optional>
#include <string>
#include <vector>
#include <memory>
#include "FunctionData.h"
#include "FunctionSymbolData.h"
#include "HookData.h"
#include "PluginMetaInformation.h"
#include "RelocationData.h"
#include "HookData.h"
#include "FunctionData.h"
#include "SectionInfo.h"
#include "FunctionSymbolData.h"
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <vector>
struct FunctionSymbolDataComparator {
bool operator()(const std::shared_ptr<FunctionSymbolData> &lhs,

View File

@@ -15,17 +15,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "PluginInformationFactory.h"
#include "../utils/ElfUtils.h"
#include "../utils/utils.h"
#include "PluginData.h"
#include <coreinit/cache.h>
#include <coreinit/memexpheap.h>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <map>
#include <coreinit/cache.h>
#include <coreinit/memexpheap.h>
#include <wups.h>
#include "PluginData.h"
#include "PluginInformationFactory.h"
#include "../utils/utils.h"
#include "../utils/ElfUtils.h"
using namespace ELFIO;
@@ -44,7 +44,7 @@ PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, ME
auto pluginInfo = std::make_shared<PluginInformation>();
uint32_t sec_num = reader.sections.size();
uint32_t sec_num = reader.sections.size();
auto **destinations = (uint8_t **) malloc(sizeof(uint8_t *) * sec_num);
uint32_t totalSize = 0;
@@ -60,7 +60,7 @@ PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, ME
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
uint32_t sectionSize = psec->get_size();
auto 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) {
@@ -95,7 +95,7 @@ PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, ME
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
uint32_t sectionSize = psec->get_size();
auto address = (uint32_t) psec->get_address();
auto address = (uint32_t) psec->get_address();
uint32_t destination = address;
if ((address >= 0x02000000) && address < 0x10000000) {
@@ -157,7 +157,7 @@ PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, ME
}
auto relocationData = getImportRelocationData(reader, destinations);
for (auto const &reloc: relocationData) {
for (auto const &reloc : relocationData) {
pluginInfo->addRelocationData(reloc);
}
@@ -173,11 +173,11 @@ PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, ME
auto secInfo = pluginInfo->getSectionInfo(".wups.hooks");
if (secInfo && secInfo.value()->getSize() > 0) {
size_t entries_count = secInfo.value()->getSize() / sizeof(wups_loader_hook_t);
auto *entries = (wups_loader_hook_t *) secInfo.value()->getAddress();
auto *entries = (wups_loader_hook_t *) secInfo.value()->getAddress();
if (entries != nullptr) {
for (size_t j = 0; j < entries_count; j++) {
wups_loader_hook_t *hook = &entries[j];
DEBUG_FUNCTION_LINE_VERBOSE("Saving hook of plugin Type: %08X, target: %08X"/*,pluginData->getPluginInformation()->getName().c_str()*/, hook->type, (void *) hook->target);
DEBUG_FUNCTION_LINE_VERBOSE("Saving hook of plugin Type: %08X, target: %08X" /*,pluginData->getPluginInformation()->getName().c_str()*/, hook->type, (void *) hook->target);
auto hook_data = std::make_shared<HookData>((void *) hook->target, hook->type);
pluginInfo->addHookData(hook_data);
}
@@ -187,12 +187,12 @@ PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, ME
secInfo = pluginInfo->getSectionInfo(".wups.load");
if (secInfo && secInfo.value()->getSize() > 0) {
size_t entries_count = secInfo.value()->getSize() / sizeof(wups_loader_entry_t);
auto *entries = (wups_loader_entry_t *) secInfo.value()->getAddress();
auto *entries = (wups_loader_entry_t *) secInfo.value()->getAddress();
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.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);
auto function_data = std::make_shared<FunctionData>((void *) cur_function->_function.physical_address, (void *) cur_function->_function.virtual_address, cur_function->_function.name,
@@ -214,17 +214,17 @@ PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, ME
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 = pluginInfo->getSectionInfo(sectionVal->get_name());
if (!sectionOpt.has_value()) {
continue;
@@ -299,7 +299,7 @@ std::vector<std::shared_ptr<RelocationData>> PluginInformationFactory::getImport
rplName = rawSectionName.substr(fimport.size());
} else if (std::equal(dimport.begin(), dimport.end(), rawSectionName.begin())) {
rplName = rawSectionName.substr(dimport.size());
isData = true;
isData = true;
} else {
DEBUG_FUNCTION_LINE("invalid section name");
continue;

View File

@@ -17,15 +17,15 @@
#pragma once
#include "../elfio/elfio.hpp"
#include "PluginContainer.h"
#include "PluginInformation.h"
#include <coreinit/memheap.h>
#include <map>
#include <optional>
#include <string>
#include <vector>
#include <map>
#include <coreinit/memheap.h>
#include <wums/defines/relocation_defines.h>
#include "PluginInformation.h"
#include "PluginContainer.h"
#include "../elfio/elfio.hpp"
class PluginInformationFactory {
public:

View File

@@ -1,12 +1,12 @@
#include "PluginMetaInformation.h"
PluginMetaInformation::PluginMetaInformation(const PluginMetaInformation &other) {
this->name = other.name;
this->author = other.author;
this->version = other.version;
this->license = other.license;
this->name = other.name;
this->author = other.author;
this->version = other.version;
this->license = other.license;
this->buildtimestamp = other.buildtimestamp;
this->description = other.description;
this->size = other.size;
this->storageId = other.storageId;
this->description = other.description;
this->size = other.size;
this->storageId = other.storageId;
}

View File

@@ -15,12 +15,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include <sys/types.h>
#include <dirent.h>
#include <whb/file.h>
#include <memory>
#include "../utils/StringTools.h"
#include "PluginMetaInformationFactory.h"
#include "../utils/StringTools.h"
#include <dirent.h>
#include <memory>
#include <sys/types.h>
#include <whb/file.h>
using namespace ELFIO;
@@ -69,7 +69,7 @@ std::optional<std::shared_ptr<PluginMetaInformation>> PluginMetaInformationFacto
// 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();
auto 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) {
@@ -80,7 +80,7 @@ std::optional<std::shared_ptr<PluginMetaInformation>> PluginMetaInformationFacto
// Get meta information and check WUPS version:
if (psec->get_name() == ".wups.meta") {
const void *sectionData = psec->get_data();
uint32_t sectionSize = psec->get_size();
uint32_t sectionSize = psec->get_size();
char *curEntry = (char *) sectionData;
while ((uint32_t) curEntry < (uint32_t) sectionData + sectionSize) {

View File

@@ -17,12 +17,12 @@
#pragma once
#include "PluginData.h"
#include "PluginMetaInformation.h"
#include <memory>
#include <optional>
#include <string>
#include <memory>
#include <vector>
#include "PluginMetaInformation.h"
#include "PluginData.h"
class PluginMetaInformationFactory {
public:

View File

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

View File

@@ -22,10 +22,9 @@
class SectionInfo {
public:
SectionInfo(std::string &name, uint32_t address, uint32_t sectionSize) :
name(name),
address(address),
sectionSize(sectionSize) {
SectionInfo(std::string &name, uint32_t address, uint32_t sectionSize) : name(name),
address(address),
sectionSize(sectionSize) {
}
SectionInfo() = default;