Clean up and formatting

This commit is contained in:
Maschell 2020-12-26 14:17:50 +01:00
parent 0467178650
commit e9bd4651ca
30 changed files with 283 additions and 325 deletions

View File

@ -1,10 +1,14 @@
#include <plugin/PluginContainer.h>
#include <utils/ElfUtils.h>
#include <coreinit/cache.h> #include <coreinit/cache.h>
#include <plugin/PluginMetaInformationFactory.h>
#include <plugin/PluginInformationFactory.h>
#include <coreinit/dynload.h> #include <coreinit/dynload.h>
#include <coreinit/memdefaultheap.h>
#include "patcher/hooks_patcher_static.h" #include "patcher/hooks_patcher_static.h"
#include "plugin/PluginContainer.h"
#include "plugin/PluginMetaInformationFactory.h"
#include "plugin/PluginInformationFactory.h"
#include "utils/logger.h"
#include "utils/ElfUtils.h"
#include "PluginManagement.h" #include "PluginManagement.h"
#include "hooks.h" #include "hooks.h"
@ -12,17 +16,17 @@ bool PluginManagement::doRelocation(const std::vector<RelocationData> &relocData
std::map<std::string, OSDynLoad_Module> moduleHandleCache; std::map<std::string, OSDynLoad_Module> moduleHandleCache;
for (auto const &cur : relocData) { for (auto const &cur : relocData) {
uint32_t functionAddress = 0; uint32_t functionAddress = 0;
std::string functionName = cur.getName(); const std::string &functionName = cur.getName();
if (functionName.compare("MEMAllocFromDefaultHeap") == 0) { if (functionName == "MEMAllocFromDefaultHeap") {
OSDynLoad_Module rplHandle; OSDynLoad_Module rplHandle;
OSDynLoad_Acquire("homebrew_memorymapping", &rplHandle); OSDynLoad_Acquire("homebrew_memorymapping", &rplHandle);
OSDynLoad_FindExport(rplHandle, 1, "MEMAllocFromMappedMemory", (void **) &functionAddress); OSDynLoad_FindExport(rplHandle, 1, "MEMAllocFromMappedMemory", (void **) &functionAddress);
} else if (functionName.compare("MEMAllocFromDefaultHeapEx") == 0) { } else if (functionName == "MEMAllocFromDefaultHeapEx") {
OSDynLoad_Module rplHandle; OSDynLoad_Module rplHandle;
OSDynLoad_Acquire("homebrew_memorymapping", &rplHandle); OSDynLoad_Acquire("homebrew_memorymapping", &rplHandle);
OSDynLoad_FindExport(rplHandle, 1, "MEMAllocFromMappedMemoryEx", (void **) &functionAddress); OSDynLoad_FindExport(rplHandle, 1, "MEMAllocFromMappedMemoryEx", (void **) &functionAddress);
} else if (functionName.compare("MEMFreeToDefaultHeap") == 0) { } else if (functionName == "MEMFreeToDefaultHeap") {
OSDynLoad_Module rplHandle; OSDynLoad_Module rplHandle;
OSDynLoad_Acquire("homebrew_memorymapping", &rplHandle); OSDynLoad_Acquire("homebrew_memorymapping", &rplHandle);
OSDynLoad_FindExport(rplHandle, 1, "MEMFreeToMappedMemory", (void **) &functionAddress); OSDynLoad_FindExport(rplHandle, 1, "MEMFreeToMappedMemory", (void **) &functionAddress);
@ -31,7 +35,7 @@ bool PluginManagement::doRelocation(const std::vector<RelocationData> &relocData
if (functionAddress == 0) { if (functionAddress == 0) {
std::string rplName = cur.getImportRPLInformation().getName(); std::string rplName = cur.getImportRPLInformation().getName();
int32_t isData = cur.getImportRPLInformation().isData(); int32_t isData = cur.getImportRPLInformation().isData();
OSDynLoad_Module rplHandle = 0; OSDynLoad_Module rplHandle = nullptr;
if (moduleHandleCache.count(rplName) > 0) { if (moduleHandleCache.count(rplName) > 0) {
rplHandle = moduleHandleCache[rplName]; rplHandle = moduleHandleCache[rplName];
} else { } else {
@ -138,10 +142,10 @@ void PluginManagement::unloadPlugins(plugin_information_t *gPluginInformation, M
DEBUG_FUNCTION_LINE("Freed %08X", plugin->info.allocatedDataMemoryAddress); DEBUG_FUNCTION_LINE("Freed %08X", plugin->info.allocatedDataMemoryAddress);
} }
for (uint32_t i = 0; i < DYN_LINK_TRAMPOLIN_LIST_LENGTH; i++) { for (auto &trampoline : gPluginInformation->trampolines) {
if (gPluginInformation->trampolines[i].id == plugin->info.trampolinId) { if (trampoline.id == plugin->info.trampolinId) {
gPluginInformation->trampolines[i].id = 0; trampoline.id = 0;
gPluginInformation->trampolines[i].status = RELOC_TRAMP_FREE; trampoline.status = RELOC_TRAMP_FREE;
} }
} }
} }

View File

@ -1,6 +1,7 @@
#include "globals.h" #include "globals.h"
MEMHeapHandle pluginDataHeap __attribute__((section(".data"))) = 0; MEMHeapHandle pluginDataHeap __attribute__((section(".data"))) = nullptr;
plugin_information_t *gPluginInformation __attribute__((section(".data"))) = NULL; plugin_information_t *gPluginInformation __attribute__((section(".data"))) = nullptr;
plugin_information_on_reload_t gLinkOnReload __attribute__((section(".data")));
plugin_information_on_reload_t gLinkOnReload __attribute__((section(".data"))); module_information_t *gModuleData __attribute__((section(".data"))) = nullptr;

View File

@ -1,10 +1,14 @@
#pragma once #pragma once
#include <plugin/PluginContainer.h> #include <wums.h>
#include <common/plugin_defines.h>
#include "plugin/PluginContainer.h"
#include "common/plugin_defines.h"
extern plugin_information_t *gPluginInformation; extern plugin_information_t *gPluginInformation;
extern MEMHeapHandle pluginDataHeap; extern MEMHeapHandle pluginDataHeap;
extern plugin_information_on_reload_t gLinkOnReload; extern plugin_information_on_reload_t gLinkOnReload;
extern module_information_t *gModuleData;
extern "C" void __init_wut(); extern "C" void __init_wut();
extern "C" void __fini_wut(); extern "C" void __fini_wut();

View File

@ -1,7 +1,6 @@
#include "hooks.h" #include "hooks.h"
#include "utils/logger.h" #include "utils/logger.h"
void CallHook(plugin_information_t *pluginInformation, wups_loader_hook_type_t hook_type) { void CallHook(plugin_information_t *pluginInformation, wups_loader_hook_type_t hook_type) {
CallHookEx(pluginInformation, hook_type, -1); CallHookEx(pluginInformation, hook_type, -1);
} }
@ -66,41 +65,41 @@ void CallHookEx(plugin_information_t *pluginInformation, wups_loader_hook_type_t
DEBUG_FUNCTION_LINE("Calling hook of type %s for plugin %s [%d]", hook_names[hook_data->type], plugin_data->meta.name, hook_type); DEBUG_FUNCTION_LINE("Calling hook of type %s for plugin %s [%d]", hook_names[hook_data->type], plugin_data->meta.name, hook_type);
} }
void *func_ptr = hook_data->func_pointer; void *func_ptr = hook_data->func_pointer;
if (func_ptr != NULL) { if (func_ptr != nullptr) {
//DEBUG_FUNCTION_LINE("function pointer is %08x\n",func_ptr); //DEBUG_FUNCTION_LINE("function pointer is %08x\n",func_ptr);
if (hook_type == WUPS_LOADER_HOOK_INIT_PLUGIN) { if (hook_type == WUPS_LOADER_HOOK_INIT_PLUGIN) {
((void (*)(void)) ((uint32_t *) func_ptr))(); ((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_DEINIT_PLUGIN) { } else if (hook_type == WUPS_LOADER_HOOK_DEINIT_PLUGIN) {
((void (*)(void)) ((uint32_t *) func_ptr))(); ((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_APPLICATION_START) { } else if (hook_type == WUPS_LOADER_HOOK_APPLICATION_START) {
wups_loader_app_started_args_t args; wups_loader_app_started_args_t args;
((void (*)(wups_loader_app_started_args_t)) ((uint32_t *) func_ptr))(args); ((void (*)(wups_loader_app_started_args_t)) ((uint32_t *) func_ptr))(args);
} else if (hook_type == WUPS_LOADER_HOOK_FUNCTIONS_PATCHED) { } else if (hook_type == WUPS_LOADER_HOOK_FUNCTIONS_PATCHED) {
((void (*)(void)) ((uint32_t *) func_ptr))(); ((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_APPLICATION_END) { } else if (hook_type == WUPS_LOADER_HOOK_APPLICATION_END) {
((void (*)(void)) ((uint32_t *) func_ptr))(); ((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_INIT_WUT_MALLOC) { } else if (hook_type == WUPS_LOADER_HOOK_INIT_WUT_MALLOC) {
((void (*)(void)) ((uint32_t *) func_ptr))(); ((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_FINI_WUT_MALLOC) { } else if (hook_type == WUPS_LOADER_HOOK_FINI_WUT_MALLOC) {
((void (*)(void)) ((uint32_t *) func_ptr))(); ((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB) { } else if (hook_type == WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB) {
((void (*)(void)) ((uint32_t *) func_ptr))(); ((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB) { } else if (hook_type == WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB) {
((void (*)(void)) ((uint32_t *) func_ptr))(); ((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_INIT_WUT_NEWLIB) { } else if (hook_type == WUPS_LOADER_HOOK_INIT_WUT_NEWLIB) {
((void (*)(void)) ((uint32_t *) func_ptr))(); ((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_FINI_WUT_NEWLIB) { } else if (hook_type == WUPS_LOADER_HOOK_FINI_WUT_NEWLIB) {
((void (*)(void)) ((uint32_t *) func_ptr))(); ((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_INIT_WUT_STDCPP) { } else if (hook_type == WUPS_LOADER_HOOK_INIT_WUT_STDCPP) {
((void (*)(void)) ((uint32_t *) func_ptr))(); ((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_FINI_WUT_STDCPP) { } else if (hook_type == WUPS_LOADER_HOOK_FINI_WUT_STDCPP) {
((void (*)(void)) ((uint32_t *) func_ptr))(); ((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_RELEASE_FOREGROUND) { } else if (hook_type == WUPS_LOADER_HOOK_RELEASE_FOREGROUND) {
((void (*)(void)) ((uint32_t *) func_ptr))(); ((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND) { } else if (hook_type == WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND) {
((void (*)(void)) ((uint32_t *) func_ptr))(); ((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_VSYNC) { } else if (hook_type == WUPS_LOADER_HOOK_VSYNC) {
((void (*)(void)) ((uint32_t *) func_ptr))(); ((void (*)()) ((uint32_t *) func_ptr))();
} else { } else {
DEBUG_FUNCTION_LINE("######################################"); DEBUG_FUNCTION_LINE("######################################");
DEBUG_FUNCTION_LINE("Hook is not implemented %s [%d]", hook_names[hook_type], hook_type); DEBUG_FUNCTION_LINE("Hook is not implemented %s [%d]", hook_names[hook_type], hook_type);

View File

@ -1,34 +1,28 @@
#include <whb/log.h>
#include <whb/log_udp.h> #include <whb/log_udp.h>
#include <wums.h>
#include <coreinit/debug.h> #include <coreinit/debug.h>
#include <coreinit/memexpheap.h>
#include <coreinit/cache.h> #include <coreinit/cache.h>
#include "plugin/PluginDataFactory.h" #include "plugin/PluginContainer.h"
#include "plugin/PluginContainerPersistence.h"
#include "plugin/PluginInformationFactory.h"
#include "plugin/PluginMetaInformationFactory.h"
#include "utils/utils.h"
#include "PluginManagement.h"
#include "globals.h" #include "globals.h"
#include <whb/sdcard.h> #include "plugin/PluginDataFactory.h"
#include <utils/exports.h> #include "plugin/PluginDataPersistence.h"
#include <wums/defines/module_defines.h> #include "plugin/PluginContainerPersistence.h"
#include <plugin/PluginDataPersistence.h> #include "PluginManagement.h"
#include "utils/logger.h"
WUMS_MODULE_EXPORT_NAME("homebrew_wupsbackend"); WUMS_MODULE_EXPORT_NAME("homebrew_wupsbackend");
std::vector<PluginContainer> loadPlugins(const std::vector<PluginData> &pluginList, MEMHeapHandle heapHandle); std::vector<PluginContainer> loadPlugins(const std::vector<PluginData> &pluginList, MEMHeapHandle heapHandle);
module_information_t *gModuleData = NULL;
WUMS_INITIALIZE(args) { WUMS_INITIALIZE(args) {
__init_wut(); __init_wut();
WHBLogUdpInit(); WHBLogUdpInit();
gModuleData = args.module_information; gModuleData = args.module_information;
if(gModuleData == NULL){ if (gModuleData == nullptr) {
OSFatal("WUPS-Backend: Failed to get gModuleData pointer."); OSFatal("WUPS-Backend: Failed to get gModuleData pointer.");
} }
if(gModuleData->version != MODULE_INFORMATION_VERSION){ if (gModuleData->version != MODULE_INFORMATION_VERSION) {
OSFatal("WUPS-Backend: The module information struct version does not match."); OSFatal("WUPS-Backend: The module information struct version does not match.");
} }
WHBLogPrintf("Init successful"); WHBLogPrintf("Init successful");
@ -43,8 +37,7 @@ WUMS_APPLICATION_STARTS() {
return; return;
} }
bool initNeeded = false; bool initNeeded = false;
if (pluginDataHeap == NULL) { if (pluginDataHeap == nullptr) {
DEBUG_FUNCTION_LINE("gModuleData = %08X", gModuleData); DEBUG_FUNCTION_LINE("gModuleData = %08X", gModuleData);
DCFlushRange((void *) gModuleData, sizeof(module_information_t)); DCFlushRange((void *) gModuleData, sizeof(module_information_t));
uint32_t endAddress = 0; uint32_t endAddress = 0;

View File

@ -1,14 +1,13 @@
#include "utils/logger.h"
#include "hooks_patcher_static.h" #include "hooks_patcher_static.h"
#include <malloc.h> #include <malloc.h>
#include <wups.h> #include <wups.h>
#include <vpad/input.h> #include <vpad/input.h>
#include <coreinit/messagequeue.h> #include <coreinit/messagequeue.h>
#include <coreinit/core.h> #include <coreinit/core.h>
#include <globals.h>
#include "hooks.h"
extern plugin_information_t *gPluginInformation; #include "../utils/logger.h"
#include "../globals.h"
#include "../hooks.h"
DECL_FUNCTION(void, GX2WaitForVsync, void) { DECL_FUNCTION(void, GX2WaitForVsync, void) {
CallHook(gPluginInformation, WUPS_LOADER_HOOK_VSYNC); CallHook(gPluginInformation, WUPS_LOADER_HOOK_VSYNC);
@ -251,7 +250,7 @@ static uint32_t lastData0 = 0;
DECL_FUNCTION(uint32_t, OSReceiveMessage, OSMessageQueue *queue, OSMessage *message, uint32_t flags) { DECL_FUNCTION(uint32_t, OSReceiveMessage, OSMessageQueue *queue, OSMessage *message, uint32_t flags) {
int32_t res = real_OSReceiveMessage(queue, message, flags); int32_t res = real_OSReceiveMessage(queue, message, flags);
if (queue == OSGetSystemMessageQueue()) { if (queue == OSGetSystemMessageQueue()) {
if (message != NULL && res) { if (message != nullptr && res) {
if (lastData0 != message->args[0]) { if (lastData0 != message->args[0]) {
if (message->args[0] == 0xFACEF000) { if (message->args[0] == 0xFACEF000) {
CallHook(gPluginInformation, WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND); CallHook(gPluginInformation, WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND);

View File

@ -1,25 +1,21 @@
#include "DynamicLinkingHelper.h" #include "DynamicLinkingHelper.h"
#include <stdio.h> #include <cstring>
#include <string.h> #include "../utils/logger.h"
#include <vector>
#include <coreinit/dynload.h>
#include "utils/logger.h"
#include "common/plugin_defines.h"
dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_linking_relocation_data_t *data, const char *functionName) { dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_linking_relocation_data_t *data, const char *functionName) {
if (data == NULL) { if (data == nullptr) {
return NULL; return nullptr;
} }
if (functionName == NULL) { if (functionName == nullptr) {
return NULL; return nullptr;
} }
dyn_linking_function_t *result = NULL; dyn_linking_function_t *result = nullptr;
for (int32_t i = 0; i < DYN_LINK_FUNCTION_LIST_LENGTH; i++) { for (int32_t i = 0; i < DYN_LINK_FUNCTION_LIST_LENGTH; i++) {
dyn_linking_function_t *curEntry = &(data->functions[i]); dyn_linking_function_t *curEntry = &(data->functions[i]);
if (strlen(curEntry->functionName) == 0) { if (strlen(curEntry->functionName) == 0) {
if (strlen(functionName) > DYN_LINK_FUNCTION_NAME_LENGTH) { if (strlen(functionName) > DYN_LINK_FUNCTION_NAME_LENGTH) {
DEBUG_FUNCTION_LINE("Failed to add function name, it's too long.\n"); DEBUG_FUNCTION_LINE("Failed to add function name, it's too long.\n");
return NULL; return nullptr;
} }
strncpy(curEntry->functionName, functionName, DYN_LINK_FUNCTION_NAME_LENGTH); strncpy(curEntry->functionName, functionName, DYN_LINK_FUNCTION_NAME_LENGTH);
result = curEntry; result = curEntry;
@ -42,16 +38,16 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddDataImportByName(dyn_linking
} }
dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocation_data_t *data, const char *importName, bool isData) { dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocation_data_t *data, const char *importName, bool isData) {
if (importName == NULL || data == NULL) { if (importName == nullptr || data == nullptr) {
return NULL; return nullptr;
} }
dyn_linking_import_t *result = NULL; dyn_linking_import_t *result = nullptr;
for (int32_t i = 0; i < DYN_LINK_IMPORT_LIST_LENGTH; i++) { for (int32_t i = 0; i < DYN_LINK_IMPORT_LIST_LENGTH; i++) {
dyn_linking_import_t *curEntry = &(data->imports[i]); dyn_linking_import_t *curEntry = &(data->imports[i]);
if (strlen(curEntry->importName) == 0) { if (strlen(curEntry->importName) == 0) {
if (strlen(importName) > DYN_LINK_IMPORT_NAME_LENGTH) { if (strlen(importName) > DYN_LINK_IMPORT_NAME_LENGTH) {
DEBUG_FUNCTION_LINE("Failed to add Import, it's too long.\n"); DEBUG_FUNCTION_LINE("Failed to add Import, it's too long.\n");
return NULL; return nullptr;
} }
strncpy(curEntry->importName, importName, DYN_LINK_IMPORT_NAME_LENGTH); strncpy(curEntry->importName, importName, DYN_LINK_IMPORT_NAME_LENGTH);
curEntry->isData = isData; curEntry->isData = isData;
@ -73,13 +69,13 @@ bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *link
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) { const std::string &name, const ImportRPLInformation &rplInfo) {
dyn_linking_import_t *importInfoGbl = DynamicLinkingHelper::getOrAddImport(linking_data, rplInfo.getName().c_str(), rplInfo.isData()); dyn_linking_import_t *importInfoGbl = DynamicLinkingHelper::getOrAddImport(linking_data, rplInfo.getName().c_str(), rplInfo.isData());
if (importInfoGbl == NULL) { if (importInfoGbl == nullptr) {
DEBUG_FUNCTION_LINE("Getting import info failed. Probably maximum of %d rpl files to import reached.\n", DYN_LINK_IMPORT_LIST_LENGTH); DEBUG_FUNCTION_LINE("Getting import info failed. Probably maximum of %d rpl files to import reached.\n", DYN_LINK_IMPORT_LIST_LENGTH);
return false; return false;
} }
dyn_linking_function_t *functionInfo = DynamicLinkingHelper::getOrAddFunctionEntryByName(linking_data, name.c_str()); dyn_linking_function_t *functionInfo = DynamicLinkingHelper::getOrAddFunctionEntryByName(linking_data, name.c_str());
if (functionInfo == NULL) { if (functionInfo == nullptr) {
DEBUG_FUNCTION_LINE("Getting import info failed. Probably maximum of %d function to be relocated reached.\n", DYN_LINK_FUNCTION_LIST_LENGTH); DEBUG_FUNCTION_LINE("Getting import info failed. Probably maximum of %d function to be relocated reached.\n", DYN_LINK_FUNCTION_LIST_LENGTH);
return false; return false;
} }
@ -91,7 +87,7 @@ bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_entry_t *lin
dyn_linking_import_t *importInfo) { dyn_linking_import_t *importInfo) {
for (uint32_t i = 0; i < linking_entry_length; i++) { for (uint32_t i = 0; i < linking_entry_length; i++) {
dyn_linking_relocation_entry_t *curEntry = &(linking_entries[i]); dyn_linking_relocation_entry_t *curEntry = &(linking_entries[i]);
if (curEntry->functionEntry != NULL) { if (curEntry->functionEntry != nullptr) {
continue; continue;
} }
curEntry->type = type; curEntry->type = type;

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <wums/defines/dynamic_linking_defines.h> #include <wums/defines/dynamic_linking_defines.h>
#include "utils/logger.h"
#include <string> #include <string>
#include <vector> #include <vector>
#include "RelocationData.h" #include "RelocationData.h"
@ -57,9 +56,7 @@ public:
dyn_linking_import_t *importInfo); dyn_linking_import_t *importInfo);
private: private:
DynamicLinkingHelper() { DynamicLinkingHelper() = default;
}
~DynamicLinkingHelper() { ~DynamicLinkingHelper() = default;
}
}; };

View File

@ -33,45 +33,43 @@ public:
this->replaceCall = replaceCall; this->replaceCall = replaceCall;
} }
~FunctionData() { ~FunctionData() = default;
} [[nodiscard]] const std::string &getName() const {
const std::string &getName() const {
return this->name; return this->name;
} }
function_replacement_library_type_t getLibrary() const { [[nodiscard]] function_replacement_library_type_t getLibrary() const {
return this->library; return this->library;
} }
const void *getPhysicalAddress() const { [[nodiscard]] const void *getPhysicalAddress() const {
return paddress; return paddress;
} }
const void *getVirtualAddress() const { [[nodiscard]] const void *getVirtualAddress() const {
return vaddress; return vaddress;
} }
const void *getReplaceAddress() const { [[nodiscard]] const void *getReplaceAddress() const {
return replaceAddr; return replaceAddr;
} }
const void *getReplaceCall() const { [[nodiscard]] const void *getReplaceCall() const {
return replaceCall; return replaceCall;
} }
const FunctionPatcherTargetProcess getTargetProcess() const { [[nodiscard]] FunctionPatcherTargetProcess getTargetProcess() const {
return targetProcess; return targetProcess;
} }
private: private:
void *paddress = NULL; void *paddress = nullptr;
void *vaddress = NULL; void *vaddress = nullptr;
std::string name; std::string name;
function_replacement_library_type_t library; function_replacement_library_type_t library;
FunctionPatcherTargetProcess targetProcess; FunctionPatcherTargetProcess targetProcess;
void *replaceAddr = NULL; void *replaceAddr = nullptr;
void *replaceCall = NULL; void *replaceCall = nullptr;
}; };

View File

@ -28,15 +28,13 @@ public:
this->type = type; this->type = type;
} }
~HookData() { ~HookData() = default;
} [[nodiscard]] void *getFunctionPointer() const {
void *getFunctionPointer() const {
return function_pointer; return function_pointer;
} }
wups_loader_hook_type_t getType() const { [[nodiscard]] wups_loader_hook_type_t getType() const {
return this->type; return this->type;
} }

View File

@ -18,24 +18,23 @@
#pragma once #pragma once
#include <string> #include <string>
#include "utils/logger.h" #include "../utils/logger.h"
class ImportRPLInformation { class ImportRPLInformation {
public: public:
ImportRPLInformation(std::string name, bool isData = false) { explicit ImportRPLInformation(std::string name, bool isData = false) {
this->name = name; this->name = name;
this->_isData = isData; this->_isData = isData;
} }
~ImportRPLInformation() { ~ImportRPLInformation() = default;
}
std::string getName() const { [[nodiscard]] std::string getName() const {
return name; return name;
} }
bool isData() const { [[nodiscard]] bool isData() const {
return _isData; return _isData;
} }

View File

@ -29,11 +29,9 @@ public:
this->metaInformation = other.metaInformation; this->metaInformation = other.metaInformation;
} }
PluginContainer() { PluginContainer() = default;
} [[nodiscard]] const PluginMetaInformation &getMetaInformation() const {
const PluginMetaInformation &getMetaInformation() const {
return this->metaInformation; return this->metaInformation;
} }
@ -41,20 +39,20 @@ public:
this->metaInformation = metaInfo; this->metaInformation = metaInfo;
} }
const PluginInformation &getPluginInformation() const { [[nodiscard]] const PluginInformation &getPluginInformation() const {
return pluginInformation; return pluginInformation;
} }
void setPluginInformation(const PluginInformation &pluginInformation) { void setPluginInformation(const PluginInformation &_pluginInformation) {
this->pluginInformation = pluginInformation; this->pluginInformation = _pluginInformation;
} }
const PluginData &getPluginData() const { [[nodiscard]] const PluginData &getPluginData() const {
return pluginData; return pluginData;
} }
void setPluginData(const PluginData &pluginData) { void setPluginData(const PluginData &_pluginData) {
this->pluginData = pluginData; this->pluginData = _pluginData;
} }
PluginData pluginData; PluginData pluginData;

View File

@ -6,7 +6,7 @@
#include "PluginContainerPersistence.h" #include "PluginContainerPersistence.h"
#include "PluginDataPersistence.h" #include "PluginDataPersistence.h"
#include "DynamicLinkingHelper.h" #include "DynamicLinkingHelper.h"
#include "common/plugin_defines.h" #include "../common/plugin_defines.h"
#include "PluginInformation.h" #include "PluginInformation.h"
#include "RelocationData.h" #include "RelocationData.h"
@ -28,7 +28,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
//plugin_data = {}; //plugin_data = {};
memset((void *) plugin_data, 0, sizeof(plugin_information_single_t)); memset((void *) plugin_data, 0, sizeof(plugin_information_single_t));
auto pluginMetaInfo = plugin.getMetaInformation(); 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) { if (pluginMetaInfo.getName().size() >= MAXIMUM_PLUGIN_META_FIELD_LENGTH) {
@ -180,7 +180,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
std::vector<PluginContainer> PluginContainerPersistence::loadPlugins(plugin_information_t *pluginInformation) { std::vector<PluginContainer> PluginContainerPersistence::loadPlugins(plugin_information_t *pluginInformation) {
std::vector<PluginContainer> result; std::vector<PluginContainer> result;
if (pluginInformation == NULL) { if (pluginInformation == nullptr) {
DEBUG_FUNCTION_LINE("pluginInformation == NULL"); DEBUG_FUNCTION_LINE("pluginInformation == NULL");
return result; return result;
} }
@ -211,19 +211,20 @@ std::vector<PluginContainer> PluginContainerPersistence::loadPlugins(plugin_info
PluginData pluginData = PluginDataPersistence::load(data); PluginData pluginData = PluginDataPersistence::load(data);
PluginInformation pluginInformation; PluginInformation curPluginInformation;
pluginInformation.setTrampolinId(plugin_data->info.trampolinId); curPluginInformation.setTrampolinId(plugin_data->info.trampolinId);
pluginInformation.allocatedTextMemoryAddress = plugin_data->info.allocatedTextMemoryAddress; curPluginInformation.allocatedTextMemoryAddress = plugin_data->info.allocatedTextMemoryAddress;
pluginInformation.allocatedDataMemoryAddress = plugin_data->info.allocatedDataMemoryAddress; curPluginInformation.allocatedDataMemoryAddress = plugin_data->info.allocatedDataMemoryAddress;
for (uint32_t i = 0; i < MAXIMUM_PLUGIN_SECTION_LENGTH; i++) { for (auto & curItem : plugin_data->info.sectionInfos) {
plugin_section_info_t *sectionInfo = &(plugin_data->info.sectionInfos[i]); plugin_section_info_t *sectionInfo = &curItem;
if (sectionInfo->addr == 0 && sectionInfo->size == 0) { if (sectionInfo->addr == 0 && sectionInfo->size == 0) {
continue; continue;
} }
DEBUG_FUNCTION_LINE("Add SectionInfo %s", sectionInfo->name); DEBUG_FUNCTION_LINE("Add SectionInfo %s", sectionInfo->name);
pluginInformation.addSectionInfo(SectionInfo(sectionInfo->name, sectionInfo->addr, sectionInfo->size)); std::string name(sectionInfo->name);
curPluginInformation.addSectionInfo(SectionInfo(name, sectionInfo->addr, sectionInfo->size));
} }
/* load hook data */ /* load hook data */
@ -237,7 +238,7 @@ std::vector<PluginContainer> PluginContainerPersistence::loadPlugins(plugin_info
for (uint32_t j = 0; j < hookCount; j++) { for (uint32_t j = 0; j < hookCount; j++) {
replacement_data_hook_t *hook_entry = &(plugin_data->info.hooks[j]); replacement_data_hook_t *hook_entry = &(plugin_data->info.hooks[j]);
HookData curHook(hook_entry->func_pointer, hook_entry->type); HookData curHook(hook_entry->func_pointer, hook_entry->type);
pluginInformation.addHookData(curHook); curPluginInformation.addHookData(curHook);
} }
/* load function replacement data */ /* load function replacement data */
@ -251,43 +252,44 @@ std::vector<PluginContainer> PluginContainerPersistence::loadPlugins(plugin_info
for (uint32_t j = 0; j < functionReplaceCount; j++) { for (uint32_t j = 0; j < functionReplaceCount; j++) {
function_replacement_data_t *entry = &(plugin_data->info.functions[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);
pluginInformation.addFunctionData(func); curPluginInformation.addFunctionData(func);
} }
/* load relocation data */ /* load relocation data */
for (uint32_t j = 0; j < PLUGIN_DYN_LINK_RELOCATION_LIST_LENGTH; j++) { for (auto & linking_entrie : plugin_data->info.linking_entries) {
dyn_linking_relocation_entry_t *linking_entry = &(plugin_data->info.linking_entries[j]); dyn_linking_relocation_entry_t *linking_entry = &linking_entrie;
if (linking_entry->destination == NULL) { if (linking_entry->destination == nullptr) {
break; break;
} }
dyn_linking_import_t *importEntry = linking_entry->importEntry; dyn_linking_import_t *importEntry = linking_entry->importEntry;
if (importEntry == NULL) { if (importEntry == nullptr) {
DEBUG_FUNCTION_LINE("importEntry was NULL, skipping relocation entry"); DEBUG_FUNCTION_LINE("importEntry was NULL, skipping relocation entry");
continue; continue;
} }
if (importEntry->importName == NULL) { if (importEntry->importName == nullptr) {
DEBUG_FUNCTION_LINE("importEntry->importName was NULL, skipping relocation entry"); DEBUG_FUNCTION_LINE("importEntry->importName was NULL, skipping relocation entry");
continue; 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"); DEBUG_FUNCTION_LINE("functionEntry was NULL, skipping relocation entry");
continue; continue;
} }
if (functionEntry->functionName == NULL) { if (functionEntry->functionName == nullptr) {
DEBUG_FUNCTION_LINE("functionEntry->functionName was NULL, skipping relocation entry"); DEBUG_FUNCTION_LINE("functionEntry->functionName was NULL, skipping relocation entry");
continue; continue;
} }
ImportRPLInformation rplInfo(importEntry->importName, importEntry->isData); ImportRPLInformation rplInfo(importEntry->importName, importEntry->isData);
RelocationData reloc(linking_entry->type, linking_entry->offset, linking_entry->addend, linking_entry->destination, functionEntry->functionName, rplInfo); std::string functionName(functionEntry->functionName);
pluginInformation.addRelocationData(reloc); RelocationData reloc(linking_entry->type, linking_entry->offset, linking_entry->addend, linking_entry->destination, functionName, rplInfo);
curPluginInformation.addRelocationData(reloc);
} }
PluginContainer container; PluginContainer container;
container.setMetaInformation(metaInformation); container.setMetaInformation(metaInformation);
container.setPluginData(pluginData); container.setPluginData(pluginData);
container.setPluginInformation(pluginInformation); container.setPluginInformation(curPluginInformation);
result.push_back(container); result.push_back(container);
} }
return result; return result;

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "common/plugin_defines.h" #include "../common/plugin_defines.h"
#include "PluginContainer.h" #include "PluginContainer.h"
class PluginContainerPersistence { class PluginContainerPersistence {
@ -8,6 +8,4 @@ public:
static bool savePlugin(plugin_information_t *pluginInformation, PluginContainer &plugin); static bool savePlugin(plugin_information_t *pluginInformation, PluginContainer &plugin);
static std::vector<PluginContainer> loadPlugins(plugin_information_t *pluginInformation); static std::vector<PluginContainer> loadPlugins(plugin_information_t *pluginInformation);
static bool savePluginData(plugin_data_t *pluginDataStruct, PluginData &plugin);
}; };

View File

@ -1,5 +1,8 @@
#include "PluginData.h" #include "PluginData.h"
#include <utility>
#include <malloc.h>
#include "../utils/logger.h"
PluginData::PluginData(const PluginData &obj) { PluginData::PluginData(const PluginData &obj) {
this->buffer = obj.buffer; this->buffer = obj.buffer;
@ -9,7 +12,7 @@ PluginData::PluginData(const PluginData &obj) {
} }
void PluginData::freeMemory() { void PluginData::freeMemory() {
if (buffer == NULL) { if (buffer == nullptr) {
return; return;
} }
@ -17,29 +20,29 @@ void PluginData::freeMemory() {
default: default:
case eMemTypeExpHeap: case eMemTypeExpHeap:
MEMFreeToExpHeap(this->heapHandle, buffer); MEMFreeToExpHeap(this->heapHandle, buffer);
this->buffer = NULL; this->buffer = nullptr;
break; break;
case eMemTypeMEM2: case eMemTypeMEM2:
free(this->buffer); free(this->buffer);
this->buffer = NULL; this->buffer = nullptr;
break; break;
} }
} }
PluginData::PluginData(std::vector<uint8_t> buffer) : PluginData(buffer, 0, eMemTypeMEM2) { PluginData::PluginData(const std::vector<uint8_t>& buffer) : PluginData(buffer, nullptr, eMemTypeMEM2) {
} }
PluginData::PluginData(std::vector<uint8_t> input, MEMHeapHandle heapHandle, eMemoryTypes memoryType) : PluginData::PluginData(const std::vector<uint8_t>& input, MEMHeapHandle heapHandle, eMemoryTypes memoryType) :
heapHandle(heapHandle), heapHandle(heapHandle),
memoryType(memoryType), memoryType(memoryType),
length(input.size()) { length(input.size()) {
void *data_copy = NULL; void *data_copy = nullptr;
switch (memoryType) { switch (memoryType) {
default: default:
case eMemTypeExpHeap: case eMemTypeExpHeap:
data_copy = MEMAllocFromExpHeapEx(heapHandle, length, 4); data_copy = MEMAllocFromExpHeapEx(heapHandle, length, 4);
DEBUG_FUNCTION_LINE("Allocated %d kb from ExpHeap", length / 1024); DEBUG_FUNCTION_LINE("Allocated %d kb from ExpHeap", length / 1024);
if (data_copy == NULL) { if (data_copy == nullptr) {
DEBUG_FUNCTION_LINE("Failed to allocate space on exp heap"); DEBUG_FUNCTION_LINE("Failed to allocate space on exp heap");
} else { } else {
memcpy(data_copy, &input[0], length); memcpy(data_copy, &input[0], length);
@ -49,7 +52,7 @@ PluginData::PluginData(std::vector<uint8_t> input, MEMHeapHandle heapHandle, eMe
break; break;
case eMemTypeMEM2: case eMemTypeMEM2:
data_copy = memalign(length, 4); data_copy = memalign(length, 4);
if (data_copy == NULL) { if (data_copy == nullptr) {
DEBUG_FUNCTION_LINE("Failed to allocate space on default heap"); DEBUG_FUNCTION_LINE("Failed to allocate space on default heap");
} else { } else {
memcpy(data_copy, &input[0], length); memcpy(data_copy, &input[0], length);
@ -57,8 +60,4 @@ PluginData::PluginData(std::vector<uint8_t> input, MEMHeapHandle heapHandle, eMe
this->buffer = data_copy; this->buffer = data_copy;
break; break;
} }
} }
std::optional<PluginData> PluginData::createFromExistingData(const void *buffer, MEMHeapHandle heapHandle, eMemoryTypes memoryType, const size_t length) {
return std::nullopt;
}

View File

@ -22,7 +22,7 @@
#include <malloc.h> #include <malloc.h>
#include <coreinit/memexpheap.h> #include <coreinit/memexpheap.h>
#include "elfio/elfio.hpp" #include "../elfio/elfio.hpp"
using namespace ELFIO; using namespace ELFIO;
@ -33,28 +33,23 @@ enum eMemoryTypes {
class PluginData { class PluginData {
public: public:
~PluginData() { ~PluginData() = default;
}
void freeMemory(); void freeMemory();
PluginData(const PluginData &obj); PluginData(const PluginData &obj);
PluginData() { PluginData() = default;
}
void *buffer = NULL; void *buffer = nullptr;
MEMHeapHandle heapHandle; MEMHeapHandle heapHandle{};
eMemoryTypes memoryType; eMemoryTypes memoryType;
size_t length = 0; size_t length = 0;
private: private:
PluginData(std::vector<uint8_t> buffer); explicit PluginData(const std::vector<uint8_t> &buffer);
PluginData(std::vector<uint8_t> input, MEMHeapHandle heapHandle, eMemoryTypes memoryType);
static std::optional<PluginData> createFromExistingData(const void *buffer, MEMHeapHandle heapHandle, eMemoryTypes memoryType, const size_t length);
PluginData(const std::vector<uint8_t>& input, MEMHeapHandle heapHandle, eMemoryTypes memoryType);
friend class PluginDataFactory; friend class PluginDataFactory;

View File

@ -15,32 +15,30 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <dirent.h> #include <dirent.h>
#include "PluginDataFactory.h" #include "PluginDataFactory.h"
#include "utils/logger.h" #include "../utils/logger.h"
#include "utils/StringTools.h" #include "../utils/StringTools.h"
std::vector<PluginData> PluginDataFactory::loadDir(const std::string &path, MEMHeapHandle heapHandle) { std::vector<PluginData> PluginDataFactory::loadDir(const std::string &path, MEMHeapHandle heapHandle) {
std::vector<PluginData> result; std::vector<PluginData> result;
struct dirent *dp; struct dirent *dp;
DIR *dfd = NULL; DIR *dfd = nullptr;
if (path.empty()) { if (path.empty()) {
DEBUG_FUNCTION_LINE("Path was empty\n"); DEBUG_FUNCTION_LINE("Path was empty\n");
return result; return result;
} }
if ((dfd = opendir(path.c_str())) == NULL) { if ((dfd = opendir(path.c_str())) == nullptr) {
DEBUG_FUNCTION_LINE("Couldn't open dir %s\n", path.c_str()); DEBUG_FUNCTION_LINE("Couldn't open dir %s\n", path.c_str());
return result; return result;
} }
while ((dp = readdir(dfd)) != NULL) { 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); std::string full_file_path = StringTools::strfmt("%s/%s", path.c_str(), dp->d_name);
StringTools::RemoveDoubleSlashs(full_file_path); StringTools::RemoveDoubleSlashs(full_file_path);
if (stat(full_file_path.c_str(), &stbuf) == -1) { if (stat(full_file_path.c_str(), &stbuf) == -1) {
@ -58,7 +56,7 @@ std::vector<PluginData> PluginDataFactory::loadDir(const std::string &path, MEMH
} }
} }
} }
if (dfd != NULL) { if (dfd != nullptr) {
closedir(dfd); closedir(dfd);
} }

View File

@ -1,9 +1,9 @@
#include <common/plugin_defines.h> #include "../common/plugin_defines.h"
#include "PluginDataPersistence.h" #include "PluginDataPersistence.h"
#include "PluginData.h" #include "PluginData.h"
bool PluginDataPersistence::save(plugin_data_t *pluginDataStruct, PluginData &plugin) { bool PluginDataPersistence::save(plugin_data_t *pluginDataStruct, PluginData &plugin) {
if (pluginDataStruct == NULL) { if (pluginDataStruct == nullptr) {
return false; return false;
} }
pluginDataStruct->buffer = (char *) plugin.buffer; pluginDataStruct->buffer = (char *) plugin.buffer;

View File

@ -1,14 +1,14 @@
#include "PluginInformation.h" #include "PluginInformation.h"
PluginInformation::PluginInformation(const PluginInformation &other) { PluginInformation::PluginInformation(const PluginInformation &other) {
for (size_t i = 0; i < other.hook_data_list.size(); i++) { for (const auto &i : other.hook_data_list) {
hook_data_list.push_back(other.hook_data_list[i]); hook_data_list.push_back(i);
} }
for (size_t i = 0; i < other.function_data_list.size(); i++) { for (const auto &i : other.function_data_list) {
function_data_list.push_back(other.function_data_list[i]); function_data_list.push_back(i);
} }
for (size_t i = 0; i < other.relocation_data_list.size(); i++) { for (const auto &i : other.relocation_data_list) {
relocation_data_list.push_back(other.relocation_data_list[i]); relocation_data_list.push_back(i);
} }
section_info_list = other.section_info_list; section_info_list = other.section_info_list;
trampolinId = other.trampolinId; trampolinId = other.trampolinId;

View File

@ -31,17 +31,15 @@ class PluginInformation {
public: public:
PluginInformation(const PluginInformation &other); PluginInformation(const PluginInformation &other);
PluginInformation() { PluginInformation() = default;
}
virtual ~PluginInformation() { virtual ~PluginInformation() = default;
}
void addHookData(const HookData &hook_data) { void addHookData(const HookData &hook_data) {
hook_data_list.push_back(hook_data); hook_data_list.push_back(hook_data);
} }
const std::vector<HookData> &getHookDataList() const { [[nodiscard]] const std::vector<HookData> &getHookDataList() const {
return hook_data_list; return hook_data_list;
} }
@ -49,7 +47,7 @@ public:
function_data_list.push_back(function_data); function_data_list.push_back(function_data);
} }
const std::vector<FunctionData> &getFunctionDataList() const { [[nodiscard]] const std::vector<FunctionData> &getFunctionDataList() const {
return function_data_list; return function_data_list;
} }
@ -57,7 +55,7 @@ public:
relocation_data_list.push_back(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; return relocation_data_list;
} }
@ -65,27 +63,26 @@ public:
section_info_list[sectionInfo.getName()] = sectionInfo; 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; 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) { if (getSectionInfoList().count(sectionName) > 0) {
return section_info_list.at(sectionName); return section_info_list.at(sectionName);
} }
return std::nullopt; return std::nullopt;
} }
void setTrampolinId(uint8_t trampolinId) { void setTrampolinId(uint8_t _trampolinId) {
this->trampolinId = trampolinId; this->trampolinId = _trampolinId;
} }
uint8_t getTrampolinId() const { [[nodiscard]] uint8_t getTrampolinId() const {
return trampolinId; return trampolinId;
} }
private: private:
std::vector<HookData> hook_data_list; std::vector<HookData> hook_data_list;
std::vector<FunctionData> function_data_list; std::vector<FunctionData> function_data_list;
std::vector<RelocationData> relocation_data_list; std::vector<RelocationData> relocation_data_list;
@ -93,8 +90,8 @@ private:
uint8_t trampolinId = 0; uint8_t trampolinId = 0;
void *allocatedTextMemoryAddress = 0; void *allocatedTextMemoryAddress = nullptr;
void *allocatedDataMemoryAddress = 0; void *allocatedDataMemoryAddress = nullptr;
friend class PluginInformationFactory; friend class PluginInformationFactory;

View File

@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* Copyright (C) 2018 Maschell * Copyright (C) 2018-2020 Maschell
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -26,20 +26,20 @@
#include "PluginInformationFactory.h" #include "PluginInformationFactory.h"
#include "HookData.h" #include "HookData.h"
#include "SectionInfo.h" #include "SectionInfo.h"
#include "elfio/elfio.hpp" #include "../elfio/elfio.hpp"
#include "utils/utils.h" #include "../utils/utils.h"
#include "utils/ElfUtils.h" #include "../utils/ElfUtils.h"
#include "utils/StringTools.h" #include "../utils/StringTools.h"
using namespace ELFIO; 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 == NULL){ if (pluginData.buffer == nullptr) {
DEBUG_FUNCTION_LINE("Buffer was NULL"); DEBUG_FUNCTION_LINE("Buffer was NULL");
return std::nullopt; return std::nullopt;
} }
elfio reader; elfio reader;
if (! reader.load((char*) pluginData.buffer, pluginData.length)) { if (!reader.load((char *) pluginData.buffer, pluginData.length)) {
DEBUG_FUNCTION_LINE("Can't process PluginData in elfio"); DEBUG_FUNCTION_LINE("Can't process PluginData in elfio");
return std::nullopt; return std::nullopt;
} }
@ -47,7 +47,7 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
PluginInformation pluginInfo; PluginInformation pluginInfo;
uint32_t sec_num = reader.sections.size(); uint32_t sec_num = reader.sections.size();
uint8_t **destinations = (uint8_t **) malloc(sizeof(uint8_t *) * sec_num); auto **destinations = (uint8_t **) malloc(sizeof(uint8_t *) * sec_num);
uint32_t totalSize = 0; uint32_t totalSize = 0;
@ -74,14 +74,14 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
} }
} }
void *text_data = MEMAllocFromExpHeapEx(heapHandle, text_size, 0x1000); void *text_data = MEMAllocFromExpHeapEx(heapHandle, text_size, 0x1000);
if (text_data == NULL) { if (text_data == nullptr) {
DEBUG_FUNCTION_LINE("Failed to alloc memory for the .text section (%d bytes)\n", text_size); DEBUG_FUNCTION_LINE("Failed to alloc memory for the .text section (%d bytes)\n", text_size);
return std::nullopt; return std::nullopt;
} }
DEBUG_FUNCTION_LINE("Allocated %d kb from ExpHeap", text_size / 1024); DEBUG_FUNCTION_LINE("Allocated %d kb from ExpHeap", text_size / 1024);
void *data_data = MEMAllocFromExpHeapEx(heapHandle, data_size, 0x1000); void *data_data = MEMAllocFromExpHeapEx(heapHandle, data_size, 0x1000);
if (data_data == NULL) { if (data_data == nullptr) {
DEBUG_FUNCTION_LINE("Failed to alloc memory for the .data section (%d bytes)\n", data_size); DEBUG_FUNCTION_LINE("Failed to alloc memory for the .data section (%d bytes)\n", data_size);
MEMFreeToExpHeap(heapHandle, text_data); MEMFreeToExpHeap(heapHandle, text_data);
@ -133,7 +133,8 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
memcpy((void *) destination, p, sectionSize); memcpy((void *) destination, p, sectionSize);
} }
pluginInfo.addSectionInfo(SectionInfo(psec->get_name(), destination, sectionSize)); std::string sectionName(psec->get_name());
pluginInfo.addSectionInfo(SectionInfo(sectionName, destination, sectionSize));
DEBUG_FUNCTION_LINE("Saved %s section info. Location: %08X size: %08X", psec->get_name().c_str(), destination, sectionSize); DEBUG_FUNCTION_LINE("Saved %s section info. Location: %08X size: %08X", psec->get_name().c_str(), destination, sectionSize);
totalSize += sectionSize; totalSize += sectionSize;
@ -177,8 +178,8 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
std::optional<SectionInfo> secInfo = pluginInfo.getSectionInfo(".wups.hooks"); std::optional<SectionInfo> secInfo = pluginInfo.getSectionInfo(".wups.hooks");
if (secInfo && secInfo->getSize() > 0) { if (secInfo && secInfo->getSize() > 0) {
size_t entries_count = secInfo->getSize() / sizeof(wups_loader_hook_t); size_t entries_count = secInfo->getSize() / sizeof(wups_loader_hook_t);
wups_loader_hook_t *entries = (wups_loader_hook_t *) secInfo->getAddress(); auto *entries = (wups_loader_hook_t *) secInfo->getAddress();
if (entries != NULL) { if (entries != nullptr) {
for (size_t j = 0; j < entries_count; j++) { for (size_t j = 0; j < entries_count; j++) {
wups_loader_hook_t *hook = &entries[j]; wups_loader_hook_t *hook = &entries[j];
DEBUG_FUNCTION_LINE("Saving hook of plugin Type: %08X, target: %08X"/*,pluginData.getPluginInformation()->getName().c_str()*/, hook->type, (void *) hook->target); DEBUG_FUNCTION_LINE("Saving hook of plugin Type: %08X, target: %08X"/*,pluginData.getPluginInformation()->getName().c_str()*/, hook->type, (void *) hook->target);
@ -191,7 +192,7 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
secInfo = pluginInfo.getSectionInfo(".wups.load"); secInfo = pluginInfo.getSectionInfo(".wups.load");
if (secInfo && secInfo->getSize() > 0) { if (secInfo && secInfo->getSize() > 0) {
size_t entries_count = secInfo->getSize() / sizeof(wups_loader_entry_t); size_t entries_count = secInfo->getSize() / sizeof(wups_loader_entry_t);
wups_loader_entry_t *entries = (wups_loader_entry_t *) secInfo->getAddress(); auto *entries = (wups_loader_entry_t *) secInfo->getAddress();
if (entries != NULL) { if (entries != NULL) {
for (size_t j = 0; j < entries_count; j++) { for (size_t j = 0; j < entries_count; j++) {
wups_loader_entry_t *cur_function = &entries[j]; wups_loader_entry_t *cur_function = &entries[j];

View File

@ -25,7 +25,7 @@
#include <wums/defines/relocation_defines.h> #include <wums/defines/relocation_defines.h>
#include "PluginInformation.h" #include "PluginInformation.h"
#include "PluginContainer.h" #include "PluginContainer.h"
#include "elfio/elfio.hpp" #include "../elfio/elfio.hpp"
class PluginInformationFactory { class PluginInformationFactory {
public: public:

View File

@ -24,64 +24,63 @@ class PluginMetaInformation {
public: public:
PluginMetaInformation(const PluginMetaInformation &other); PluginMetaInformation(const PluginMetaInformation &other);
const std::string getName() const { [[nodiscard]] std::string getName() const {
return name; return name;
} }
const std::string getAuthor() const { [[nodiscard]] std::string getAuthor() const {
return this->author; return this->author;
} }
const std::string getVersion() const { [[nodiscard]] std::string getVersion() const {
return this->version; return this->version;
} }
const std::string getLicense() const { [[nodiscard]] std::string getLicense() const {
return this->license; return this->license;
} }
const std::string getBuildTimestamp() const { [[nodiscard]] std::string getBuildTimestamp() const {
return this->buildtimestamp; return this->buildtimestamp;
} }
const std::string getDescription() const { [[nodiscard]] std::string getDescription() const {
return this->description; return this->description;
} }
const size_t getSize() const { [[nodiscard]] size_t getSize() const {
return this->size; return this->size;
} }
private: private:
PluginMetaInformation() { PluginMetaInformation() = default;
void setName(const std::string &_name) {
this->name = _name;
} }
void setName(const std::string &name) { void setAuthor(const std::string &_author) {
this->name = name; this->author = _author;
} }
void setAuthor(const std::string &author) { void setVersion(const std::string &_version) {
this->author = author; this->version = _version;
} }
void setVersion(const std::string &version) { void setLicense(const std::string &_license) {
this->version = version; this->license = _license;
} }
void setLicense(const std::string &license) { void setBuildTimestamp(const std::string &_buildtimestamp) {
this->license = license; this->buildtimestamp = _buildtimestamp;
} }
void setBuildTimestamp(const std::string &buildtimestamp) { void setDescription(const std::string &_description) {
this->buildtimestamp = buildtimestamp; this->description = _description;
} }
void setDescription(const std::string &description) { void setSize(size_t _size) {
this->description = description; this->size = _size;
}
void setSize(size_t size) {
this->size = size;
} }
std::string name; std::string name;
@ -90,7 +89,7 @@ private:
std::string license; std::string license;
std::string buildtimestamp; std::string buildtimestamp;
std::string description; std::string description;
size_t size; size_t size{};
friend class PluginMetaInformationFactory; friend class PluginMetaInformationFactory;

View File

@ -19,27 +19,28 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <dirent.h> #include <dirent.h>
#include <whb/file.h> #include <whb/file.h>
#include "utils/StringTools.h" #include "../utils/StringTools.h"
#include "PluginMetaInformationFactory.h" #include "PluginMetaInformationFactory.h"
#include "PluginMetaInformation.h" #include "PluginMetaInformation.h"
#include "elfio/elfio.hpp" #include "../elfio/elfio.hpp"
#include "../utils/logger.h"
using namespace ELFIO; using namespace ELFIO;
std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(const PluginData &pluginData) { std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(const PluginData &pluginData) {
if(pluginData.buffer == NULL){ if (pluginData.buffer == NULL) {
DEBUG_FUNCTION_LINE("Buffer was NULL"); DEBUG_FUNCTION_LINE("Buffer was NULL");
return std::nullopt; return std::nullopt;
} }
elfio reader; elfio reader;
if (! reader.load((char*) pluginData.buffer, pluginData.length)) { if (!reader.load((char *) pluginData.buffer, pluginData.length)) {
DEBUG_FUNCTION_LINE("Can't process PluginData in elfio"); DEBUG_FUNCTION_LINE("Can't process PluginData in elfio");
return std::nullopt; return std::nullopt;
} }
return loadPlugin(reader); return loadPlugin(reader);
} }
std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(const std::string filePath) { std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(std::string &filePath) {
elfio reader; elfio reader;
if (!reader.load(filePath)) { if (!reader.load(filePath)) {
DEBUG_FUNCTION_LINE("Can't find or process ELF file\n"); DEBUG_FUNCTION_LINE("Can't find or process ELF file\n");

View File

@ -27,7 +27,7 @@ class PluginMetaInformationFactory {
public: public:
static std::optional<PluginMetaInformation> loadPlugin(const PluginData &pluginData); static std::optional<PluginMetaInformation> loadPlugin(const PluginData &pluginData);
static std::optional<PluginMetaInformation> loadPlugin(const std::string filePath); static std::optional<PluginMetaInformation> loadPlugin(std::string &filePath);
static std::optional<PluginMetaInformation> loadPlugin(char *buffer, size_t size); static std::optional<PluginMetaInformation> loadPlugin(char *buffer, size_t size);

View File

@ -23,7 +23,7 @@
class RelocationData { class RelocationData {
public: public:
RelocationData(const char type, size_t offset, int32_t addend, void *destination, std::string name, ImportRPLInformation rplInfo) : RelocationData(const char type, size_t offset, int32_t addend, void *destination, std::string &name, const ImportRPLInformation &rplInfo) :
type(type), type(type),
offset(offset), offset(offset),
addend(addend), addend(addend),
@ -32,39 +32,31 @@ public:
rplInfo(rplInfo) { rplInfo(rplInfo) {
} }
RelocationData(const RelocationData &o2) : RelocationData(const RelocationData &o2) = default;
type(o2.type),
offset(o2.offset),
addend(o2.addend),
destination(o2.destination),
name(o2.name),
rplInfo(o2.rplInfo) {
}
virtual ~RelocationData() { virtual ~RelocationData() = default;
}
const char getType() const { [[nodiscard]] char getType() const {
return type; return type;
} }
const size_t getOffset() const { [[nodiscard]] size_t getOffset() const {
return offset; return offset;
} }
const int32_t getAddend() const { [[nodiscard]] int32_t getAddend() const {
return addend; return addend;
} }
const void *getDestination() const { [[nodiscard]] const void *getDestination() const {
return destination; return destination;
} }
const std::string &getName() const { [[nodiscard]] const std::string &getName() const {
return name; return name;
} }
const ImportRPLInformation &getImportRPLInformation() const { [[nodiscard]] const ImportRPLInformation &getImportRPLInformation() const {
return rplInfo; return rplInfo;
} }

View File

@ -22,40 +22,33 @@
class SectionInfo { class SectionInfo {
public: public:
SectionInfo(std::string name, uint32_t address, uint32_t sectionSize) : SectionInfo(std::string &name, uint32_t address, uint32_t sectionSize) :
name(name), name(name),
address(address), address(address),
sectionSize(sectionSize) { sectionSize(sectionSize) {
} }
SectionInfo() { SectionInfo() = default;
}
SectionInfo(const SectionInfo &o2) : SectionInfo(const SectionInfo &o2) = default;
name(o2.name),
address(o2.address),
sectionSize(o2.sectionSize) {
}
virtual ~SectionInfo() { virtual ~SectionInfo() = default;
} [[nodiscard]] const std::string &getName() const {
const std::string &getName() const {
return name; return name;
} }
const uint32_t getAddress() const { [[nodiscard]] uint32_t getAddress() const {
return address; return address;
} }
const uint32_t getSize() const { [[nodiscard]] uint32_t getSize() const {
return sectionSize; return sectionSize;
} }
private: private:
std::string name; std::string name;
uint32_t address; uint32_t address{};
uint32_t sectionSize; uint32_t sectionSize{};
}; };

View File

@ -1,11 +1,11 @@
#include <coreinit/cache.h> #include <coreinit/cache.h>
#include <plugin/PluginMetaInformationFactory.h> #include "../plugin/PluginMetaInformationFactory.h"
#include <plugin/PluginContainer.h> #include "../plugin/PluginContainer.h"
#include <plugin/PluginContainerPersistence.h> #include "../plugin/PluginContainerPersistence.h"
#include <plugin/PluginDataFactory.h> #include "../plugin/PluginDataFactory.h"
#include <PluginManagement.h> #include "../PluginManagement.h"
#include <globals.h> #include "../globals.h"
#include <plugin/PluginDataPersistence.h> #include "../plugin/PluginDataPersistence.h"
#include "exports.h" #include "exports.h"
#include <wums.h> #include <wums.h>
@ -19,7 +19,7 @@ void fillPluginInformation(plugin_information *out, PluginMetaInformation *metaI
out->size = metaInformation->getSize(); out->size = metaInformation->getSize();
} }
int32_t WUPSLoadAndLinkByDataHandle(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size) { extern "C" int32_t WUPSLoadAndLinkByDataHandle(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size) {
gLinkOnReload.number_used_plugins = 0; gLinkOnReload.number_used_plugins = 0;
if (plugin_data_handle_list != NULL && plugin_data_handle_list_size != 0) { if (plugin_data_handle_list != NULL && plugin_data_handle_list_size != 0) {
for (uint32_t i = 0; i < plugin_data_handle_list_size; i++) { for (uint32_t i = 0; i < plugin_data_handle_list_size; i++) {
@ -40,7 +40,7 @@ int32_t WUPSLoadAndLinkByDataHandle(const plugin_data_handle *plugin_data_handle
return ERROR_NONE; return ERROR_NONE;
} }
int32_t WUPSDeletePluginContainer(const plugin_container_handle *handle_list, uint32_t handle_list_size) { extern "C" int32_t WUPSDeletePluginContainer(const plugin_container_handle *handle_list, uint32_t handle_list_size) {
if (handle_list != NULL && handle_list_size != 0) { if (handle_list != NULL && handle_list_size != 0) {
for (uint32_t i = 0; i < handle_list_size; i++) { for (uint32_t i = 0; i < handle_list_size; i++) {
auto handle = handle_list[i]; auto handle = handle_list[i];
@ -52,11 +52,11 @@ int32_t WUPSDeletePluginContainer(const plugin_container_handle *handle_list, ui
return ERROR_NONE; return ERROR_NONE;
} }
int32_t WUPSDeletePluginData(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size) { extern "C" int32_t WUPSDeletePluginData(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size) {
if (plugin_data_handle_list != NULL && plugin_data_handle_list_size != 0) { if (plugin_data_handle_list != nullptr && plugin_data_handle_list_size != 0) {
for (uint32_t i = 0; i < plugin_data_handle_list_size; i++) { for (uint32_t i = 0; i < plugin_data_handle_list_size; i++) {
auto handle = plugin_data_handle_list[i]; auto handle = plugin_data_handle_list[i];
PluginData *pluginData = (PluginData *) handle; auto *pluginData = (PluginData *) handle;
DEBUG_FUNCTION_LINE("delete plugin data %08X", pluginData); DEBUG_FUNCTION_LINE("delete plugin data %08X", pluginData);
delete pluginData; delete pluginData;
} }
@ -64,7 +64,7 @@ int32_t WUPSDeletePluginData(const plugin_data_handle *plugin_data_handle_list,
return ERROR_NONE; return ERROR_NONE;
} }
int32_t WUPSLoadPluginAsData(GetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, plugin_data_handle *out) { extern "C" int32_t WUPSLoadPluginAsData(GetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, plugin_data_handle *out) {
std::optional<PluginData> pluginData; std::optional<PluginData> pluginData;
if (inputType == PLUGIN_INFORMATION_INPUT_TYPE_PATH) { if (inputType == PLUGIN_INFORMATION_INPUT_TYPE_PATH) {
pluginData = PluginDataFactory::load(path, pluginDataHeap); pluginData = PluginDataFactory::load(path, pluginDataHeap);
@ -81,32 +81,33 @@ int32_t WUPSLoadPluginAsData(GetPluginInformationInputType inputType, const char
return ERROR_FAILED_ALLOC; return ERROR_FAILED_ALLOC;
} }
if (out == NULL) { if (out == nullptr) {
DEBUG_FUNCTION_LINE("out was NULL"); DEBUG_FUNCTION_LINE("out was NULL");
return ERROR_INVALID_ARG; return ERROR_INVALID_ARG;
} else { } else {
PluginData *pluginDataHeap = new PluginData(pluginData.value()); auto *pluginDataHandle = new PluginData(pluginData.value());
DEBUG_FUNCTION_LINE("Saving handle %08X", pluginDataHeap); DEBUG_FUNCTION_LINE("Saving handle %08X", pluginDataHandle);
*out = (uint32_t) pluginDataHeap; *out = (uint32_t) pluginDataHandle;
} }
return ERROR_NONE; return ERROR_NONE;
} }
int32_t WUPSLoadPluginAsDataByPath(plugin_data_handle *output, const char *path) { extern "C" int32_t WUPSLoadPluginAsDataByPath(plugin_data_handle *output, const char *path) {
return WUPSLoadPluginAsData(PLUGIN_INFORMATION_INPUT_TYPE_PATH, path, NULL, 0, output); return WUPSLoadPluginAsData(PLUGIN_INFORMATION_INPUT_TYPE_PATH, path, nullptr, 0, output);
} }
int32_t WUPSLoadPluginAsDataByBuffer(plugin_data_handle *output, char *buffer, size_t size) { extern "C" int32_t WUPSLoadPluginAsDataByBuffer(plugin_data_handle *output, char *buffer, size_t size) {
return WUPSLoadPluginAsData(PLUGIN_INFORMATION_INPUT_TYPE_BUFFER, NULL, buffer, size, output); return WUPSLoadPluginAsData(PLUGIN_INFORMATION_INPUT_TYPE_BUFFER, nullptr, buffer, size, output);
} }
int32_t WUPSGetPluginMetaInformation(GetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, plugin_information *output) { extern "C" int32_t WUPSGetPluginMetaInformation(GetPluginInformationInputType inputType, const char* path, char *buffer, size_t size, plugin_information *output) {
std::optional<PluginMetaInformation> pluginInfo; std::optional<PluginMetaInformation> pluginInfo;
if (inputType == PLUGIN_INFORMATION_INPUT_TYPE_PATH && path != NULL) { if (inputType == PLUGIN_INFORMATION_INPUT_TYPE_PATH && path != nullptr) {
std::string pathStr(path);
DEBUG_FUNCTION_LINE("PLUGIN_INFORMATION_INPUT_TYPE_PATH %s", path); DEBUG_FUNCTION_LINE("PLUGIN_INFORMATION_INPUT_TYPE_PATH %s", path);
pluginInfo = PluginMetaInformationFactory::loadPlugin(path); pluginInfo = PluginMetaInformationFactory::loadPlugin(pathStr);
} else if (inputType == PLUGIN_INFORMATION_INPUT_TYPE_BUFFER && buffer != NULL && size > 0) { } else if (inputType == PLUGIN_INFORMATION_INPUT_TYPE_BUFFER && buffer != nullptr && size > 0) {
DEBUG_FUNCTION_LINE("PLUGIN_INFORMATION_INPUT_TYPE_BUFFER %08X %d", buffer, size); DEBUG_FUNCTION_LINE("PLUGIN_INFORMATION_INPUT_TYPE_BUFFER %08X %d", buffer, size);
pluginInfo = PluginMetaInformationFactory::loadPlugin(buffer, size); pluginInfo = PluginMetaInformationFactory::loadPlugin(buffer, size);
} else { } else {
@ -120,7 +121,7 @@ int32_t WUPSGetPluginMetaInformation(GetPluginInformationInputType inputType, co
DEBUG_FUNCTION_LINE("loaded plugin"); DEBUG_FUNCTION_LINE("loaded plugin");
if (output == NULL) { if (output == nullptr) {
return ERROR_INVALID_ARG; return ERROR_INVALID_ARG;
} else { } else {
fillPluginInformation(output, &pluginInfo.value()); fillPluginInformation(output, &pluginInfo.value());
@ -128,21 +129,21 @@ int32_t WUPSGetPluginMetaInformation(GetPluginInformationInputType inputType, co
return ERROR_NONE; return ERROR_NONE;
} }
int32_t WUPSGetPluginMetaInformationByPath(plugin_information *output, const char *path) { extern "C" int32_t WUPSGetPluginMetaInformationByPath(plugin_information *output, const char *path) {
return WUPSGetPluginMetaInformation(PLUGIN_INFORMATION_INPUT_TYPE_PATH, path, NULL, 0, output); return WUPSGetPluginMetaInformation(PLUGIN_INFORMATION_INPUT_TYPE_PATH, path, nullptr, 0, output);
} }
int32_t WUPSGetPluginMetaInformationByBuffer(plugin_information *output, char *buffer, size_t size) { extern "C" int32_t WUPSGetPluginMetaInformationByBuffer(plugin_information *output, char *buffer, size_t size) {
return WUPSGetPluginMetaInformation(PLUGIN_INFORMATION_INPUT_TYPE_BUFFER, NULL, buffer, size, output); return WUPSGetPluginMetaInformation(PLUGIN_INFORMATION_INPUT_TYPE_BUFFER, nullptr, buffer, size, output);
} }
int32_t WUPSGetPluginDataForContainerHandles(const plugin_container_handle *plugin_container_handle_list, plugin_data_handle *plugin_data_list, uint32_t buffer_size) { extern "C" int32_t WUPSGetPluginDataForContainerHandles(const plugin_container_handle *plugin_container_handle_list, plugin_data_handle *plugin_data_list, uint32_t buffer_size) {
int res = ERROR_NONE; int res = ERROR_NONE;
if (plugin_container_handle_list != NULL && buffer_size != 0) { if (plugin_container_handle_list != nullptr && buffer_size != 0) {
for (uint32_t i = 0; i < buffer_size; i++) { for (uint32_t i = 0; i < buffer_size; i++) {
auto handle = plugin_container_handle_list[i]; auto handle = plugin_container_handle_list[i];
PluginContainer *container = (PluginContainer *) handle; auto *container = (PluginContainer *) handle;
PluginData *pluginData = new PluginData(container->getPluginData()); auto *pluginData = new PluginData(container->getPluginData());
DEBUG_FUNCTION_LINE("Created pluginData [%08X]", pluginData); DEBUG_FUNCTION_LINE("Created pluginData [%08X]", pluginData);
plugin_data_list[i] = (uint32_t) pluginData; plugin_data_list[i] = (uint32_t) pluginData;
} }
@ -152,12 +153,12 @@ int32_t WUPSGetPluginDataForContainerHandles(const plugin_container_handle *plug
return res; return res;
} }
int32_t WUPSGetMetaInformation(plugin_container_handle *plugin_container_handle_list, plugin_information *plugin_information_list, uint32_t buffer_size) { extern "C" int32_t WUPSGetMetaInformation(const plugin_container_handle *plugin_container_handle_list, plugin_information *plugin_information_list, uint32_t buffer_size) {
int res = ERROR_NONE; int res = ERROR_NONE;
if (plugin_container_handle_list != NULL && buffer_size != 0) { if (plugin_container_handle_list != nullptr && buffer_size != 0) {
for (uint32_t i = 0; i < buffer_size; i++) { for (uint32_t i = 0; i < buffer_size; i++) {
auto handle = plugin_container_handle_list[i]; auto handle = plugin_container_handle_list[i];
PluginContainer *container = (PluginContainer *) handle; auto *container = (PluginContainer *) handle;
strncpy(plugin_information_list[i].author, container->metaInformation.getAuthor().c_str(), 255); strncpy(plugin_information_list[i].author, container->metaInformation.getAuthor().c_str(), 255);
strncpy(plugin_information_list[i].buildTimestamp, container->metaInformation.getBuildTimestamp().c_str(), 255); strncpy(plugin_information_list[i].buildTimestamp, container->metaInformation.getBuildTimestamp().c_str(), 255);
@ -173,12 +174,12 @@ int32_t WUPSGetMetaInformation(plugin_container_handle *plugin_container_handle_
return res; return res;
} }
int32_t WUPSGetLoadedPlugins(plugin_container_handle *io_handles, uint32_t buffer_size, uint32_t *outSize) { extern "C" int32_t WUPSGetLoadedPlugins(plugin_container_handle *io_handles, uint32_t buffer_size, uint32_t *outSize) {
auto plugins = PluginContainerPersistence::loadPlugins(gPluginInformation); auto plugins = PluginContainerPersistence::loadPlugins(gPluginInformation);
uint32_t counter = 0; uint32_t counter = 0;
for (auto &plugin: plugins) { for (auto &plugin: plugins) {
if (counter < buffer_size) { if (counter < buffer_size) {
PluginContainer *container = new PluginContainer(plugin); auto *container = new PluginContainer(plugin);
DEBUG_FUNCTION_LINE("Created container [%08X]", container); DEBUG_FUNCTION_LINE("Created container [%08X]", container);
io_handles[counter] = (uint32_t) container; io_handles[counter] = (uint32_t) container;
counter++; counter++;
@ -186,7 +187,7 @@ int32_t WUPSGetLoadedPlugins(plugin_container_handle *io_handles, uint32_t buffe
break; break;
} }
} }
if (outSize != NULL) { if (outSize != nullptr) {
*outSize = counter; *outSize = counter;
} }
return 0; return 0;

View File

@ -53,7 +53,7 @@ int32_t WUPSGetPluginMetaInformationByBuffer(plugin_information *output, char *b
int32_t WUPSGetPluginDataForContainerHandles(const plugin_container_handle *plugin_container_handle_list, plugin_data_handle *plugin_data_list, uint32_t buffer_size); int32_t WUPSGetPluginDataForContainerHandles(const plugin_container_handle *plugin_container_handle_list, plugin_data_handle *plugin_data_list, uint32_t buffer_size);
int32_t WUPSGetMetaInformation(plugin_container_handle *plugin_container_handle_list, plugin_information *plugin_information_list, uint32_t buffer_size); int32_t WUPSGetMetaInformation(const plugin_container_handle *plugin_container_handle_list, plugin_information *plugin_information_list, uint32_t buffer_size);
int32_t WUPSGetLoadedPlugins(plugin_container_handle *io_handles, uint32_t buffer_size, uint32_t *outSize); int32_t WUPSGetLoadedPlugins(plugin_container_handle *io_handles, uint32_t buffer_size, uint32_t *outSize);

View File

@ -1,6 +1,4 @@
#ifndef __LOGGER_H_ #pragma once
#define __LOGGER_H_
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -25,6 +23,4 @@ extern "C" {
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif