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

View File

@ -1,6 +1,7 @@
#include "globals.h"
MEMHeapHandle pluginDataHeap __attribute__((section(".data"))) = 0;
plugin_information_t *gPluginInformation __attribute__((section(".data"))) = NULL;
MEMHeapHandle pluginDataHeap __attribute__((section(".data"))) = nullptr;
plugin_information_t *gPluginInformation __attribute__((section(".data"))) = nullptr;
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
#include <plugin/PluginContainer.h>
#include <common/plugin_defines.h>
#include <wums.h>
#include "plugin/PluginContainer.h"
#include "common/plugin_defines.h"
extern plugin_information_t *gPluginInformation;
extern MEMHeapHandle pluginDataHeap;
extern plugin_information_on_reload_t gLinkOnReload;
extern module_information_t *gModuleData;
extern "C" void __init_wut();
extern "C" void __fini_wut();

View File

@ -1,7 +1,6 @@
#include "hooks.h"
#include "utils/logger.h"
void CallHook(plugin_information_t *pluginInformation, wups_loader_hook_type_t hook_type) {
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);
}
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);
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) {
((void (*)(void)) ((uint32_t *) func_ptr))();
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_APPLICATION_START) {
wups_loader_app_started_args_t args;
((void (*)(wups_loader_app_started_args_t)) ((uint32_t *) func_ptr))(args);
} 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) {
((void (*)(void)) ((uint32_t *) func_ptr))();
((void (*)()) ((uint32_t *) func_ptr))();
} 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) {
((void (*)(void)) ((uint32_t *) func_ptr))();
((void (*)()) ((uint32_t *) func_ptr))();
} 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) {
((void (*)(void)) ((uint32_t *) func_ptr))();
((void (*)()) ((uint32_t *) func_ptr))();
} 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) {
((void (*)(void)) ((uint32_t *) func_ptr))();
((void (*)()) ((uint32_t *) func_ptr))();
} 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) {
((void (*)(void)) ((uint32_t *) func_ptr))();
((void (*)()) ((uint32_t *) func_ptr))();
} 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) {
((void (*)(void)) ((uint32_t *) func_ptr))();
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_VSYNC) {
((void (*)(void)) ((uint32_t *) func_ptr))();
((void (*)()) ((uint32_t *) func_ptr))();
} else {
DEBUG_FUNCTION_LINE("######################################");
DEBUG_FUNCTION_LINE("Hook is not implemented %s [%d]", hook_names[hook_type], hook_type);

View File

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

View File

@ -1,14 +1,13 @@
#include "utils/logger.h"
#include "hooks_patcher_static.h"
#include <malloc.h>
#include <wups.h>
#include <vpad/input.h>
#include <coreinit/messagequeue.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) {
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) {
int32_t res = real_OSReceiveMessage(queue, message, flags);
if (queue == OSGetSystemMessageQueue()) {
if (message != NULL && res) {
if (message != nullptr && res) {
if (lastData0 != message->args[0]) {
if (message->args[0] == 0xFACEF000) {
CallHook(gPluginInformation, WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND);

View File

@ -1,25 +1,21 @@
#include "DynamicLinkingHelper.h"
#include <stdio.h>
#include <string.h>
#include <vector>
#include <coreinit/dynload.h>
#include "utils/logger.h"
#include "common/plugin_defines.h"
#include <cstring>
#include "../utils/logger.h"
dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_linking_relocation_data_t *data, const char *functionName) {
if (data == NULL) {
return NULL;
if (data == nullptr) {
return nullptr;
}
if (functionName == NULL) {
return NULL;
if (functionName == nullptr) {
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++) {
dyn_linking_function_t *curEntry = &(data->functions[i]);
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.\n");
return NULL;
return nullptr;
}
strncpy(curEntry->functionName, functionName, DYN_LINK_FUNCTION_NAME_LENGTH);
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) {
if (importName == NULL || data == NULL) {
return NULL;
if (importName == nullptr || data == nullptr) {
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++) {
dyn_linking_import_t *curEntry = &(data->imports[i]);
if (strlen(curEntry->importName) == 0) {
if (strlen(importName) > DYN_LINK_IMPORT_NAME_LENGTH) {
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);
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,
const std::string &name, const ImportRPLInformation &rplInfo) {
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);
return false;
}
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);
return false;
}
@ -91,7 +87,7 @@ bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_entry_t *lin
dyn_linking_import_t *importInfo) {
for (uint32_t i = 0; i < linking_entry_length; i++) {
dyn_linking_relocation_entry_t *curEntry = &(linking_entries[i]);
if (curEntry->functionEntry != NULL) {
if (curEntry->functionEntry != nullptr) {
continue;
}
curEntry->type = type;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
#pragma once
#include "common/plugin_defines.h"
#include "../common/plugin_defines.h"
#include "PluginContainer.h"
class PluginContainerPersistence {
@ -8,6 +8,4 @@ public:
static bool savePlugin(plugin_information_t *pluginInformation, PluginContainer &plugin);
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 <utility>
#include <malloc.h>
#include "../utils/logger.h"
PluginData::PluginData(const PluginData &obj) {
this->buffer = obj.buffer;
@ -9,7 +12,7 @@ PluginData::PluginData(const PluginData &obj) {
}
void PluginData::freeMemory() {
if (buffer == NULL) {
if (buffer == nullptr) {
return;
}
@ -17,29 +20,29 @@ void PluginData::freeMemory() {
default:
case eMemTypeExpHeap:
MEMFreeToExpHeap(this->heapHandle, buffer);
this->buffer = NULL;
this->buffer = nullptr;
break;
case eMemTypeMEM2:
free(this->buffer);
this->buffer = NULL;
this->buffer = nullptr;
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),
memoryType(memoryType),
length(input.size()) {
void *data_copy = NULL;
void *data_copy = nullptr;
switch (memoryType) {
default:
case eMemTypeExpHeap:
data_copy = MEMAllocFromExpHeapEx(heapHandle, length, 4);
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");
} else {
memcpy(data_copy, &input[0], length);
@ -49,7 +52,7 @@ PluginData::PluginData(std::vector<uint8_t> input, MEMHeapHandle heapHandle, eMe
break;
case eMemTypeMEM2:
data_copy = memalign(length, 4);
if (data_copy == NULL) {
if (data_copy == nullptr) {
DEBUG_FUNCTION_LINE("Failed to allocate space on default heap");
} else {
memcpy(data_copy, &input[0], length);
@ -58,7 +61,3 @@ PluginData::PluginData(std::vector<uint8_t> input, MEMHeapHandle heapHandle, eMe
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 <coreinit/memexpheap.h>
#include "elfio/elfio.hpp"
#include "../elfio/elfio.hpp"
using namespace ELFIO;
@ -33,28 +33,23 @@ enum eMemoryTypes {
class PluginData {
public:
~PluginData() {
}
~PluginData() = default;
void freeMemory();
PluginData(const PluginData &obj);
PluginData() {
}
PluginData() = default;
void *buffer = NULL;
MEMHeapHandle heapHandle;
void *buffer = nullptr;
MEMHeapHandle heapHandle{};
eMemoryTypes memoryType;
size_t length = 0;
private:
PluginData(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);
explicit PluginData(const std::vector<uint8_t> &buffer);
PluginData(const std::vector<uint8_t>& input, MEMHeapHandle heapHandle, eMemoryTypes memoryType);
friend class PluginDataFactory;

View File

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

View File

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

View File

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

View File

@ -31,17 +31,15 @@ class PluginInformation {
public:
PluginInformation(const PluginInformation &other);
PluginInformation() {
}
PluginInformation() = default;
virtual ~PluginInformation() {
}
virtual ~PluginInformation() = default;
void addHookData(const HookData &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;
}
@ -49,7 +47,7 @@ public:
function_data_list.push_back(function_data);
}
const std::vector<FunctionData> &getFunctionDataList() const {
[[nodiscard]] const std::vector<FunctionData> &getFunctionDataList() const {
return function_data_list;
}
@ -57,7 +55,7 @@ public:
relocation_data_list.push_back(relocation_data);
}
const std::vector<RelocationData> &getRelocationDataList() const {
[[nodiscard]] const std::vector<RelocationData> &getRelocationDataList() const {
return relocation_data_list;
}
@ -65,27 +63,26 @@ public:
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;
}
std::optional<SectionInfo> getSectionInfo(const std::string &sectionName) const {
[[nodiscard]] std::optional<SectionInfo> getSectionInfo(const std::string &sectionName) const {
if (getSectionInfoList().count(sectionName) > 0) {
return section_info_list.at(sectionName);
}
return std::nullopt;
}
void setTrampolinId(uint8_t trampolinId) {
this->trampolinId = trampolinId;
void setTrampolinId(uint8_t _trampolinId) {
this->trampolinId = _trampolinId;
}
uint8_t getTrampolinId() const {
[[nodiscard]] uint8_t getTrampolinId() const {
return trampolinId;
}
private:
std::vector<HookData> hook_data_list;
std::vector<FunctionData> function_data_list;
std::vector<RelocationData> relocation_data_list;
@ -93,8 +90,8 @@ private:
uint8_t trampolinId = 0;
void *allocatedTextMemoryAddress = 0;
void *allocatedDataMemoryAddress = 0;
void *allocatedTextMemoryAddress = nullptr;
void *allocatedDataMemoryAddress = nullptr;
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
* it under the terms of the GNU General Public License as published by
@ -26,15 +26,15 @@
#include "PluginInformationFactory.h"
#include "HookData.h"
#include "SectionInfo.h"
#include "elfio/elfio.hpp"
#include "utils/utils.h"
#include "utils/ElfUtils.h"
#include "utils/StringTools.h"
#include "../elfio/elfio.hpp"
#include "../utils/utils.h"
#include "../utils/ElfUtils.h"
#include "../utils/StringTools.h"
using namespace ELFIO;
std::optional<PluginInformation> PluginInformationFactory::load(const PluginData &pluginData, MEMHeapHandle heapHandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId) {
if(pluginData.buffer == NULL){
if (pluginData.buffer == nullptr) {
DEBUG_FUNCTION_LINE("Buffer was NULL");
return std::nullopt;
}
@ -47,7 +47,7 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
PluginInformation pluginInfo;
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;
@ -74,14 +74,14 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
}
}
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);
return std::nullopt;
}
DEBUG_FUNCTION_LINE("Allocated %d kb from ExpHeap", text_size / 1024);
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);
MEMFreeToExpHeap(heapHandle, text_data);
@ -133,7 +133,8 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
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);
totalSize += sectionSize;
@ -177,8 +178,8 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
std::optional<SectionInfo> secInfo = pluginInfo.getSectionInfo(".wups.hooks");
if (secInfo && secInfo->getSize() > 0) {
size_t entries_count = secInfo->getSize() / sizeof(wups_loader_hook_t);
wups_loader_hook_t *entries = (wups_loader_hook_t *) secInfo->getAddress();
if (entries != NULL) {
auto *entries = (wups_loader_hook_t *) secInfo->getAddress();
if (entries != nullptr) {
for (size_t j = 0; j < entries_count; 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);
@ -191,7 +192,7 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
secInfo = pluginInfo.getSectionInfo(".wups.load");
if (secInfo && secInfo->getSize() > 0) {
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) {
for (size_t j = 0; j < entries_count; j++) {
wups_loader_entry_t *cur_function = &entries[j];

View File

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

View File

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

View File

@ -19,10 +19,11 @@
#include <sys/stat.h>
#include <dirent.h>
#include <whb/file.h>
#include "utils/StringTools.h"
#include "../utils/StringTools.h"
#include "PluginMetaInformationFactory.h"
#include "PluginMetaInformation.h"
#include "elfio/elfio.hpp"
#include "../elfio/elfio.hpp"
#include "../utils/logger.h"
using namespace ELFIO;
@ -39,7 +40,7 @@ std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(co
return loadPlugin(reader);
}
std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(const std::string filePath) {
std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(std::string &filePath) {
elfio reader;
if (!reader.load(filePath)) {
DEBUG_FUNCTION_LINE("Can't find or process ELF file\n");

View File

@ -27,7 +27,7 @@ class PluginMetaInformationFactory {
public:
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);

View File

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

View File

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

View File

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

View File

@ -1,6 +1,4 @@
#ifndef __LOGGER_H_
#define __LOGGER_H_
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
@ -26,5 +24,3 @@ extern "C" {
#ifdef __cplusplus
}
#endif
#endif