mirror of
https://github.com/wiiu-env/WiiUPluginLoaderBackend.git
synced 2024-11-22 04:39:17 +01:00
Formatting and cleanup
This commit is contained in:
parent
13ed348f43
commit
aa90e2478b
@ -7,7 +7,6 @@
|
||||
#include "plugin/PluginMetaInformationFactory.h"
|
||||
#include "plugin/PluginInformationFactory.h"
|
||||
|
||||
#include "utils/logger.h"
|
||||
#include "utils/ElfUtils.h"
|
||||
#include "PluginManagement.h"
|
||||
#include "hooks.h"
|
||||
@ -98,22 +97,22 @@ void PluginManagement::RestorePatches(plugin_information_t *pluginInformation, B
|
||||
}
|
||||
}
|
||||
|
||||
void PluginManagement::unloadPlugins(plugin_information_t *gPluginInformation, MEMHeapHandle pluginHeap, BOOL freePluginData) {
|
||||
CallHook(gPluginInformation, WUPS_LOADER_HOOK_INIT_WUT_MALLOC);
|
||||
CallHook(gPluginInformation, WUPS_LOADER_HOOK_INIT_WUT_NEWLIB);
|
||||
CallHook(gPluginInformation, WUPS_LOADER_HOOK_INIT_WUT_STDCPP);
|
||||
CallHook(gPluginInformation, WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB);
|
||||
CallHook(gPluginInformation, WUPS_LOADER_HOOK_INIT_WUT_SOCKETS);
|
||||
CallHook(gPluginInformation, WUPS_LOADER_HOOK_DEINIT_PLUGIN);
|
||||
// CallHook(gPluginInformation, WUPS_LOADER_HOOK_FINI_WUT_SOCKETS); To keep network alive we skip this.
|
||||
CallHook(gPluginInformation, WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB);
|
||||
CallHook(gPluginInformation, WUPS_LOADER_HOOK_FINI_WUT_STDCPP);
|
||||
CallHook(gPluginInformation, WUPS_LOADER_HOOK_FINI_WUT_NEWLIB);
|
||||
CallHook(gPluginInformation, WUPS_LOADER_HOOK_FINI_WUT_MALLOC);
|
||||
void PluginManagement::unloadPlugins(plugin_information_t *pluginInformation, MEMHeapHandle pluginHeap, BOOL freePluginData) {
|
||||
CallHook(pluginInformation, WUPS_LOADER_HOOK_INIT_WUT_MALLOC);
|
||||
CallHook(pluginInformation, WUPS_LOADER_HOOK_INIT_WUT_NEWLIB);
|
||||
CallHook(pluginInformation, WUPS_LOADER_HOOK_INIT_WUT_STDCPP);
|
||||
CallHook(pluginInformation, WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB);
|
||||
CallHook(pluginInformation, WUPS_LOADER_HOOK_INIT_WUT_SOCKETS);
|
||||
CallHook(pluginInformation, WUPS_LOADER_HOOK_DEINIT_PLUGIN);
|
||||
// CallHook(pluginInformation, WUPS_LOADER_HOOK_FINI_WUT_SOCKETS); To keep network alive we skip this.
|
||||
CallHook(pluginInformation, WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB);
|
||||
CallHook(pluginInformation, WUPS_LOADER_HOOK_FINI_WUT_STDCPP);
|
||||
CallHook(pluginInformation, WUPS_LOADER_HOOK_FINI_WUT_NEWLIB);
|
||||
CallHook(pluginInformation, WUPS_LOADER_HOOK_FINI_WUT_MALLOC);
|
||||
|
||||
RestorePatches(gPluginInformation, true);
|
||||
for (int32_t plugin_index = 0; plugin_index < gPluginInformation->number_used_plugins; plugin_index++) {
|
||||
plugin_information_single_t *plugin = &(gPluginInformation->plugin_data[plugin_index]);
|
||||
RestorePatches(pluginInformation, true);
|
||||
for (int32_t plugin_index = 0; plugin_index < pluginInformation->number_used_plugins; plugin_index++) {
|
||||
plugin_information_single_t *plugin = &(pluginInformation->plugin_data[plugin_index]);
|
||||
if (freePluginData) {
|
||||
if (plugin->data.buffer != nullptr) {
|
||||
if (plugin->data.memoryType == eMemTypeMEM2) {
|
||||
@ -151,7 +150,7 @@ void PluginManagement::unloadPlugins(plugin_information_t *gPluginInformation, M
|
||||
}
|
||||
}
|
||||
|
||||
memset((void *) gPluginInformation, 0, sizeof(plugin_information_t));
|
||||
memset((void *) pluginInformation, 0, sizeof(plugin_information_t));
|
||||
}
|
||||
|
||||
void PluginManagement::callInitHooks(plugin_information_t *pluginInformation) {
|
||||
@ -165,29 +164,30 @@ void module_callback(OSDynLoad_Module module,
|
||||
OSDynLoad_NotifyReason reason,
|
||||
OSDynLoad_NotifyData *infos) {
|
||||
if (reason == OS_DYNLOAD_NOTIFY_LOADED) {
|
||||
auto *gPluginInformation = (plugin_information_t *) userContext;
|
||||
for (int32_t plugin_index = 0; plugin_index < gPluginInformation->number_used_plugins; plugin_index++) {
|
||||
FunctionPatcherPatchFunction(gPluginInformation->plugin_data[plugin_index].info.functions, gPluginInformation->plugin_data[plugin_index].info.number_used_functions);
|
||||
auto *pluginInformation = (plugin_information_t *) userContext;
|
||||
for (int32_t plugin_index = 0; plugin_index < pluginInformation->number_used_plugins; plugin_index++) {
|
||||
FunctionPatcherPatchFunction(pluginInformation->plugin_data[plugin_index].info.functions, pluginInformation->plugin_data[plugin_index].info.number_used_functions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PluginManagement::PatchFunctionsAndCallHooks(plugin_information_t *gPluginInformation) {
|
||||
void PluginManagement::PatchFunctionsAndCallHooks(plugin_information_t *pluginInformation) {
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Patching functions");
|
||||
FunctionPatcherPatchFunction(method_hooks_hooks_static, method_hooks_size_hooks_static);
|
||||
|
||||
DCFlushRange((void *) 0x00800000, 0x00800000);
|
||||
ICInvalidateRange((void *) 0x00800000, 0x00800000);
|
||||
|
||||
for (int32_t plugin_index = 0; plugin_index < gPluginInformation->number_used_plugins; plugin_index++) {
|
||||
CallHookEx(gPluginInformation, WUPS_LOADER_HOOK_APPLICATION_STARTS, plugin_index);
|
||||
FunctionPatcherPatchFunction(gPluginInformation->plugin_data[plugin_index].info.functions, gPluginInformation->plugin_data[plugin_index].info.number_used_functions);
|
||||
CallHookEx(gPluginInformation, WUPS_LOADER_HOOK_FUNCTIONS_PATCHED, plugin_index);
|
||||
for (int32_t plugin_index = 0; plugin_index < pluginInformation->number_used_plugins; plugin_index++) {
|
||||
CallHookEx(pluginInformation, WUPS_LOADER_HOOK_APPLICATION_STARTS, plugin_index);
|
||||
FunctionPatcherPatchFunction(pluginInformation->plugin_data[plugin_index].info.functions, pluginInformation->plugin_data[plugin_index].info.number_used_functions);
|
||||
CallHookEx(pluginInformation, WUPS_LOADER_HOOK_FUNCTIONS_PATCHED, plugin_index);
|
||||
}
|
||||
OSDynLoad_AddNotifyCallback(module_callback, gPluginInformation);
|
||||
OSDynLoad_AddNotifyCallback(module_callback, pluginInformation);
|
||||
}
|
||||
|
||||
std::vector<PluginContainer> PluginManagement::loadPlugins(const std::vector<PluginData> &pluginList, MEMHeapHandle heapHandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length) {
|
||||
std::vector<PluginContainer>
|
||||
PluginManagement::loadPlugins(const std::vector<PluginData> &pluginList, MEMHeapHandle heapHandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length) {
|
||||
std::vector<PluginContainer> plugins;
|
||||
|
||||
for (auto &pluginData: pluginList) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <common/plugin_defines.h>
|
||||
#include <vector>
|
||||
|
||||
|
@ -17,8 +17,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <wums/defines/dynamic_linking_defines.h>
|
||||
#include <wums/defines/export_defines.h>
|
||||
#include <wums/defines/relocation_defines.h>
|
||||
@ -45,8 +45,8 @@ extern "C" {
|
||||
|
||||
struct plugin_section_info_t {
|
||||
char name[MAXIMUM_PLUGIN_SECTION_NAME_LENGTH] = "";
|
||||
uint32_t addr;
|
||||
uint32_t size;
|
||||
uint32_t addr{};
|
||||
uint32_t size{};
|
||||
};
|
||||
|
||||
struct plugin_meta_info_t {
|
||||
@ -57,28 +57,28 @@ struct plugin_meta_info_t {
|
||||
char buildTimestamp[MAXIMUM_PLUGIN_META_FIELD_LENGTH] = "";
|
||||
char descripion[MAXIMUM_PLUGIN_DESCRIPTION_LENGTH] = "";
|
||||
char id[MAXIMUM_PLUGIN_META_FIELD_LENGTH] = "";
|
||||
uint32_t size;
|
||||
uint32_t size{};
|
||||
};
|
||||
|
||||
struct replacement_data_hook_t {
|
||||
void * func_pointer = NULL; /* [will be filled] */
|
||||
wups_loader_hook_type_t type; /* [will be filled] */
|
||||
void * func_pointer = nullptr; /* [will be filled] */
|
||||
wups_loader_hook_type_t type{}; /* [will be filled] */
|
||||
};
|
||||
|
||||
struct plugin_info_t {
|
||||
dyn_linking_relocation_entry_t linking_entries[PLUGIN_DYN_LINK_RELOCATION_LIST_LENGTH];
|
||||
dyn_linking_relocation_entry_t linking_entries[PLUGIN_DYN_LINK_RELOCATION_LIST_LENGTH]{};
|
||||
plugin_section_info_t sectionInfos[MAXIMUM_PLUGIN_SECTION_LENGTH];
|
||||
uint32_t number_used_functions; // Number of used function. Maximum is MAXIMUM_FUNCTION_PER_PLUGIN
|
||||
function_replacement_data_t functions[MAXIMUM_FUNCTION_PER_PLUGIN]; // Replacement information for each function.
|
||||
uint32_t number_used_hooks; // Number of used hooks. Maximum is MAXIMUM_HOOKS_PER_PLUGIN
|
||||
uint32_t number_used_functions{}; // Number of used function. Maximum is MAXIMUM_FUNCTION_PER_PLUGIN
|
||||
function_replacement_data_t functions[MAXIMUM_FUNCTION_PER_PLUGIN]{}; // Replacement information for each function.
|
||||
uint32_t number_used_hooks{}; // Number of used hooks. Maximum is MAXIMUM_HOOKS_PER_PLUGIN
|
||||
replacement_data_hook_t hooks[MAXIMUM_HOOKS_PER_PLUGIN]; // Replacement information for each function.
|
||||
uint8_t trampolinId;
|
||||
uint8_t trampolinId{};
|
||||
void * allocatedTextMemoryAddress = nullptr;
|
||||
void * allocatedDataMemoryAddress = nullptr;
|
||||
};
|
||||
|
||||
struct plugin_data_t {
|
||||
char * buffer = NULL;
|
||||
char * buffer = nullptr;
|
||||
size_t bufferLength = 0;
|
||||
int memoryType = 0;
|
||||
int heapHandle = 0;
|
||||
@ -88,7 +88,7 @@ struct plugin_information_single_t {
|
||||
plugin_meta_info_t meta;
|
||||
plugin_info_t info;
|
||||
plugin_data_t data;
|
||||
int32_t priority; // Priority of this plugin
|
||||
int32_t priority{}; // Priority of this plugin
|
||||
};
|
||||
|
||||
#define MAXIMUM_PLUGINS 32
|
||||
@ -96,7 +96,7 @@ struct plugin_information_single_t {
|
||||
struct plugin_information_t {
|
||||
int32_t number_used_plugins = 0; // Number of used plugins. Maximum is MAXIMUM_PLUGINS
|
||||
plugin_information_single_t plugin_data[MAXIMUM_PLUGINS];
|
||||
dyn_linking_relocation_data_t linking_data; // RPL and function name list
|
||||
dyn_linking_relocation_data_t linking_data{}; // RPL and function name list
|
||||
};
|
||||
|
||||
struct plugin_information_on_reload_t {
|
||||
|
@ -69,7 +69,7 @@ public:
|
||||
\param category: The category that will be added to this config.
|
||||
|
||||
\return On success, the inserted category will be returned.
|
||||
On error NULL will be returned. In this case the caller still has the responsibility
|
||||
On error nullptr will be returned. In this case the caller still has the responsibility
|
||||
for deleting the WUPSConfigCategory instance.
|
||||
**/
|
||||
WUPSConfigCategory *addCategory(WUPSConfigCategory *category) {
|
||||
|
@ -140,7 +140,7 @@ public:
|
||||
This function will be called whenever this item should call it's (optional) given
|
||||
callback with the current value.
|
||||
Returns true if a valid callback could be called
|
||||
Returns false if no callback was called (e.g. callback was NULL)
|
||||
Returns false if no callback was called (e.g. callback was nullptr)
|
||||
**/
|
||||
bool callCallback() {
|
||||
if (this->callbacks.callCallback != nullptr) {
|
||||
|
@ -14,7 +14,7 @@ int32_t WUPSConfigItem_Create(WUPSConfigItemHandle *out, const char *configID, c
|
||||
return 0;
|
||||
}
|
||||
return -2;
|
||||
};
|
||||
}
|
||||
|
||||
int32_t WUPSConfigItem_Destroy(WUPSConfigItemHandle handle) {
|
||||
if (handle == 0) {
|
||||
@ -24,7 +24,7 @@ int32_t WUPSConfigItem_Destroy(WUPSConfigItemHandle handle) {
|
||||
auto *config = reinterpret_cast<WUPSConfigItem *>(handle);
|
||||
delete config;
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
int32_t WUPSConfigItem_SetDisplayName(WUPSConfigItemHandle handle, const char *displayName) {
|
||||
if (displayName == nullptr) {
|
||||
@ -34,7 +34,7 @@ int32_t WUPSConfigItem_SetDisplayName(WUPSConfigItemHandle handle, const char *d
|
||||
auto *config = reinterpret_cast<WUPSConfigItem *>(handle);
|
||||
config->setDisplayName(displayName);
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
int32_t WUPSConfigItem_GetDisplayName(WUPSConfigItemHandle handle, char *out_buf, int32_t out_len) {
|
||||
if (out_buf == nullptr) {
|
||||
@ -53,7 +53,7 @@ int32_t WUPSConfigItem_SetConfigID(WUPSConfigItemHandle handle, const char *conf
|
||||
auto *config = reinterpret_cast<WUPSConfigItem *>(handle);
|
||||
config->setConfigID(configID);
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
int32_t WUPSConfigItem_GetConfigID(WUPSConfigItemHandle handle, char *out_buf, int32_t out_len) {
|
||||
if (out_buf == nullptr) {
|
||||
|
@ -1,13 +1,12 @@
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <strings.h>
|
||||
#include <fs/CFile.hpp>
|
||||
|
||||
CFile::CFile() {
|
||||
iFd = -1;
|
||||
mem_file = NULL;
|
||||
mem_file = nullptr;
|
||||
filesize = 0;
|
||||
pos = 0;
|
||||
}
|
||||
@ -78,7 +77,7 @@ void CFile::close() {
|
||||
::close(iFd);
|
||||
|
||||
iFd = -1;
|
||||
mem_file = NULL;
|
||||
mem_file = nullptr;
|
||||
filesize = 0;
|
||||
pos = 0;
|
||||
}
|
||||
@ -99,7 +98,7 @@ int32_t CFile::read(uint8_t *ptr, size_t size) {
|
||||
if (readsize <= 0)
|
||||
return readsize;
|
||||
|
||||
if (mem_file != NULL) {
|
||||
if (mem_file != nullptr) {
|
||||
memcpy(ptr, mem_file + pos, readsize);
|
||||
pos += readsize;
|
||||
return readsize;
|
||||
@ -147,7 +146,7 @@ int32_t CFile::seek(long int offset, int32_t origin) {
|
||||
if (iFd >= 0)
|
||||
ret = ::lseek(iFd, pos, SEEK_SET);
|
||||
|
||||
if (mem_file != NULL) {
|
||||
if (mem_file != nullptr) {
|
||||
if (pos > filesize) {
|
||||
pos = filesize;
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
#ifndef CFILE_HPP_
|
||||
#define CFILE_HPP_
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <wut_types.h>
|
||||
@ -29,7 +28,7 @@ public:
|
||||
|
||||
int32_t open(const uint8_t *memory, int32_t memsize);
|
||||
|
||||
BOOL isOpen() const {
|
||||
[[nodiscard]] BOOL isOpen() const {
|
||||
if (iFd >= 0)
|
||||
return true;
|
||||
|
||||
@ -49,11 +48,11 @@ public:
|
||||
|
||||
int32_t seek(long int offset, int32_t origin);
|
||||
|
||||
uint64_t tell() {
|
||||
[[nodiscard]] uint64_t tell() const {
|
||||
return pos;
|
||||
};
|
||||
|
||||
uint64_t size() {
|
||||
[[nodiscard]] uint64_t size() const {
|
||||
return filesize;
|
||||
};
|
||||
|
||||
@ -63,9 +62,7 @@ public:
|
||||
|
||||
protected:
|
||||
int32_t iFd;
|
||||
const uint8_t *mem_file;
|
||||
uint64_t filesize;
|
||||
uint64_t pos;
|
||||
const uint8_t *mem_file{};
|
||||
uint64_t filesize{};
|
||||
uint64_t pos{};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -81,11 +81,11 @@ BOOL DirList::InternalLoadPath(std::string &folderpath) {
|
||||
if (folderpath.size() < 3)
|
||||
return false;
|
||||
|
||||
struct dirent *dirent = NULL;
|
||||
DIR *dir = NULL;
|
||||
struct dirent *dirent = nullptr;
|
||||
DIR *dir = nullptr;
|
||||
|
||||
dir = opendir(folderpath.c_str());
|
||||
if (dir == NULL)
|
||||
if (dir == nullptr)
|
||||
return false;
|
||||
|
||||
while ((dirent = readdir(dir)) != 0) {
|
||||
@ -153,7 +153,7 @@ void DirList::ClearList() {
|
||||
for (uint32_t i = 0; i < FileInfo.size(); ++i) {
|
||||
if (FileInfo[i].FilePath) {
|
||||
free(FileInfo[i].FilePath);
|
||||
FileInfo[i].FilePath = NULL;
|
||||
FileInfo[i].FilePath = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,13 +44,13 @@ public:
|
||||
//!\param path Path from where to load the filelist of all files
|
||||
//!\param filter A fileext that needs to be filtered
|
||||
//!\param flags search/filter flags from the enum
|
||||
DirList(const std::string &path, const char *filter = NULL, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
|
||||
DirList(const std::string &path, const char *filter = nullptr, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
|
||||
|
||||
//!Destructor
|
||||
virtual ~DirList();
|
||||
|
||||
//! Load all the files from a directory
|
||||
BOOL LoadPath(const std::string &path, const char *filter = NULL, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
|
||||
BOOL LoadPath(const std::string &path, const char *filter = nullptr, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
|
||||
|
||||
//! Get a filename of the list
|
||||
//!\param list index
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) {
|
||||
//! always initialze input
|
||||
*inbuffer = NULL;
|
||||
*inbuffer = nullptr;
|
||||
if (size)
|
||||
*size = 0;
|
||||
|
||||
@ -21,7 +21,7 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_
|
||||
lseek(iFd, 0, SEEK_SET);
|
||||
|
||||
uint8_t *buffer = (uint8_t *) malloc(filesize);
|
||||
if (buffer == NULL) {
|
||||
if (buffer == nullptr) {
|
||||
close(iFd);
|
||||
return -2;
|
||||
}
|
||||
@ -44,7 +44,7 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_
|
||||
|
||||
if (done != filesize) {
|
||||
free(buffer);
|
||||
buffer = NULL;
|
||||
buffer = nullptr;
|
||||
return -3;
|
||||
}
|
||||
|
||||
|
@ -213,7 +213,7 @@ void *allocOnCustomHeap(int alignment, int size) {
|
||||
}
|
||||
uint32_t *custom_memalign;
|
||||
dyn_res = OSDynLoad_FindExport(module, true, "MEMAllocFromMappedMemoryEx", reinterpret_cast<void **>(&custom_memalign));
|
||||
void *(*customMEMAllocFromDefaultHeapEx)(uint32_t size, int align) = (void *(*)(uint32_t, int)) *custom_memalign;
|
||||
auto * customMEMAllocFromDefaultHeapEx = (void *(*)(uint32_t, int)) *custom_memalign;
|
||||
|
||||
if (dyn_res != OS_DYNLOAD_OK) {
|
||||
return nullptr;
|
||||
|
@ -45,8 +45,9 @@ DECL_FUNCTION(void, GX2SetDRCBuffer, void *buffer, uint32_t buffer_size, uint32_
|
||||
}
|
||||
|
||||
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);
|
||||
uint32_t res = real_OSReceiveMessage(queue, message, flags);
|
||||
if (queue == OSGetSystemMessageQueue()) {
|
||||
if (message != nullptr && res) {
|
||||
if (lastData0 != message->args[0]) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "DynamicLinkingHelper.h"
|
||||
#include <cstring>
|
||||
#include "../utils/logger.h"
|
||||
|
||||
dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_linking_relocation_data_t *data, const char *functionName) {
|
||||
if (data == nullptr) {
|
||||
@ -10,19 +9,18 @@ dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_li
|
||||
return nullptr;
|
||||
}
|
||||
dyn_linking_function_t *result = nullptr;
|
||||
for (int32_t i = 0; i < DYN_LINK_FUNCTION_LIST_LENGTH; i++) {
|
||||
dyn_linking_function_t *curEntry = &(data->functions[i]);
|
||||
if (strlen(curEntry->functionName) == 0) {
|
||||
for (auto & curEntry : data->functions) {
|
||||
if (strlen(curEntry.functionName) == 0) {
|
||||
if (strlen(functionName) > DYN_LINK_FUNCTION_NAME_LENGTH) {
|
||||
DEBUG_FUNCTION_LINE("Failed to add function name, it's too long.");
|
||||
return nullptr;
|
||||
}
|
||||
strncpy(curEntry->functionName, functionName, DYN_LINK_FUNCTION_NAME_LENGTH);
|
||||
result = curEntry;
|
||||
strncpy(curEntry.functionName, functionName, DYN_LINK_FUNCTION_NAME_LENGTH);
|
||||
result = &curEntry;
|
||||
break;
|
||||
}
|
||||
if (strncmp(curEntry->functionName, functionName, DYN_LINK_FUNCTION_NAME_LENGTH) == 0) {
|
||||
result = curEntry;
|
||||
if (strncmp(curEntry.functionName, functionName, DYN_LINK_FUNCTION_NAME_LENGTH) == 0) {
|
||||
result = &curEntry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -42,31 +40,33 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocatio
|
||||
return nullptr;
|
||||
}
|
||||
dyn_linking_import_t *result = nullptr;
|
||||
for (int32_t i = 0; i < DYN_LINK_IMPORT_LIST_LENGTH; i++) {
|
||||
dyn_linking_import_t *curEntry = &(data->imports[i]);
|
||||
if (strlen(curEntry->importName) == 0) {
|
||||
for (auto & curEntry : data->imports) {
|
||||
if (strlen(curEntry.importName) == 0) {
|
||||
if (strlen(importName) > DYN_LINK_IMPORT_NAME_LENGTH) {
|
||||
DEBUG_FUNCTION_LINE("Failed to add Import, it's too long.");
|
||||
return nullptr;
|
||||
}
|
||||
strncpy(curEntry->importName, importName, DYN_LINK_IMPORT_NAME_LENGTH);
|
||||
curEntry->isData = isData;
|
||||
result = curEntry;
|
||||
strncpy(curEntry.importName, importName, DYN_LINK_IMPORT_NAME_LENGTH);
|
||||
curEntry.isData = isData;
|
||||
result = &curEntry;
|
||||
break;
|
||||
}
|
||||
if (strncmp(curEntry->importName, importName, DYN_LINK_IMPORT_NAME_LENGTH) == 0 && (curEntry->isData == isData)) {
|
||||
return curEntry;
|
||||
if (strncmp(curEntry.importName, importName, DYN_LINK_IMPORT_NAME_LENGTH) == 0 && (curEntry.isData == isData)) {
|
||||
return &curEntry;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, const RelocationData &relocationData) {
|
||||
return addReloationEntry(linking_data, linking_entries, linking_entry_length, relocationData.getType(), relocationData.getOffset(), relocationData.getAddend(), relocationData.getDestination(), relocationData.getName(),
|
||||
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length,
|
||||
const RelocationData &relocationData) {
|
||||
return addReloationEntry(linking_data, linking_entries, linking_entry_length, relocationData.getType(), relocationData.getOffset(), relocationData.getAddend(), relocationData.getDestination(),
|
||||
relocationData.getName(),
|
||||
relocationData.getImportRPLInformation());
|
||||
}
|
||||
|
||||
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination,
|
||||
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset,
|
||||
int32_t addend, const void *destination,
|
||||
const std::string &name, const ImportRPLInformation &rplInfo) {
|
||||
dyn_linking_import_t *importInfoGbl = DynamicLinkingHelper::getOrAddImport(linking_data, rplInfo.getName().c_str(), rplInfo.isData());
|
||||
if (importInfoGbl == nullptr) {
|
||||
@ -83,7 +83,8 @@ bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *link
|
||||
return addReloationEntry(linking_entries, linking_entry_length, type, offset, addend, destination, functionInfo, importInfoGbl);
|
||||
}
|
||||
|
||||
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination, dyn_linking_function_t *functionName,
|
||||
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination,
|
||||
dyn_linking_function_t *functionName,
|
||||
dyn_linking_import_t *importInfo) {
|
||||
for (uint32_t i = 0; i < linking_entry_length; i++) {
|
||||
dyn_linking_relocation_entry_t *curEntry = &(linking_entries[i]);
|
||||
|
@ -49,10 +49,12 @@ public:
|
||||
static bool addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, const RelocationData &relocationData);
|
||||
|
||||
static bool
|
||||
addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination, const std::string &name,
|
||||
addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend,
|
||||
const void *destination, const std::string &name,
|
||||
const ImportRPLInformation &rplInfo);
|
||||
|
||||
static bool addReloationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination, dyn_linking_function_t *functionName,
|
||||
static bool addReloationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination,
|
||||
dyn_linking_function_t *functionName,
|
||||
dyn_linking_import_t *importInfo);
|
||||
|
||||
private:
|
||||
|
@ -23,7 +23,8 @@
|
||||
class FunctionData {
|
||||
|
||||
public:
|
||||
FunctionData(void *paddress, void *vaddress, const std::string &name, function_replacement_library_type_t library, void *replaceAddr, void *replaceCall, FunctionPatcherTargetProcess targetProcess) {
|
||||
FunctionData(void *paddress, void *vaddress, const std::string &name, function_replacement_library_type_t library, void *replaceAddr, void *replaceCall,
|
||||
FunctionPatcherTargetProcess targetProcess) {
|
||||
this->paddress = paddress;
|
||||
this->vaddress = vaddress;
|
||||
this->name = name;
|
||||
|
@ -6,9 +6,6 @@
|
||||
#include "PluginContainerPersistence.h"
|
||||
#include "PluginDataPersistence.h"
|
||||
#include "DynamicLinkingHelper.h"
|
||||
#include "../common/plugin_defines.h"
|
||||
#include "PluginInformation.h"
|
||||
#include "RelocationData.h"
|
||||
|
||||
bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformation, PluginContainer &plugin) {
|
||||
int32_t plugin_count = pluginInformation->number_used_plugins;
|
||||
@ -135,17 +132,17 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
|
||||
for (auto &curSection: pluginInfo.getSectionInfoList()) {
|
||||
bool foundFreeSlot = false;
|
||||
uint32_t slot = 0;
|
||||
for (uint32_t i = 0; i < MAXIMUM_PLUGIN_SECTION_LENGTH; i++) {
|
||||
plugin_section_info_t *sectionInfo = &(plugin_data->info.sectionInfos[i]);
|
||||
for (uint32_t j = 0; j < MAXIMUM_PLUGIN_SECTION_LENGTH; j++) {
|
||||
plugin_section_info_t *sectionInfo = &(plugin_data->info.sectionInfos[j]);
|
||||
if (sectionInfo->addr == 0 && sectionInfo->size == 0) {
|
||||
foundFreeSlot = true;
|
||||
slot = i;
|
||||
slot = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (foundFreeSlot) {
|
||||
plugin_section_info_t *sectionInfo = &(plugin_data->info.sectionInfos[slot]);
|
||||
if (strlen(curSection.first.c_str()) > MAXIMUM_PLUGIN_SECTION_NAME_LENGTH - 1) {
|
||||
if (curSection.first.length() > MAXIMUM_PLUGIN_SECTION_NAME_LENGTH - 1) {
|
||||
DEBUG_FUNCTION_LINE("Could not add section info \"%s\" for plugin \"%s\" section name is too long.", curSection.first.c_str(), pluginName.c_str());
|
||||
break;
|
||||
}
|
||||
@ -180,7 +177,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
|
||||
std::vector<PluginContainer> PluginContainerPersistence::loadPlugins(plugin_information_t *pluginInformation) {
|
||||
std::vector<PluginContainer> result;
|
||||
if (pluginInformation == nullptr) {
|
||||
DEBUG_FUNCTION_LINE("pluginInformation == NULL");
|
||||
DEBUG_FUNCTION_LINE("pluginInformation == nullptr");
|
||||
return result;
|
||||
}
|
||||
DCFlushRange((void *) pluginInformation, sizeof(plugin_information_t));
|
||||
@ -250,38 +247,30 @@ std::vector<PluginContainer> PluginContainerPersistence::loadPlugins(plugin_info
|
||||
|
||||
for (uint32_t j = 0; j < functionReplaceCount; j++) {
|
||||
function_replacement_data_t *entry = &(plugin_data->info.functions[j]);
|
||||
FunctionData func((void *) entry->physicalAddr, (void *) entry->virtualAddr, entry->function_name, (function_replacement_library_type_t) entry->library, (void *) entry->replaceAddr, (void *) entry->replaceCall, entry->targetProcess);
|
||||
FunctionData func((void *) entry->physicalAddr, (void *) entry->virtualAddr, entry->function_name, (function_replacement_library_type_t) entry->library, (void *) entry->replaceAddr,
|
||||
(void *) entry->replaceCall, entry->targetProcess);
|
||||
curPluginInformation.addFunctionData(func);
|
||||
}
|
||||
|
||||
/* load relocation data */
|
||||
for (auto & linking_entrie : plugin_data->info.linking_entries) {
|
||||
dyn_linking_relocation_entry_t *linking_entry = &linking_entrie;
|
||||
if (linking_entry->destination == nullptr) {
|
||||
for (auto &linking_entry: plugin_data->info.linking_entries) {
|
||||
if (linking_entry.destination == nullptr) {
|
||||
break;
|
||||
}
|
||||
dyn_linking_import_t *importEntry = linking_entry->importEntry;
|
||||
dyn_linking_import_t *importEntry = linking_entry.importEntry;
|
||||
if (importEntry == nullptr) {
|
||||
DEBUG_FUNCTION_LINE("importEntry was NULL, skipping relocation entry");
|
||||
DEBUG_FUNCTION_LINE("importEntry was nullptr, skipping relocation entry");
|
||||
continue;
|
||||
}
|
||||
if (importEntry->importName == nullptr) {
|
||||
DEBUG_FUNCTION_LINE("importEntry->importName was NULL, skipping relocation entry");
|
||||
continue;
|
||||
}
|
||||
dyn_linking_function_t *functionEntry = linking_entry->functionEntry;
|
||||
dyn_linking_function_t *functionEntry = linking_entry.functionEntry;
|
||||
|
||||
if (functionEntry == nullptr) {
|
||||
DEBUG_FUNCTION_LINE("functionEntry was NULL, skipping relocation entry");
|
||||
continue;
|
||||
}
|
||||
if (functionEntry->functionName == nullptr) {
|
||||
DEBUG_FUNCTION_LINE("functionEntry->functionName was NULL, skipping relocation entry");
|
||||
DEBUG_FUNCTION_LINE("functionEntry was nullptr, skipping relocation entry");
|
||||
continue;
|
||||
}
|
||||
ImportRPLInformation rplInfo(importEntry->importName, importEntry->isData);
|
||||
std::string functionName(functionEntry->functionName);
|
||||
RelocationData reloc(linking_entry->type, linking_entry->offset, linking_entry->addend, linking_entry->destination, functionName, rplInfo);
|
||||
RelocationData reloc(linking_entry.type, linking_entry.offset, linking_entry.addend, linking_entry.destination, functionName, rplInfo);
|
||||
curPluginInformation.addRelocationData(reloc);
|
||||
}
|
||||
|
||||
|
@ -21,21 +21,17 @@
|
||||
#include <coreinit/cache.h>
|
||||
#include <coreinit/memexpheap.h>
|
||||
#include <wups.h>
|
||||
#include <whb/file.h>
|
||||
#include "PluginData.h"
|
||||
#include "PluginInformationFactory.h"
|
||||
#include "HookData.h"
|
||||
#include "SectionInfo.h"
|
||||
#include "../elfio/elfio.hpp"
|
||||
#include "../utils/utils.h"
|
||||
#include "../utils/ElfUtils.h"
|
||||
#include "../utils/StringTools.h"
|
||||
|
||||
using namespace ELFIO;
|
||||
|
||||
std::optional<PluginInformation> PluginInformationFactory::load(const PluginData &pluginData, MEMHeapHandle heapHandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId) {
|
||||
std::optional<PluginInformation>
|
||||
PluginInformationFactory::load(const PluginData &pluginData, MEMHeapHandle heapHandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId) {
|
||||
if (pluginData.buffer == nullptr) {
|
||||
DEBUG_FUNCTION_LINE("Buffer was NULL");
|
||||
DEBUG_FUNCTION_LINE("Buffer was nullptr");
|
||||
return std::nullopt;
|
||||
}
|
||||
elfio reader;
|
||||
@ -62,7 +58,7 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
|
||||
|
||||
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
|
||||
uint32_t sectionSize = psec->get_size();
|
||||
uint32_t address = (uint32_t) psec->get_address();
|
||||
auto address = (uint32_t) psec->get_address();
|
||||
if ((address >= 0x02000000) && address < 0x10000000) {
|
||||
text_size += sectionSize;
|
||||
} else if ((address >= 0x10000000) && address < 0xC0000000) {
|
||||
@ -89,8 +85,6 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
|
||||
}
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Allocated %d kb from ExpHeap", data_size / 1024);
|
||||
|
||||
uint32_t entrypoint = (uint32_t) text_data + (uint32_t) reader.get_entry() - 0x02000000;
|
||||
|
||||
for (uint32_t i = 0; i < sec_num; ++i) {
|
||||
section *psec = reader.sections[i];
|
||||
if (psec->get_type() == 0x80000002) {
|
||||
@ -99,7 +93,7 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
|
||||
|
||||
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
|
||||
uint32_t sectionSize = psec->get_size();
|
||||
uint32_t address = (uint32_t) psec->get_address();
|
||||
auto address = (uint32_t) psec->get_address();
|
||||
|
||||
uint32_t destination = address;
|
||||
if ((address >= 0x02000000) && address < 0x10000000) {
|
||||
@ -173,8 +167,6 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
|
||||
|
||||
pluginInfo.setTrampolinId(trampolinId);
|
||||
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Saved entrypoint as %08X", entrypoint);
|
||||
|
||||
std::optional<SectionInfo> secInfo = pluginInfo.getSectionInfo(".wups.hooks");
|
||||
if (secInfo && secInfo->getSize() > 0) {
|
||||
size_t entries_count = secInfo->getSize() / sizeof(wups_loader_hook_t);
|
||||
@ -193,12 +185,15 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
|
||||
if (secInfo && secInfo->getSize() > 0) {
|
||||
size_t entries_count = secInfo->getSize() / sizeof(wups_loader_entry_t);
|
||||
auto *entries = (wups_loader_entry_t *) secInfo->getAddress();
|
||||
if (entries != NULL) {
|
||||
if (entries != nullptr) {
|
||||
for (size_t j = 0; j < entries_count; j++) {
|
||||
wups_loader_entry_t *cur_function = &entries[j];
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Saving function \"%s\" of plugin . PA:%08X VA:%08X Library: %08X, target: %08X, call_addr: %08X", cur_function->_function.name/*,pluginData.getPluginInformation()->getName().c_str()*/,
|
||||
cur_function->_function.physical_address, cur_function->_function.virtual_address, cur_function->_function.library, cur_function->_function.target, (void *) cur_function->_function.call_addr);
|
||||
FunctionData function_data((void *) cur_function->_function.physical_address, (void *) cur_function->_function.virtual_address, cur_function->_function.name, (function_replacement_library_type_t) cur_function->_function.library,
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Saving function \"%s\" of plugin . PA:%08X VA:%08X Library: %08X, target: %08X, call_addr: %08X",
|
||||
cur_function->_function.name/*,pluginData.getPluginInformation()->getName().c_str()*/,
|
||||
cur_function->_function.physical_address, cur_function->_function.virtual_address, cur_function->_function.library, cur_function->_function.target,
|
||||
(void *) cur_function->_function.call_addr);
|
||||
FunctionData function_data((void *) cur_function->_function.physical_address, (void *) cur_function->_function.virtual_address, cur_function->_function.name,
|
||||
(function_replacement_library_type_t) cur_function->_function.library,
|
||||
(void *) cur_function->_function.target, (void *) cur_function->_function.call_addr, (FunctionPatcherTargetProcess) cur_function->_function.targetProcess);
|
||||
pluginInfo.addFunctionData(function_data);
|
||||
}
|
||||
@ -244,7 +239,7 @@ std::vector<RelocationData> PluginInformationFactory::getImportRelocationData(co
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t adjusted_sym_value = (uint32_t) sym_value;
|
||||
auto adjusted_sym_value = (uint32_t) sym_value;
|
||||
if (adjusted_sym_value < 0xC0000000) {
|
||||
continue;
|
||||
}
|
||||
@ -254,7 +249,7 @@ std::vector<RelocationData> PluginInformationFactory::getImportRelocationData(co
|
||||
|
||||
bool isData = false;
|
||||
|
||||
std::string rplName = "";
|
||||
std::string rplName;
|
||||
std::string rawSectionName = infoMap[sym_section_index];
|
||||
|
||||
if (rawSectionName.size() < fimport.size()) {
|
||||
@ -274,14 +269,15 @@ std::vector<RelocationData> PluginInformationFactory::getImportRelocationData(co
|
||||
|
||||
uint32_t section_index = psec->get_info();
|
||||
|
||||
result.push_back(RelocationData(type, offset - 0x02000000, addend, (void *) (destinations[section_index]), sym_name, rplInfo));
|
||||
result.emplace_back(type, offset - 0x02000000, addend, (void *) (destinations[section_index]), sym_name, rplInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
|
||||
bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data,
|
||||
uint32_t trampolin_data_length,
|
||||
uint8_t trampolinId) {
|
||||
uint32_t sec_num = reader.sections.size();
|
||||
|
||||
@ -303,7 +299,7 @@ bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t adjusted_sym_value = (uint32_t) sym_value;
|
||||
auto adjusted_sym_value = (uint32_t) sym_value;
|
||||
if ((adjusted_sym_value >= 0x02000000) && adjusted_sym_value < 0x10000000) {
|
||||
adjusted_sym_value -= 0x02000000;
|
||||
adjusted_sym_value += base_text;
|
||||
@ -321,7 +317,7 @@ bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t adjusted_offset = (uint32_t) offset;
|
||||
auto adjusted_offset = (uint32_t) offset;
|
||||
if ((offset >= 0x02000000) && offset < 0x10000000) {
|
||||
adjusted_offset -= 0x02000000;
|
||||
} else if ((adjusted_offset >= 0x10000000) && adjusted_offset < 0xC0000000) {
|
||||
@ -336,9 +332,8 @@ bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section
|
||||
DEBUG_FUNCTION_LINE("NOT IMPLEMENTED: %04X", sym_section_index);
|
||||
return false;
|
||||
}
|
||||
if (false) {
|
||||
DEBUG_FUNCTION_LINE("sym_value %08X adjusted_sym_value %08X offset %08X adjusted_offset %08X", (uint32_t) sym_value, adjusted_sym_value, (uint32_t) offset, adjusted_offset);
|
||||
}
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("sym_value %08X adjusted_sym_value %08X offset %08X adjusted_offset %08X", (uint32_t) sym_value, adjusted_sym_value, (uint32_t) offset, adjusted_offset);
|
||||
|
||||
if (!ElfUtils::elfLinkOne(type, adjusted_offset, addend, destination, adjusted_sym_value, trampolin_data, trampolin_data_length, RELOC_TYPE_FIXED, trampolinId)) {
|
||||
DEBUG_FUNCTION_LINE("Link failed");
|
||||
return false;
|
||||
|
@ -29,9 +29,12 @@
|
||||
|
||||
class PluginInformationFactory {
|
||||
public:
|
||||
static std::optional<PluginInformation> load(const PluginData &pluginData, MEMHeapHandle heaphandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId);
|
||||
static std::optional<PluginInformation>
|
||||
load(const PluginData &pluginData, MEMHeapHandle heaphandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId);
|
||||
|
||||
static bool linkSection(const elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId);
|
||||
static bool
|
||||
linkSection(const elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
|
||||
uint8_t trampolinId);
|
||||
|
||||
static std::vector<RelocationData> getImportRelocationData(const elfio &reader, uint8_t **destinations);
|
||||
};
|
||||
|
@ -24,38 +24,38 @@ class PluginMetaInformation {
|
||||
public:
|
||||
PluginMetaInformation(const PluginMetaInformation &other);
|
||||
|
||||
[[nodiscard]] std::string getName() const {
|
||||
[[nodiscard]] const std::string &getName() const {
|
||||
return name;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string getAuthor() const {
|
||||
[[nodiscard]] const std::string &getAuthor() const {
|
||||
return this->author;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string getVersion() const {
|
||||
[[nodiscard]] const std::string &getVersion() const {
|
||||
return this->version;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string getLicense() const {
|
||||
[[nodiscard]] const std::string &getLicense() const {
|
||||
return this->license;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string getBuildTimestamp() const {
|
||||
[[nodiscard]] const std::string &getBuildTimestamp() const {
|
||||
return this->buildtimestamp;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string getDescription() const {
|
||||
[[nodiscard]] const std::string &getDescription() const {
|
||||
return this->description;
|
||||
}
|
||||
|
||||
[[nodiscard]] const std::string &getId() const {
|
||||
return this->id;
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t getSize() const {
|
||||
return this->size;
|
||||
}
|
||||
|
||||
[[nodiscard]] const std::string getId() const {
|
||||
return this->id;
|
||||
}
|
||||
|
||||
private:
|
||||
PluginMetaInformation() = default;
|
||||
|
||||
@ -87,8 +87,8 @@ private:
|
||||
this->size = _size;
|
||||
}
|
||||
|
||||
void setId(const std::string &id) {
|
||||
this->id = id;
|
||||
void setId(const std::string &_id) {
|
||||
this->id = _id;
|
||||
}
|
||||
|
||||
std::string name;
|
||||
|
@ -28,8 +28,8 @@
|
||||
using namespace ELFIO;
|
||||
|
||||
std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(const PluginData &pluginData) {
|
||||
if (pluginData.buffer == NULL) {
|
||||
DEBUG_FUNCTION_LINE("Buffer was NULL");
|
||||
if (pluginData.buffer == nullptr) {
|
||||
DEBUG_FUNCTION_LINE("Buffer was nullptr");
|
||||
return std::nullopt;
|
||||
}
|
||||
elfio reader;
|
||||
@ -72,7 +72,7 @@ std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(co
|
||||
// Calculate total size:
|
||||
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
|
||||
uint32_t sectionSize = psec->get_size();
|
||||
uint32_t address = (uint32_t) psec->get_address();
|
||||
auto address = (uint32_t) psec->get_address();
|
||||
if ((address >= 0x02000000) && address < 0x10000000) {
|
||||
pluginSize += sectionSize;
|
||||
} else if ((address >= 0x10000000) && address < 0xC0000000) {
|
||||
@ -98,22 +98,22 @@ std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(co
|
||||
std::string key(curEntry);
|
||||
std::string value(curEntry + firstFound + 1);
|
||||
|
||||
if (key.compare("name") == 0) {
|
||||
if (key == "name") {
|
||||
pluginInfo.setName(value);
|
||||
} else if (key.compare("author") == 0) {
|
||||
} else if (key == "author") {
|
||||
pluginInfo.setAuthor(value);
|
||||
} else if (key.compare("version") == 0) {
|
||||
} else if (key == "version") {
|
||||
pluginInfo.setVersion(value);
|
||||
} else if (key.compare("license") == 0) {
|
||||
} else if (key == "license") {
|
||||
pluginInfo.setLicense(value);
|
||||
} else if (key.compare("buildtimestamp") == 0) {
|
||||
} else if (key == "buildtimestamp") {
|
||||
pluginInfo.setBuildTimestamp(value);
|
||||
} else if (key.compare("description") == 0) {
|
||||
} else if (key == "description") {
|
||||
pluginInfo.setDescription(value);
|
||||
} else if (key.compare("id") == 0) {
|
||||
} else if (key == "id") {
|
||||
pluginInfo.setId(value);
|
||||
} else if (key.compare("wups") == 0) {
|
||||
if (value.compare("0.6") != 0) {
|
||||
} else if (key == "wups") {
|
||||
if (value != "0.6") {
|
||||
DEBUG_FUNCTION_LINE("Warning: Ignoring plugin - Unsupported WUPS version: %s.", value.c_str());
|
||||
return std::nullopt;
|
||||
}
|
||||
|
@ -4,16 +4,13 @@
|
||||
#include "../config/WUPSConfig.h"
|
||||
#include "../globals.h"
|
||||
#include "DrawUtils.h"
|
||||
#include "StringTools.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <coreinit/screen.h>
|
||||
#include <coreinit/cache.h>
|
||||
#include <memory/mappedmemory.h>
|
||||
#include <vpad/input.h>
|
||||
#include <padscore/kpad.h>
|
||||
#include <padscore/wpad.h>
|
||||
#include <gx2/display.h>
|
||||
|
||||
#define COLOR_BACKGROUND Color(238, 238, 238, 255)
|
||||
@ -26,17 +23,16 @@
|
||||
#define COLOR_BLACK Color(0, 0, 0, 255)
|
||||
|
||||
struct ConfigDisplayItem {
|
||||
WUPSConfig* config;
|
||||
WUPSConfig *config{};
|
||||
std::string name;
|
||||
std::string author;
|
||||
std::string version;
|
||||
bool enabled;
|
||||
bool enabled{};
|
||||
};
|
||||
|
||||
#define MAX_BUTTONS_ON_SCREEN 8
|
||||
|
||||
static uint32_t remapWiiMoteButtons(uint32_t buttons)
|
||||
{
|
||||
static uint32_t remapWiiMoteButtons(uint32_t buttons) {
|
||||
uint32_t conv_buttons = 0;
|
||||
|
||||
if (buttons & WPAD_BUTTON_LEFT)
|
||||
@ -69,8 +65,7 @@ static uint32_t remapWiiMoteButtons(uint32_t buttons)
|
||||
return conv_buttons;
|
||||
}
|
||||
|
||||
static uint32_t remapClassicButtons(uint32_t buttons)
|
||||
{
|
||||
static uint32_t remapClassicButtons(uint32_t buttons) {
|
||||
uint32_t conv_buttons = 0;
|
||||
|
||||
if (buttons & WPAD_CLASSIC_BUTTON_LEFT)
|
||||
@ -140,17 +135,11 @@ void ConfigUtils::displayMenu() {
|
||||
if (hook_data->func_pointer == nullptr) {
|
||||
break;
|
||||
}
|
||||
WUPSConfig *cur_config = reinterpret_cast<WUPSConfig *>(((WUPSConfigHandle (*)()) ((uint32_t *) hook_data->func_pointer))());
|
||||
auto *cur_config = reinterpret_cast<WUPSConfig *>(((WUPSConfigHandle (*)()) ((uint32_t *) hook_data->func_pointer))());
|
||||
if (cur_config == nullptr) {
|
||||
break;
|
||||
}
|
||||
|
||||
//if(cur_config > 0x8000000);
|
||||
//DCFlushRange(&cur_config, sizeof(WUPSConfig*));
|
||||
//DCFlushRange(cur_config, sizeof(WUPSConfig));
|
||||
cfg.config = cur_config;
|
||||
|
||||
DEBUG_FUNCTION_LINE("name %s author %s version %s enabled %d config %08X",cfg.name.c_str(),cfg.author.c_str(),cfg.version.c_str(),cfg.enabled, cfg.config)
|
||||
configs.push_back(cfg);
|
||||
break;
|
||||
}
|
||||
@ -211,8 +200,7 @@ void ConfigUtils::displayMenu() {
|
||||
selectedBtn++;
|
||||
redraw = true;
|
||||
}
|
||||
}
|
||||
else if (buttonsTriggered & VPAD_BUTTON_UP) {
|
||||
} else if (buttonsTriggered & VPAD_BUTTON_UP) {
|
||||
if (selectedBtn > 0) {
|
||||
selectedBtn--;
|
||||
redraw = true;
|
||||
@ -221,11 +209,9 @@ void ConfigUtils::displayMenu() {
|
||||
if (buttonsTriggered & VPAD_BUTTON_X) {
|
||||
configs[selectedBtn].enabled = !configs[selectedBtn].enabled;
|
||||
redraw = true;
|
||||
}
|
||||
else if (buttonsTriggered & VPAD_BUTTON_A) {
|
||||
} else if (buttonsTriggered & VPAD_BUTTON_A) {
|
||||
currentConfig = &configs[selectedBtn];
|
||||
if (currentConfig == nullptr) {
|
||||
DEBUG_FUNCTION_LINE("BYEBYE");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -245,8 +231,7 @@ void ConfigUtils::displayMenu() {
|
||||
if (selectedBtn >= end) {
|
||||
end = selectedBtn + 1;
|
||||
start = end - MAX_BUTTONS_ON_SCREEN;
|
||||
}
|
||||
else if (selectedBtn < start) {
|
||||
} else if (selectedBtn < start) {
|
||||
start = selectedBtn;
|
||||
end = start + MAX_BUTTONS_ON_SCREEN;
|
||||
}
|
||||
@ -319,22 +304,20 @@ void ConfigUtils::displayMenu() {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (!currentCategory) {
|
||||
auto cats = currentConfig->config->getCategories();
|
||||
|
||||
if (buttonsTriggered & VPAD_BUTTON_DOWN) {
|
||||
if (selectedBtn < cats.size() - 1) {
|
||||
selectedBtn++;
|
||||
redraw = true;
|
||||
}
|
||||
}
|
||||
else if (buttonsTriggered & VPAD_BUTTON_UP) {
|
||||
} else if (buttonsTriggered & VPAD_BUTTON_UP) {
|
||||
if (selectedBtn > 0) {
|
||||
selectedBtn--;
|
||||
redraw = true;
|
||||
}
|
||||
}
|
||||
else if (buttonsTriggered & VPAD_BUTTON_A) {
|
||||
} else if (buttonsTriggered & VPAD_BUTTON_A) {
|
||||
currentCategory = cats[selectedBtn];
|
||||
if (currentCategory == nullptr) {
|
||||
DEBUG_FUNCTION_LINE("BYEBYE");
|
||||
@ -368,8 +351,7 @@ void ConfigUtils::displayMenu() {
|
||||
if (selectedBtn >= end) {
|
||||
end = selectedBtn + 1;
|
||||
start = end - MAX_BUTTONS_ON_SCREEN;
|
||||
}
|
||||
else if (selectedBtn < start) {
|
||||
} else if (selectedBtn < start) {
|
||||
start = selectedBtn;
|
||||
end = start + MAX_BUTTONS_ON_SCREEN;
|
||||
}
|
||||
@ -441,14 +423,12 @@ void ConfigUtils::displayMenu() {
|
||||
selectedBtn++;
|
||||
redraw = true;
|
||||
}
|
||||
}
|
||||
else if (buttonsTriggered & VPAD_BUTTON_UP) {
|
||||
} else if (buttonsTriggered & VPAD_BUTTON_UP) {
|
||||
if (selectedBtn > 0) {
|
||||
selectedBtn--;
|
||||
redraw = true;
|
||||
}
|
||||
}
|
||||
else if (buttonsTriggered & VPAD_BUTTON_B) {
|
||||
} else if (buttonsTriggered & VPAD_BUTTON_B) {
|
||||
currentCategory = nullptr;
|
||||
selectedBtn = 0;
|
||||
start = 0;
|
||||
@ -490,8 +470,7 @@ void ConfigUtils::displayMenu() {
|
||||
if (selectedBtn >= end) {
|
||||
end = selectedBtn + 1;
|
||||
start = end - MAX_BUTTONS_ON_SCREEN;
|
||||
}
|
||||
else if (selectedBtn < start) {
|
||||
} else if (selectedBtn < start) {
|
||||
start = selectedBtn;
|
||||
end = start + MAX_BUTTONS_ON_SCREEN;
|
||||
}
|
||||
@ -518,8 +497,7 @@ void ConfigUtils::displayMenu() {
|
||||
config_items[i]->onButtonPressed(pressedButtons);
|
||||
}
|
||||
DrawUtils::print(SCREEN_WIDTH - 16 * 2, index + 8 + 24, config_items[i]->getCurrentValueSelectedDisplay().c_str(), true);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
DrawUtils::print(SCREEN_WIDTH - 16 * 2, index + 8 + 24, config_items[i]->getCurrentValueDisplay().c_str(), true);
|
||||
}
|
||||
index += 42 + 8;
|
||||
@ -595,8 +573,7 @@ void ConfigUtils::displayMenu() {
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigUtils::openConfigMenu()
|
||||
{
|
||||
void ConfigUtils::openConfigMenu() {
|
||||
bool wasHomeButtonMenuEnabled = OSIsHomeButtonMenuEnabled();
|
||||
|
||||
OSScreenInit();
|
||||
@ -669,11 +646,9 @@ void ConfigUtils::openConfigMenu()
|
||||
}
|
||||
if (!skipScreen0Free && screenbuffer0) {
|
||||
MEMFreeToMappedMemory(screenbuffer0);
|
||||
screenbuffer0 = nullptr;
|
||||
}
|
||||
|
||||
if (!skipScreen1Free && screenbuffer1) {
|
||||
MEMFreeToMappedMemory(screenbuffer1);
|
||||
screenbuffer1 = nullptr;
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,12 @@ union Color {
|
||||
explicit Color(uint32_t color) {
|
||||
this->color = color;
|
||||
}
|
||||
|
||||
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
|
||||
this->r = r; this->g = g; this->b = b; this->a = a;
|
||||
this->r = r;
|
||||
this->g = g;
|
||||
this->b = b;
|
||||
this->a = a;
|
||||
}
|
||||
|
||||
uint32_t color{};
|
||||
@ -26,25 +30,39 @@ union Color {
|
||||
class DrawUtils {
|
||||
public:
|
||||
static void initBuffers(void *tvBuffer, uint32_t tvSize, void *drcBuffer, uint32_t drcSize);
|
||||
|
||||
static void beginDraw();
|
||||
|
||||
static void endDraw();
|
||||
|
||||
static void clear(Color col);
|
||||
|
||||
static void drawPixel(uint32_t x, uint32_t y, Color col) { drawPixel(x, y, col.r, col.g, col.b, col.a); }
|
||||
|
||||
static void drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
|
||||
|
||||
static void drawRectFilled(uint32_t x, uint32_t y, uint32_t w, uint32_t h, Color col);
|
||||
|
||||
static void drawRect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t borderSize, Color col);
|
||||
|
||||
static void drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32_t target_height, const uint8_t *data);
|
||||
|
||||
static void drawPNG(uint32_t x, uint32_t y, const uint8_t *data);
|
||||
|
||||
static void initFont();
|
||||
|
||||
static void deinitFont();
|
||||
|
||||
static void setFontSize(uint32_t size);
|
||||
|
||||
static void setFontColor(Color col);
|
||||
|
||||
static void print(uint32_t x, uint32_t y, const char *string, bool alignRight = false);
|
||||
|
||||
static void print(uint32_t x, uint32_t y, const wchar_t *string, bool alignRight = false);
|
||||
|
||||
static uint32_t getTextWidth(const char *string);
|
||||
|
||||
static uint32_t getTextWidth(const wchar_t *string);
|
||||
|
||||
private:
|
||||
|
@ -1,14 +1,12 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
#include <coreinit/cache.h>
|
||||
|
||||
#include "utils/logger.h"
|
||||
|
||||
#include "elfio/elfio.hpp"
|
||||
#include "ElfUtils.h"
|
||||
|
||||
// See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144
|
||||
bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, RelocationType reloc_type, uint8_t trampolinId) {
|
||||
bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
|
||||
RelocationType reloc_type, uint8_t trampolinId) {
|
||||
if (type == R_PPC_NONE) {
|
||||
return true;
|
||||
}
|
||||
|
@ -46,5 +46,6 @@ uint32_t load_loader_elf(unsigned char *baseAddress, char *elf_data, uint32_t fi
|
||||
class ElfUtils {
|
||||
|
||||
public:
|
||||
static bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, RelocationType reloc_type, uint8_t trampolinId);
|
||||
static bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
|
||||
RelocationType reloc_type, uint8_t trampolinId);
|
||||
};
|
||||
|
@ -5,5 +5,6 @@
|
||||
class StorageUtils {
|
||||
public:
|
||||
static int OpenStorage(const char *plugin_id, wups_storage_item_t *items);
|
||||
|
||||
static int CloseStorage(const char *plugin_id, wups_storage_item_t *items);
|
||||
};
|
||||
|
@ -25,14 +25,11 @@
|
||||
***************************************************************************/
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <cstdarg>
|
||||
#include <cstdlib>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <strings.h>
|
||||
#include <wut_types.h>
|
||||
#include <stdio.h>
|
||||
#include <cstdio>
|
||||
#include <utils/StringTools.h>
|
||||
|
||||
|
||||
@ -78,7 +75,7 @@ const char *StringTools::fmt(const char *format, ...) {
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const wchar_t *StringTools::wfmt(const char *format, ...) {
|
||||
@ -107,7 +104,7 @@ const wchar_t *StringTools::wfmt(const char *format, ...) {
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int32_t StringTools::strprintf(std::string &str, const char *format, ...) {
|
||||
@ -165,11 +162,11 @@ int32_t StringTools::strtokcmp(const char *string, const char *compare, const ch
|
||||
|
||||
char *strTok = strtok(TokCopy, separator);
|
||||
|
||||
while (strTok != NULL) {
|
||||
while (strTok != nullptr) {
|
||||
if (strcasecmp(string, strTok) == 0) {
|
||||
return 0;
|
||||
}
|
||||
strTok = strtok(NULL, separator);
|
||||
strTok = strtok(nullptr, separator);
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
@ -10,13 +10,13 @@
|
||||
#include <wums.h>
|
||||
|
||||
void fillPluginInformation(plugin_information *out, PluginMetaInformation *metaInformation) {
|
||||
strncpy(out->author, metaInformation->getAuthor().c_str(), 255);
|
||||
strncpy(out->buildTimestamp, metaInformation->getBuildTimestamp().c_str(), 255);
|
||||
strncpy(out->description, metaInformation->getDescription().c_str(), 255);
|
||||
strncpy(out->name, metaInformation->getName().c_str(), 255);
|
||||
strncpy(out->license, metaInformation->getLicense().c_str(), 255);
|
||||
strncpy(out->version, metaInformation->getVersion().c_str(), 255);
|
||||
strncpy(out->id, metaInformation->getId().c_str(), 255);
|
||||
strncpy(out->author, metaInformation->getAuthor().c_str(), sizeof(out->author) - 1);
|
||||
strncpy(out->buildTimestamp, metaInformation->getBuildTimestamp().c_str(), sizeof(out->buildTimestamp) - 1);
|
||||
strncpy(out->description, metaInformation->getDescription().c_str(), sizeof(out->description) - 1);
|
||||
strncpy(out->name, metaInformation->getName().c_str(), sizeof(out->name) - 1);
|
||||
strncpy(out->license, metaInformation->getLicense().c_str(), sizeof(out->license) - 1);
|
||||
strncpy(out->version, metaInformation->getVersion().c_str(), sizeof(out->version) - 1);
|
||||
strncpy(out->id, metaInformation->getId().c_str(), sizeof(out->id) - 1);
|
||||
out->size = metaInformation->getSize();
|
||||
}
|
||||
|
||||
@ -26,7 +26,6 @@ extern "C" PluginBackendApiErrorType WUPSLoadAndLinkByDataHandle(const plugin_da
|
||||
for (uint32_t i = 0; i < plugin_data_handle_list_size; i++) {
|
||||
plugin_data_handle handle = plugin_data_handle_list[i];
|
||||
auto *pluginData = (PluginData *) handle;
|
||||
DEBUG_FUNCTION_LINE("Saving plugin data %08X", pluginData);
|
||||
PluginDataPersistence::save(&gLinkOnReload.plugin_data[gLinkOnReload.number_used_plugins], *pluginData);
|
||||
|
||||
gLinkOnReload.number_used_plugins++;
|
||||
@ -36,6 +35,7 @@ extern "C" PluginBackendApiErrorType WUPSLoadAndLinkByDataHandle(const plugin_da
|
||||
}
|
||||
DCFlushRange(&gLinkOnReload, sizeof(gLinkOnReload));
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_INVALID_ARG");
|
||||
return PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
|
||||
}
|
||||
return PLUGIN_BACKEND_API_ERROR_NONE;
|
||||
@ -46,7 +46,6 @@ extern "C" PluginBackendApiErrorType WUPSDeletePluginContainer(const plugin_cont
|
||||
for (uint32_t i = 0; i < handle_list_size; i++) {
|
||||
auto handle = handle_list[i];
|
||||
auto *pluginContainer = (PluginContainer *) handle;
|
||||
DEBUG_FUNCTION_LINE("Delete plugin container: %08X", pluginContainer);
|
||||
delete pluginContainer;
|
||||
}
|
||||
}
|
||||
@ -58,7 +57,6 @@ extern "C" PluginBackendApiErrorType WUPSDeletePluginData(const plugin_data_hand
|
||||
for (uint32_t i = 0; i < plugin_data_handle_list_size; i++) {
|
||||
auto handle = plugin_data_handle_list[i];
|
||||
auto *pluginData = (PluginData *) handle;
|
||||
DEBUG_FUNCTION_LINE("Delete plugin data: %08X", pluginData);
|
||||
delete pluginData;
|
||||
}
|
||||
}
|
||||
@ -78,16 +76,15 @@ extern "C" PluginBackendApiErrorType WUPSLoadPluginAsData(GetPluginInformationIn
|
||||
}
|
||||
|
||||
if (!pluginData) {
|
||||
DEBUG_FUNCTION_LINE("Failed to alloc plugin data");
|
||||
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_FAILED_ALLOC");
|
||||
return PLUGIN_BACKEND_API_ERROR_FAILED_ALLOC;
|
||||
}
|
||||
|
||||
if (out == nullptr) {
|
||||
DEBUG_FUNCTION_LINE("out was NULL");
|
||||
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_INVALID_ARG");
|
||||
return PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
|
||||
} else {
|
||||
auto *pluginDataHandle = new PluginData(pluginData.value());
|
||||
DEBUG_FUNCTION_LINE("Saving plugin data handle: %08X", pluginDataHandle);
|
||||
*out = (uint32_t) pluginDataHandle;
|
||||
}
|
||||
|
||||
@ -106,23 +103,21 @@ extern "C" PluginBackendApiErrorType WUPSGetPluginMetaInformation(GetPluginInfor
|
||||
std::optional<PluginMetaInformation> pluginInfo;
|
||||
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(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 {
|
||||
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_INVALID_ARG");
|
||||
return PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (!pluginInfo) {
|
||||
DEBUG_FUNCTION_LINE("Failed to load plugin meta information");
|
||||
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_FILE_NOT_FOUND");
|
||||
return PLUGIN_BACKEND_API_ERROR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
DEBUG_FUNCTION_LINE("Loaded plugin meta information");
|
||||
|
||||
if (output == nullptr) {
|
||||
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_INVALID_ARG");
|
||||
return PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
|
||||
} else {
|
||||
fillPluginInformation(output, &pluginInfo.value());
|
||||
@ -145,10 +140,10 @@ extern "C" PluginBackendApiErrorType WUPSGetPluginDataForContainerHandles(const
|
||||
auto handle = plugin_container_handle_list[i];
|
||||
auto *container = (PluginContainer *) handle;
|
||||
auto *pluginData = new PluginData(container->getPluginData());
|
||||
DEBUG_FUNCTION_LINE("Created pluginData [%08X]", pluginData);
|
||||
plugin_data_list[i] = (uint32_t) pluginData;
|
||||
}
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_INVALID_ARG");
|
||||
res = PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
|
||||
}
|
||||
return res;
|
||||
@ -171,6 +166,7 @@ extern "C" PluginBackendApiErrorType WUPSGetMetaInformation(const plugin_contain
|
||||
plugin_information_list[i].size = container->metaInformation.getSize();
|
||||
}
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_INVALID_ARG");
|
||||
res = PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
|
||||
}
|
||||
return res;
|
||||
@ -182,7 +178,6 @@ extern "C" PluginBackendApiErrorType WUPSGetLoadedPlugins(plugin_container_handl
|
||||
for (auto &plugin: plugins) {
|
||||
if (counter < buffer_size) {
|
||||
auto *container = new PluginContainer(plugin);
|
||||
DEBUG_FUNCTION_LINE("Created container [%08X]", container);
|
||||
io_handles[counter] = (uint32_t) container;
|
||||
counter++;
|
||||
} else {
|
||||
|
@ -16,11 +16,11 @@ extern "C" {
|
||||
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
|
||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
|
||||
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
|
||||
} while (0);
|
||||
} while (0)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
|
||||
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
|
||||
} while (0);
|
||||
} while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user