From 7d07f6525bdbaebfae72a50cc138da236c87170e Mon Sep 17 00:00:00 2001 From: Maschell Date: Sun, 24 Mar 2024 07:40:58 +0100 Subject: [PATCH] Remove unnecessary std::unique_ptr usages --- source/PluginManagement.cpp | 50 ++++----- source/PluginManagement.h | 12 +- source/config/WUPSConfigAPI.cpp | 4 +- source/globals.cpp | 2 +- source/globals.h | 2 +- source/hooks.cpp | 10 +- source/hooks.h | 2 +- source/main.cpp | 16 +-- source/patcher/hooks_patcher_static.cpp | 14 +-- source/plugin/PluginConfigData.h | 6 +- source/plugin/PluginContainer.h | 43 ++++++- source/plugin/PluginInformation.h | 91 ++++++++++----- source/plugin/PluginInformationFactory.cpp | 106 ++++++------------ source/plugin/PluginInformationFactory.h | 2 +- source/plugin/PluginMetaInformation.cpp | 13 --- source/plugin/PluginMetaInformation.h | 2 - .../plugin/PluginMetaInformationFactory.cpp | 32 +++--- source/plugin/PluginMetaInformationFactory.h | 6 +- source/plugin/WUPSVersion.h | 2 - source/utils/config/ConfigUtils.cpp | 30 ++--- source/utils/exports.cpp | 28 ++--- 21 files changed, 244 insertions(+), 229 deletions(-) delete mode 100644 source/plugin/PluginMetaInformation.cpp diff --git a/source/PluginManagement.cpp b/source/PluginManagement.cpp index ec4bdf6..bffd23a 100644 --- a/source/PluginManagement.cpp +++ b/source/PluginManagement.cpp @@ -12,9 +12,9 @@ #include #include -std::vector> +std::vector PluginManagement::loadPlugins(const std::set> &pluginDataList, std::vector &trampolineData) { - std::vector> plugins; + std::vector plugins; uint32_t trampolineID = 0; for (const auto &pluginData : pluginDataList) { @@ -29,13 +29,7 @@ PluginManagement::loadPlugins(const std::set> &plugi DisplayErrorNotificationMessage(errMsg, 15.0f); continue; } - std::string nameCpy = metaInfo->getName(); - auto container = make_unique_nothrow(std::move(metaInfo), std::move(info), pluginData); - if (!container) { - DEBUG_FUNCTION_LINE_ERR("Failed to create PluginContainer, skipping %s", nameCpy.c_str()); - continue; - } - plugins.push_back(std::move(container)); + plugins.emplace_back(std::move(*metaInfo), std::move(*info), pluginData); } else { auto errMsg = string_format("Failed to load plugin: %s", pluginData->getSource().c_str()); if (error == PLUGIN_PARSE_ERROR_INCOMPATIBLE_VERSION) { @@ -54,13 +48,13 @@ PluginManagement::loadPlugins(const std::set> &plugi return plugins; } -bool PluginManagement::doRelocation(const std::vector> &relocData, +bool PluginManagement::doRelocation(const std::vector &relocData, std::vector &trampData, uint32_t trampolineID, std::map &usedRPls) { for (auto const &cur : relocData) { uint32_t functionAddress = 0; - auto &functionName = cur->getName(); + auto &functionName = cur.getName(); if (functionName == "MEMAllocFromDefaultHeap") { OSDynLoad_Module rplHandle; @@ -77,8 +71,8 @@ bool PluginManagement::doRelocation(const std::vectorgetImportRPLInformation().getRPLName(); - int32_t isData = cur->getImportRPLInformation().isData(); + auto rplName = cur.getImportRPLInformation().getRPLName(); + int32_t isData = cur.getImportRPLInformation().isData(); OSDynLoad_Module rplHandle = nullptr; if (!usedRPls.contains(rplName)) { @@ -106,7 +100,7 @@ bool PluginManagement::doRelocation(const std::vectorgetType(), cur->getOffset(), cur->getAddend(), (uint32_t) cur->getDestination(), functionAddress, trampData, RELOC_TYPE_IMPORT, trampolineID)) { + if (!ElfUtils::elfLinkOne(cur.getType(), cur.getOffset(), cur.getAddend(), (uint32_t) cur.getDestination(), functionAddress, trampData, RELOC_TYPE_IMPORT, trampolineID)) { DEBUG_FUNCTION_LINE_ERR("elfLinkOne failed"); return false; } @@ -127,7 +121,7 @@ bool PluginManagement::doRelocation(const std::vector> &plugins, +bool PluginManagement::doRelocations(const std::vector &plugins, std::vector &trampData, std::map &usedRPls) { for (auto &cur : trampData) { @@ -143,10 +137,10 @@ bool PluginManagement::doRelocations(const std::vectorgetMetaInformation().getName().c_str()); - if (!PluginManagement::doRelocation(pluginContainer->getPluginInformation().getRelocationDataList(), + DEBUG_FUNCTION_LINE_VERBOSE("Doing relocations for plugin: %s", pluginContainer.getMetaInformation().getName().c_str()); + if (!PluginManagement::doRelocation(pluginContainer.getPluginInformation().getRelocationDataList(), trampData, - pluginContainer->getPluginInformation().getTrampolineId(), + pluginContainer.getPluginInformation().getTrampolineId(), usedRPls)) { return false; } @@ -157,10 +151,10 @@ bool PluginManagement::doRelocations(const std::vector> &plugins) { - for (const auto &cur : std::ranges::reverse_view(plugins)) { - for (const auto &curFunction : std::ranges::reverse_view(cur->getPluginInformation().getFunctionDataList())) { - if (!curFunction->RemovePatch()) { +bool PluginManagement::RestoreFunctionPatches(std::vector &plugins) { + for (auto &cur : std::ranges::reverse_view(plugins)) { + for (auto &curFunction : std::ranges::reverse_view(cur.getPluginInformation().getFunctionDataList())) { + if (!curFunction.RemovePatch()) { return false; } } @@ -168,11 +162,11 @@ bool PluginManagement::RestoreFunctionPatches(const std::vector> &plugins) { - for (const auto &cur : plugins) { - for (const auto &curFunction : cur->getPluginInformation().getFunctionDataList()) { - if (!curFunction->AddPatch()) { - DEBUG_FUNCTION_LINE_ERR("Failed to add function patch for: plugin %s", cur->getMetaInformation().getName().c_str()); +bool PluginManagement::DoFunctionPatches(std::vector &plugins) { + for (auto &cur : plugins) { + for (auto &curFunction : cur.getPluginInformation().getFunctionDataList()) { + if (!curFunction.AddPatch()) { + DEBUG_FUNCTION_LINE_ERR("Failed to add function patch for: plugin %s", cur.getMetaInformation().getName().c_str()); return false; } } @@ -180,7 +174,7 @@ bool PluginManagement::DoFunctionPatches(const std::vector> &plugins) { +void PluginManagement::callInitHooks(const std::vector &plugins) { CallHook(plugins, WUPS_LOADER_HOOK_INIT_CONFIG); CallHook(plugins, WUPS_LOADER_HOOK_INIT_STORAGE_DEPRECATED); CallHook(plugins, WUPS_LOADER_HOOK_INIT_STORAGE); diff --git a/source/PluginManagement.h b/source/PluginManagement.h index d71d284..f1b2d2c 100644 --- a/source/PluginManagement.h +++ b/source/PluginManagement.h @@ -9,22 +9,22 @@ class PluginManagement { public: - static std::vector> loadPlugins( + static std::vector loadPlugins( const std::set> &pluginDataList, std::vector &trampolineData); - static void callInitHooks(const std::vector> &plugins); + static void callInitHooks(const std::vector &plugins); - static bool doRelocations(const std::vector> &plugins, + static bool doRelocations(const std::vector &plugins, std::vector &trampData, std::map &usedRPls); - static bool doRelocation(const std::vector> &relocData, + static bool doRelocation(const std::vector &relocData, std::vector &trampData, uint32_t trampolineID, std::map &usedRPls); - static bool DoFunctionPatches(const std::vector> &plugins); + static bool DoFunctionPatches(std::vector &plugins); - static bool RestoreFunctionPatches(const std::vector> &plugins); + static bool RestoreFunctionPatches(std::vector &plugins); }; \ No newline at end of file diff --git a/source/config/WUPSConfigAPI.cpp b/source/config/WUPSConfigAPI.cpp index ead0e3c..adc5322 100644 --- a/source/config/WUPSConfigAPI.cpp +++ b/source/config/WUPSConfigAPI.cpp @@ -140,7 +140,7 @@ namespace WUPSConfigAPIBackend { return WUPSCONFIG_API_RESULT_INVALID_ARGUMENT; } for (auto &cur : gLoadedPlugins) { - if (cur->getHandle() == pluginIdentifier) { + if (cur.getHandle() == pluginIdentifier) { if (options.version != 1) { return WUPSCONFIG_API_RESULT_UNSUPPORTED_VERSION; } @@ -149,7 +149,7 @@ namespace WUPSConfigAPIBackend { DEBUG_FUNCTION_LINE_WARN("Failed to create config data for %08X", pluginIdentifier); return WUPSCONFIG_API_RESULT_UNSUPPORTED_VERSION; } - cur->setConfigData(configDat.value()); + cur.setConfigData(configDat.value()); return WUPSCONFIG_API_RESULT_SUCCESS; } } diff --git a/source/globals.cpp b/source/globals.cpp index 18d8216..c14ec4c 100644 --- a/source/globals.cpp +++ b/source/globals.cpp @@ -3,7 +3,7 @@ StoredBuffer gStoredTVBuffer = {}; StoredBuffer gStoredDRCBuffer = {}; -std::vector> gLoadedPlugins; +std::vector gLoadedPlugins; std::vector gTrampData; std::set> gLoadedData; diff --git a/source/globals.h b/source/globals.h index 04146ca..cde7d3b 100644 --- a/source/globals.h +++ b/source/globals.h @@ -17,7 +17,7 @@ extern StoredBuffer gStoredDRCBuffer; #define TRAMP_DATA_SIZE 1024 extern std::vector gTrampData; -extern std::vector> gLoadedPlugins; +extern std::vector gLoadedPlugins; extern std::set> gLoadedData; extern std::set> gLoadOnNextLaunch; diff --git a/source/hooks.cpp b/source/hooks.cpp index 7e664b2..7a09d9f 100644 --- a/source/hooks.cpp +++ b/source/hooks.cpp @@ -35,18 +35,18 @@ static const char **hook_names = (const char *[]){ "WUPS_LOADER_HOOK_INIT_STORAGE", "WUPS_LOADER_HOOK_INIT_CONFIG"}; -void CallHook(const std::vector> &plugins, wups_loader_hook_type_t hook_type) { +void CallHook(const std::vector &plugins, wups_loader_hook_type_t hook_type) { DEBUG_FUNCTION_LINE_VERBOSE("Calling hook of type %s [%d]", hook_names[hook_type], hook_type); for (const auto &plugin : plugins) { - CallHook(*plugin, hook_type); + CallHook(plugin, hook_type); } } void CallHook(const PluginContainer &plugin, wups_loader_hook_type_t hook_type) { for (const auto &hook : plugin.getPluginInformation().getHookDataList()) { - if (hook->getType() == hook_type) { - DEBUG_FUNCTION_LINE_VERBOSE("Calling hook of type %s for plugin %s [%d]", hook_names[hook->getType()], plugin.getMetaInformation().getName().c_str(), hook_type); - void *func_ptr = hook->getFunctionPointer(); + if (hook.getType() == hook_type) { + DEBUG_FUNCTION_LINE_VERBOSE("Calling hook of type %s for plugin %s [%d]", hook_names[hook.getType()], plugin.getMetaInformation().getName().c_str(), hook_type); + void *func_ptr = hook.getFunctionPointer(); if (func_ptr != nullptr) { switch (hook_type) { case WUPS_LOADER_HOOK_INIT_WUT_MALLOC: diff --git a/source/hooks.h b/source/hooks.h index 8d426c9..24327ec 100644 --- a/source/hooks.h +++ b/source/hooks.h @@ -5,6 +5,6 @@ #include #include -void CallHook(const std::vector> &plugins, wups_loader_hook_type_t hook_type); +void CallHook(const std::vector &plugins, wups_loader_hook_type_t hook_type); void CallHook(const PluginContainer &plugin, wups_loader_hook_type_t hook_type); \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index f590a45..68fb6e1 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -67,7 +67,7 @@ WUMS_APPLICATION_ENDS() { deinitLogging(); } -void CheckCleanupCallbackUsage(const std::vector> &plugins); +void CheckCleanupCallbackUsage(const std::vector &plugins); WUMS_APPLICATION_STARTS() { uint32_t upid = OSGetUPID(); @@ -132,9 +132,9 @@ WUMS_APPLICATION_STARTS() { PluginManagement::RestoreFunctionPatches(gLoadedPlugins); for (auto &plugin : gLoadedPlugins) { - WUPSStorageError err = plugin->CloseStorage(); + WUPSStorageError err = plugin.CloseStorage(); if (err != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("Failed to close storage for plugin: %s", plugin->getMetaInformation().getName().c_str()); + DEBUG_FUNCTION_LINE_ERR("Failed to close storage for plugin: %s", plugin.getMetaInformation().getName().c_str()); } } @@ -174,9 +174,9 @@ WUMS_APPLICATION_STARTS() { if (initNeeded) { for (auto &plugin : gLoadedPlugins) { - WUPSStorageError err = plugin->OpenStorage(); + WUPSStorageError err = plugin.OpenStorage(); if (err != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("Failed to open storage for plugin: %s. (%s)", plugin->getMetaInformation().getName().c_str(), WUPSStorageAPI_GetStatusStr(err)); + DEBUG_FUNCTION_LINE_ERR("Failed to open storage for plugin: %s. (%s)", plugin.getMetaInformation().getName().c_str(), WUPSStorageAPI_GetStatusStr(err)); } } PluginManagement::callInitHooks(gLoadedPlugins); @@ -186,16 +186,16 @@ WUMS_APPLICATION_STARTS() { } } -void CheckCleanupCallbackUsage(const std::vector> &plugins) { +void CheckCleanupCallbackUsage(const std::vector &plugins) { auto *curThread = OSGetCurrentThread(); for (const auto &cur : plugins) { - auto textSection = cur->getPluginInformation().getSectionInfo(".text"); + auto textSection = cur.getPluginInformation().getSectionInfo(".text"); if (!textSection) { continue; } uint32_t startAddress = textSection->getAddress(); uint32_t endAddress = textSection->getAddress() + textSection->getSize(); - auto *pluginName = cur->getMetaInformation().getName().c_str(); + auto *pluginName = cur.getMetaInformation().getName().c_str(); { __OSLockScheduler(curThread); int state = OSDisableInterrupts(); diff --git a/source/patcher/hooks_patcher_static.cpp b/source/patcher/hooks_patcher_static.cpp index d085947..d3243d9 100644 --- a/source/patcher/hooks_patcher_static.cpp +++ b/source/patcher/hooks_patcher_static.cpp @@ -121,7 +121,7 @@ DECL_FUNCTION(uint32_t, SC17_FindClosestSymbol, char *moduleNameBuffer, uint32_t moduleNameBufferLength) { for (const auto &plugin : gLoadedPlugins) { - auto sectionInfo = plugin->getPluginInformation().getSectionInfo(".text"); + const auto sectionInfo = plugin.getPluginInformation().getSectionInfo(".text"); if (!sectionInfo) { continue; } @@ -130,8 +130,8 @@ DECL_FUNCTION(uint32_t, SC17_FindClosestSymbol, continue; } - strncpy(moduleNameBuffer, plugin->getMetaInformation().getName().c_str(), moduleNameBufferLength - 1); - auto functionSymbolData = plugin->getPluginInformation().getNearestFunctionSymbolData(addr); + strncpy(moduleNameBuffer, plugin.getMetaInformation().getName().c_str(), moduleNameBufferLength - 1); + auto functionSymbolData = plugin.getPluginInformation().getNearestFunctionSymbolData(addr); if (functionSymbolData) { strncpy(symbolNameBuffer, functionSymbolData->getName().c_str(), moduleNameBufferLength - 1); if (outDistance) { @@ -154,7 +154,7 @@ DECL_FUNCTION(uint32_t, SC17_FindClosestSymbol, DECL_FUNCTION(uint32_t, KiGetAppSymbolName, uint32_t addr, char *buffer, int32_t bufSize) { for (const auto &plugin : gLoadedPlugins) { - auto sectionInfo = plugin->getPluginInformation().getSectionInfo(".text"); + const auto sectionInfo = plugin.getPluginInformation().getSectionInfo(".text"); if (!sectionInfo) { continue; } @@ -163,14 +163,14 @@ DECL_FUNCTION(uint32_t, KiGetAppSymbolName, uint32_t addr, char *buffer, int32_t continue; } - auto pluginNameLen = strlen(plugin->getMetaInformation().getName().c_str()); + auto pluginNameLen = strlen(plugin.getMetaInformation().getName().c_str()); int32_t spaceLeftInBuffer = (int32_t) bufSize - (int32_t) pluginNameLen - 1; if (spaceLeftInBuffer < 0) { spaceLeftInBuffer = 0; } - strncpy(buffer, plugin->getMetaInformation().getName().c_str(), bufSize - 1); + strncpy(buffer, plugin.getMetaInformation().getName().c_str(), bufSize - 1); - auto functionSymbolData = plugin->getPluginInformation().getNearestFunctionSymbolData(addr); + const auto functionSymbolData = plugin.getPluginInformation().getNearestFunctionSymbolData(addr); if (functionSymbolData) { buffer[pluginNameLen] = '|'; buffer[pluginNameLen + 1] = '\0'; diff --git a/source/plugin/PluginConfigData.h b/source/plugin/PluginConfigData.h index ae01464..c4df471 100644 --- a/source/plugin/PluginConfigData.h +++ b/source/plugin/PluginConfigData.h @@ -14,7 +14,7 @@ public: mClosedCallback(closedCallback) { } - std::optional createConfig() { + [[nodiscard]] std::optional createConfig() const{ WUPSConfigHandle handle; if (WUPSConfigAPIBackend::Intern::CreateConfig(mName.c_str(), &handle) == WUPSCONFIG_API_RESULT_SUCCESS) { return handle; @@ -22,7 +22,7 @@ public: return std::nullopt; } - WUPSConfigAPIStatus CallMenuOpenendCallback(WUPSConfigHandle config) { + [[nodiscard]] WUPSConfigAPIStatus CallMenuOpenendCallback(WUPSConfigHandle config) const { if (mOpenedCallback == nullptr) { return WUPSCONFIG_API_RESULT_MISSING_CALLBACK; } @@ -32,7 +32,7 @@ public: return WUPSCONFIG_API_RESULT_SUCCESS; } - WUPSConfigAPIStatus CallMenuClosedCallback() { + [[nodiscard]] WUPSConfigAPIStatus CallMenuClosedCallback() const { if (mClosedCallback == nullptr) { return WUPSCONFIG_API_RESULT_MISSING_CALLBACK; } diff --git a/source/plugin/PluginContainer.h b/source/plugin/PluginContainer.h index 5a325fc..4cdee98 100644 --- a/source/plugin/PluginContainer.h +++ b/source/plugin/PluginContainer.h @@ -28,18 +28,49 @@ class PluginContainer { public: - PluginContainer(std::unique_ptr metaInformation, std::unique_ptr pluginInformation, std::shared_ptr pluginData) + PluginContainer(PluginMetaInformation metaInformation, PluginInformation pluginInformation, std::shared_ptr pluginData) : mMetaInformation(std::move(metaInformation)), mPluginInformation(std::move(pluginInformation)), mPluginData(std::move(pluginData)) { } + + PluginContainer(const PluginContainer &) = delete; + + + PluginContainer(PluginContainer &&src) : mMetaInformation(std::move(src.mMetaInformation)), + mPluginInformation(std::move(src.mPluginInformation)), + mPluginData(std::move(src.mPluginData)), + mPluginConfigData(std::move(src.mPluginConfigData)), + storageRootItem(src.storageRootItem) + + { + src.storageRootItem = {}; + } + + PluginContainer &operator=(PluginContainer &&src) { + if (this != &src) { + this->mMetaInformation = src.mMetaInformation; + this->mPluginInformation = std::move(src.mPluginInformation); + this->mPluginData = std::move(src.mPluginData); + this->mPluginConfigData = std::move(src.mPluginConfigData); + this->storageRootItem = src.storageRootItem; + + storageRootItem = nullptr; + } + return *this; + } + + [[nodiscard]] const PluginMetaInformation &getMetaInformation() const { - return *this->mMetaInformation; + return this->mMetaInformation; } [[nodiscard]] const PluginInformation &getPluginInformation() const { - return *this->mPluginInformation; + return this->mPluginInformation; + } + [[nodiscard]] PluginInformation &getPluginInformation() { + return this->mPluginInformation; } [[nodiscard]] std::shared_ptr getPluginDataCopy() const { @@ -88,9 +119,9 @@ public: } private: - const std::unique_ptr mMetaInformation; - const std::unique_ptr mPluginInformation; - const std::shared_ptr mPluginData; + PluginMetaInformation mMetaInformation; + PluginInformation mPluginInformation; + std::shared_ptr mPluginData; std::optional mPluginConfigData; wups_storage_root_item storageRootItem = nullptr; diff --git a/source/plugin/PluginInformation.h b/source/plugin/PluginInformation.h index 5a12cdf..eba8567 100644 --- a/source/plugin/PluginInformation.h +++ b/source/plugin/PluginInformation.h @@ -34,53 +34,89 @@ #include struct FunctionSymbolDataComparator { - bool operator()(const std::unique_ptr &lhs, - const std::unique_ptr &rhs) const { - return *lhs < *rhs; + bool operator()(const FunctionSymbolData &lhs, + const FunctionSymbolData &rhs) const { + return lhs < rhs; } }; class PluginInformation { public: - void addHookData(std::unique_ptr hook_data) { - mHookDataList.push_back(std::move(hook_data)); + PluginInformation(const PluginInformation &) = delete; + + + PluginInformation(PluginInformation &&src) : mHookDataList(std::move(src.mHookDataList)), + mFunctionDataList(std::move(src.mFunctionDataList)), + mRelocationDataList(std::move(src.mRelocationDataList)), + mSymbolDataList(std::move(src.mSymbolDataList)), + mSectionInfoList(std::move(src.mSectionInfoList)), + mTrampolineId(src.mTrampolineId), + mAllocatedTextMemoryAddress(std::move(src.mAllocatedTextMemoryAddress)), + mAllocatedDataMemoryAddress(std::move(src.mAllocatedDataMemoryAddress)) + + { + src.mTrampolineId = {}; } - [[nodiscard]] const std::vector> &getHookDataList() const { + PluginInformation &operator=(PluginInformation &&src) { + if (this != &src) { + this->mHookDataList = std::move(src.mHookDataList); + this->mFunctionDataList = std::move(src.mFunctionDataList); + this->mRelocationDataList = std::move(src.mRelocationDataList); + this->mSymbolDataList = std::move(src.mSymbolDataList); + this->mSectionInfoList = std::move(src.mSectionInfoList); + this->mTrampolineId = src.mTrampolineId; + this->mAllocatedTextMemoryAddress = std::move(src.mAllocatedTextMemoryAddress); + this->mAllocatedDataMemoryAddress = std::move(src.mAllocatedDataMemoryAddress); + src.mTrampolineId = {}; + } + return *this; + } + + + void addHookData(HookData hook_data) { + mHookDataList.push_back(hook_data); + } + + [[nodiscard]] const std::vector &getHookDataList() const { return mHookDataList; } - void addFunctionData(std::unique_ptr function_data) { + void addFunctionData(FunctionData function_data) { mFunctionDataList.push_back(std::move(function_data)); } - [[nodiscard]] const std::vector> &getFunctionDataList() const { + [[nodiscard]] const std::vector &getFunctionDataList() const { return mFunctionDataList; } - void addRelocationData(std::unique_ptr relocation_data) { + [[nodiscard]] std::vector &getFunctionDataList() { + return mFunctionDataList; + } + + void addRelocationData(RelocationData relocation_data) { mRelocationDataList.push_back(std::move(relocation_data)); } - [[nodiscard]] const std::vector> &getRelocationDataList() const { + [[nodiscard]] const std::vector &getRelocationDataList() const { return mRelocationDataList; } - void addFunctionSymbolData(std::unique_ptr symbol_data) { - mSymbolDataList.insert(std::move(symbol_data)); + void addFunctionSymbolData(const FunctionSymbolData &symbol_data) { + mSymbolDataList.insert(symbol_data); } - void addSectionInfo(std::unique_ptr sectionInfo) { - mSectionInfoList[sectionInfo->getName()] = std::move(sectionInfo); + void addSectionInfo(const SectionInfo §ionInfo) { + mSectionInfoList.insert(std::pair(sectionInfo.getName(), sectionInfo)); } - [[nodiscard]] const std::map> &getSectionInfoList() const { + [[nodiscard]] const std::map &getSectionInfoList() const { return mSectionInfoList; } [[nodiscard]] std::optional getSectionInfo(const std::string §ionName) const { if (getSectionInfoList().contains(sectionName)) { - return *mSectionInfoList.at(sectionName); + return mSectionInfoList.at(sectionName); } return std::nullopt; } @@ -93,16 +129,16 @@ public: return mTrampolineId; } - [[nodiscard]] FunctionSymbolData *getNearestFunctionSymbolData(uint32_t address) const { - FunctionSymbolData *result = nullptr; + [[nodiscard]] const FunctionSymbolData *getNearestFunctionSymbolData(uint32_t address) const { + const FunctionSymbolData *result = nullptr; bool foundHit = false; for (auto &cur : mSymbolDataList) { - if (foundHit && address < (uint32_t) cur->getAddress()) { + if (foundHit && address < (uint32_t) cur.getAddress()) { break; } - if (address >= (uint32_t) cur->getAddress()) { - result = cur.get(); + if (address >= (uint32_t) cur.getAddress()) { + result = &cur; foundHit = true; } } @@ -122,11 +158,14 @@ public: } private: - std::vector> mHookDataList; - std::vector> mFunctionDataList; - std::vector> mRelocationDataList; - std::set, FunctionSymbolDataComparator> mSymbolDataList; - std::map> mSectionInfoList; + PluginInformation(){ + + } + std::vector mHookDataList; + std::vector mFunctionDataList; + std::vector mRelocationDataList; + std::set mSymbolDataList; + std::map mSectionInfoList; uint8_t mTrampolineId = 0; diff --git a/source/plugin/PluginInformationFactory.cpp b/source/plugin/PluginInformationFactory.cpp index da3d6d2..c83b911 100644 --- a/source/plugin/PluginInformationFactory.cpp +++ b/source/plugin/PluginInformationFactory.cpp @@ -17,7 +17,6 @@ #include "PluginInformationFactory.h" #include "../utils/ElfUtils.h" -#include "../utils/utils.h" #include "utils/HeapMemoryFixedSize.h" #include "utils/wiiu_zlib.hpp" #include @@ -28,32 +27,28 @@ using namespace ELFIO; -std::unique_ptr +std::optional PluginInformationFactory::load(const PluginData &pluginData, std::vector &trampolineData, uint8_t trampolineId) { auto buffer = pluginData.getBuffer(); if (buffer.empty()) { DEBUG_FUNCTION_LINE_ERR("Buffer was empty"); - return nullptr; + return std::nullopt; } elfio reader(new wiiu_zlib); if (!reader.load(reinterpret_cast(buffer.data()), buffer.size())) { DEBUG_FUNCTION_LINE_ERR("Can't process PluginData in elfio"); - return nullptr; + return std::nullopt; } - auto pluginInfo = make_unique_nothrow(); - if (!pluginInfo) { - DEBUG_FUNCTION_LINE_ERR("Failed to allocate PluginInformation"); - return nullptr; - } + PluginInformation pluginInfo; uint32_t sec_num = reader.sections.size(); auto destinationsData = make_unique_nothrow(sec_num); if (!destinationsData) { DEBUG_FUNCTION_LINE_ERR("Failed alloc memory for destinations array"); - return nullptr; + return std::nullopt; } std::span destinations(destinationsData.get(), sec_num); @@ -85,13 +80,13 @@ PluginInformationFactory::load(const PluginData &pluginData, std::vector= 0xC0000000) { DEBUG_FUNCTION_LINE_ERR("Loading section from 0xC0000000 is NOT supported"); - return nullptr; + return std::nullopt; } else { DEBUG_FUNCTION_LINE_ERR("Unhandled case"); - return nullptr; + return std::nullopt; } const char *p = psec->get_data(); @@ -140,14 +135,7 @@ PluginInformationFactory::load(const PluginData &pluginData, std::vector %08X (%d bytes)", psec->get_name().c_str(), p, destination, sectionSize); memcpy((void *) destination, p, sectionSize); } - - auto sectionInfo = make_unique_nothrow(psec->get_name(), destination, sectionSize); - if (!sectionInfo) { - DEBUG_FUNCTION_LINE_ERR("Failed to allocat SectionInfo"); - return nullptr; - } - - pluginInfo->addSectionInfo(std::move(sectionInfo)); + pluginInfo.addSectionInfo(SectionInfo(psec->get_name(), destination, sectionSize)); DEBUG_FUNCTION_LINE_VERBOSE("Saved %s section info. Location: %08X size: %08X", psec->get_name().c_str(), destination, sectionSize); totalSize += sectionSize; @@ -164,14 +152,14 @@ PluginInformationFactory::load(const PluginData &pluginData, std::vectorget_index(), (uint32_t) destinations[psec->get_index()], (uint32_t) text_data.data(), (uint32_t) data_data.data(), trampolineData, trampolineId)) { DEBUG_FUNCTION_LINE_ERR("linkSection failed"); - return nullptr; + return std::nullopt; } } } - if (!PluginInformationFactory::addImportRelocationData(*pluginInfo, reader, destinations)) { + if (!PluginInformationFactory::addImportRelocationData(pluginInfo, reader, destinations)) { DEBUG_FUNCTION_LINE_ERR("addImportRelocationData failed"); - return nullptr; + return std::nullopt; } DCFlushRange((void *) text_data.data(), text_data.size()); @@ -179,9 +167,9 @@ PluginInformationFactory::load(const PluginData &pluginData, std::vectorsetTrampolineId(trampolineId); + pluginInfo.setTrampolineId(trampolineId); - auto secInfo = pluginInfo->getSectionInfo(".wups.hooks"); + auto secInfo = pluginInfo.getSectionInfo(".wups.hooks"); if (secInfo && secInfo->getSize() > 0) { size_t entries_count = secInfo->getSize() / sizeof(wups_loader_hook_t); auto *entries = (wups_loader_hook_t *) secInfo->getAddress(); @@ -189,17 +177,12 @@ PluginInformationFactory::load(const PluginData &pluginData, std::vectortype, (void *) hook->target); - auto hookData = make_unique_nothrow((void *) hook->target, hook->type); - if (!hookData) { - DEBUG_FUNCTION_LINE_ERR("Failed to allocate HookData"); - return nullptr; - } - pluginInfo->addHookData(std::move(hookData)); + pluginInfo.addHookData(HookData((void *) hook->target, hook->type)); } } } - secInfo = pluginInfo->getSectionInfo(".wups.load"); + secInfo = pluginInfo.getSectionInfo(".wups.load"); if (secInfo && secInfo->getSize() > 0) { size_t entries_count = secInfo->getSize() / sizeof(wups_loader_entry_t); auto *entries = (wups_loader_entry_t *) secInfo->getAddress(); @@ -210,19 +193,13 @@ PluginInformationFactory::load(const PluginData &pluginData, std::vector_function.name /*,mPluginData->getPluginInformation()->getName().c_str()*/, cur_function->_function.physical_address, cur_function->_function.virtual_address, cur_function->_function.library, cur_function->_function.target, (void *) cur_function->_function.call_addr); - - auto functionData = make_unique_nothrow((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); - if (!functionData) { - DEBUG_FUNCTION_LINE_ERR("Failed to allocate FunctionData"); - return nullptr; - } - pluginInfo->addFunctionData(std::move(functionData)); + pluginInfo.addFunctionData(FunctionData((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)); } } } @@ -248,18 +225,13 @@ PluginInformationFactory::load(const PluginData &pluginData, std::vectorget_address(); - auto sectionInfo = pluginInfo->getSectionInfo(sectionVal->get_name()); + auto sectionInfo = pluginInfo.getSectionInfo(sectionVal->get_name()); if (!sectionInfo) { continue; } - auto finalAddress = offsetVal + sectionInfo->getAddress(); - auto functionSymbolData = make_unique_nothrow(name, (void *) finalAddress, (uint32_t) size); - if (!functionSymbolData) { - DEBUG_FUNCTION_LINE_ERR("Failed to allocate FunctionSymbolData"); - return nullptr; - } - pluginInfo->addFunctionSymbolData(std::move(functionSymbolData)); + auto finalAddress = offsetVal + sectionInfo->getAddress(); + pluginInfo.addFunctionSymbolData(FunctionSymbolData(name, (void *) finalAddress, (uint32_t) size)); } } } @@ -270,13 +242,13 @@ PluginInformationFactory::load(const PluginData &pluginData, std::vector text_size + data_size) { DEBUG_FUNCTION_LINE_ERR("We didn't allocate enough memory!!"); - return nullptr; + return std::nullopt; } // Save the addresses for the allocated memory. This way we can free it again :) - pluginInfo->mAllocatedDataMemoryAddress = std::move(data_data); - pluginInfo->mAllocatedTextMemoryAddress = std::move(text_data); + pluginInfo.mAllocatedDataMemoryAddress = std::move(data_data); + pluginInfo.mAllocatedTextMemoryAddress = std::move(text_data); return pluginInfo; } @@ -340,18 +312,12 @@ bool PluginInformationFactory::addImportRelocationData(PluginInformation &plugin return false; } - auto relocationData = make_unique_nothrow(type, - offset - 0x02000000, - addend, - (void *) (destinations[section_index]), - sym_name, - infoMap[sym_section_index]); - if (!relocationData) { - DEBUG_FUNCTION_LINE_ERR("Failed to allocate RelocationData"); - return false; - } - - pluginInfo.addRelocationData(std::move(relocationData)); + pluginInfo.addRelocationData(RelocationData(type, + offset - 0x02000000, + addend, + (void *) (destinations[section_index]), + sym_name, + infoMap[sym_section_index])); } } } diff --git a/source/plugin/PluginInformationFactory.h b/source/plugin/PluginInformationFactory.h index 10d0bac..8b31aab 100644 --- a/source/plugin/PluginInformationFactory.h +++ b/source/plugin/PluginInformationFactory.h @@ -29,7 +29,7 @@ class PluginInformationFactory { public: - static std::unique_ptr + static std::optional load(const PluginData &pluginData, std::vector &trampolineData, uint8_t trampolineId); static bool diff --git a/source/plugin/PluginMetaInformation.cpp b/source/plugin/PluginMetaInformation.cpp deleted file mode 100644 index 8dbe35e..0000000 --- a/source/plugin/PluginMetaInformation.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "PluginMetaInformation.h" - -PluginMetaInformation::PluginMetaInformation(const PluginMetaInformation &other) { - this->name = other.name; - this->author = other.author; - this->version = other.version; - this->license = other.license; - this->buildtimestamp = other.buildtimestamp; - this->description = other.description; - this->size = other.size; - this->storageId = other.storageId; - this->wupsversion = other.wupsversion; -} \ No newline at end of file diff --git a/source/plugin/PluginMetaInformation.h b/source/plugin/PluginMetaInformation.h index 15759fb..f0e90d0 100644 --- a/source/plugin/PluginMetaInformation.h +++ b/source/plugin/PluginMetaInformation.h @@ -23,8 +23,6 @@ class PluginMetaInformation { public: - PluginMetaInformation(const PluginMetaInformation &other); - [[nodiscard]] const std::string &getName() const { return name; } diff --git a/source/plugin/PluginMetaInformationFactory.cpp b/source/plugin/PluginMetaInformationFactory.cpp index 22e774a..debb8db 100644 --- a/source/plugin/PluginMetaInformationFactory.cpp +++ b/source/plugin/PluginMetaInformationFactory.cpp @@ -22,11 +22,11 @@ #include "utils/wiiu_zlib.hpp" #include -std::unique_ptr PluginMetaInformationFactory::loadPlugin(const PluginData &pluginData, PluginParseErrors &error) { +std::optional PluginMetaInformationFactory::loadPlugin(const PluginData &pluginData, PluginParseErrors &error) { return loadPlugin(pluginData.getBuffer(), error); } -std::unique_ptr PluginMetaInformationFactory::loadPlugin(std::string_view filePath, PluginParseErrors &error) { +std::optional PluginMetaInformationFactory::loadPlugin(std::string_view filePath, PluginParseErrors &error) { std::vector buffer; if (FSUtils::LoadFileToMem(filePath, buffer) < 0) { DEBUG_FUNCTION_LINE_ERR("Failed to load file to memory"); @@ -36,7 +36,7 @@ std::unique_ptr PluginMetaInformationFactory::loadPlugin( return loadPlugin(buffer, error); } -std::unique_ptr PluginMetaInformationFactory::loadPlugin(std::span buffer, PluginParseErrors &error) { +std::optional PluginMetaInformationFactory::loadPlugin(std::span buffer, PluginParseErrors &error) { if (buffer.empty()) { error = PLUGIN_PARSE_ERROR_BUFFER_EMPTY; DEBUG_FUNCTION_LINE_ERR("Buffer is empty"); @@ -47,12 +47,12 @@ std::unique_ptr PluginMetaInformationFactory::loadPlugin( if (!reader.load(reinterpret_cast(buffer.data()), buffer.size())) { error = PLUGIN_PARSE_ERROR_ELFIO_PARSE_FAILED; DEBUG_FUNCTION_LINE_ERR("Can't find or process ELF file"); - return nullptr; + return {}; } size_t pluginSize = 0; - auto pluginInfo = std::unique_ptr(new PluginMetaInformation); + PluginMetaInformation pluginInfo; uint32_t sec_num = reader.sections.size(); @@ -89,28 +89,28 @@ std::unique_ptr PluginMetaInformationFactory::loadPlugin( std::string value(curEntry + firstFound + 1); if (key == "name") { - pluginInfo->setName(value); + pluginInfo.setName(value); } else if (key == "author") { - pluginInfo->setAuthor(value); + pluginInfo.setAuthor(value); } else if (key == "version") { - pluginInfo->setVersion(value); + pluginInfo.setVersion(value); } else if (key == "license") { - pluginInfo->setLicense(value); + pluginInfo.setLicense(value); } else if (key == "buildtimestamp") { - pluginInfo->setBuildTimestamp(value); + pluginInfo.setBuildTimestamp(value); } else if (key == "description") { - pluginInfo->setDescription(value); + pluginInfo.setDescription(value); } else if (key == "storage_id") { - pluginInfo->setStorageId(value); + pluginInfo.setStorageId(value); } else if (key == "wups") { if (value == "0.7.1") { - pluginInfo->setWUPSVersion(0, 7, 1); + pluginInfo.setWUPSVersion(0, 7, 1); } else if (value == "0.8.0") { - pluginInfo->setWUPSVersion(0, 8, 0); + pluginInfo.setWUPSVersion(0, 8, 0); } else { error = PLUGIN_PARSE_ERROR_INCOMPATIBLE_VERSION; DEBUG_FUNCTION_LINE_ERR("Warning: Ignoring plugin - Unsupported WUPS version: %s.", value.c_str()); - return nullptr; + return {}; } } } @@ -119,7 +119,7 @@ std::unique_ptr PluginMetaInformationFactory::loadPlugin( } } - pluginInfo->setSize(pluginSize); + pluginInfo.setSize(pluginSize); error = PLUGIN_PARSE_ERROR_NONE; diff --git a/source/plugin/PluginMetaInformationFactory.h b/source/plugin/PluginMetaInformationFactory.h index 052a320..6020f86 100644 --- a/source/plugin/PluginMetaInformationFactory.h +++ b/source/plugin/PluginMetaInformationFactory.h @@ -36,9 +36,9 @@ enum PluginParseErrors { class PluginMetaInformationFactory { public: - static std::unique_ptr loadPlugin(const PluginData &pluginData, PluginParseErrors &error); + static std::optional loadPlugin(const PluginData &pluginData, PluginParseErrors &error); - static std::unique_ptr loadPlugin(std::string_view filePath, PluginParseErrors &error); + static std::optional loadPlugin(std::string_view filePath, PluginParseErrors &error); - static std::unique_ptr loadPlugin(std::span buffer, PluginParseErrors &error); + static std::optional loadPlugin(std::span buffer, PluginParseErrors &error); }; diff --git a/source/plugin/WUPSVersion.h b/source/plugin/WUPSVersion.h index 3238476..c42694a 100644 --- a/source/plugin/WUPSVersion.h +++ b/source/plugin/WUPSVersion.h @@ -9,8 +9,6 @@ public: (static_cast(minor) << 16) | static_cast(revision)) {} - WUPSVersion(const WUPSVersion &other) = default; - static std::optional createFromString(const std::string &versionStr) { char *end; errno = 0; // Initialize errno before calling strtol diff --git a/source/utils/config/ConfigUtils.cpp b/source/utils/config/ConfigUtils.cpp index 2b84d0f..81c8414 100644 --- a/source/utils/config/ConfigUtils.cpp +++ b/source/utils/config/ConfigUtils.cpp @@ -72,16 +72,16 @@ void ConfigUtils::displayMenu() { renderBasicScreen("Loading configs..."); std::vector configs; - for (auto &plugin : gLoadedPlugins) { + for (const auto &plugin : gLoadedPlugins) { GeneralConfigInformation info; - info.name = plugin->getMetaInformation().getName(); - info.author = plugin->getMetaInformation().getAuthor(); - info.version = plugin->getMetaInformation().getVersion(); + info.name = plugin.getMetaInformation().getName(); + info.author = plugin.getMetaInformation().getAuthor(); + info.version = plugin.getMetaInformation().getVersion(); std::unique_ptr config; - auto configData = plugin->getConfigData(); + const auto configData = plugin.getConfigData(); if (configData) { - auto configHandleOpt = configData->createConfig(); + const auto configHandleOpt = configData->createConfig(); if (configHandleOpt) { WUPSConfigAPIStatus callbackResult = configData->CallMenuOpenendCallback(configHandleOpt.value()); config = WUPSConfigAPIBackend::Intern::PopConfigByHandle(configHandleOpt.value()); @@ -97,13 +97,13 @@ void ConfigUtils::displayMenu() { DEBUG_FUNCTION_LINE_ERR("Failed to create config for plugin: \"%s\"", info.name.c_str()); } } else { - for (const auto &hook : plugin->getPluginInformation().getHookDataList()) { - if (hook->getType() == WUPS_LOADER_HOOK_GET_CONFIG_DEPRECATED) { - if (hook->getFunctionPointer() == nullptr) { + for (const auto &hook : plugin.getPluginInformation().getHookDataList()) { + if (hook.getType() == WUPS_LOADER_HOOK_GET_CONFIG_DEPRECATED) { + if (hook.getFunctionPointer() == nullptr) { DEBUG_FUNCTION_LINE_ERR("Hook had invalid ptr"); break; } - auto cur_config_handle = ((void *(*) ())((uint32_t *) hook->getFunctionPointer()))(); + auto cur_config_handle = ((void *(*) ())((uint32_t *) hook.getFunctionPointer()))(); if (cur_config_handle == nullptr) { DEBUG_FUNCTION_LINE_WARN("Hook returned empty handle"); break; @@ -183,12 +183,14 @@ void ConfigUtils::displayMenu() { } } - for (auto &plugin : gLoadedPlugins) { - auto configData = plugin->getConfigData(); + for (const auto &plugin : gLoadedPlugins) { + const auto configData = plugin.getConfigData(); if (configData) { - configData->CallMenuClosedCallback(); + if (configData->CallMenuClosedCallback() == WUPSCONFIG_API_RESULT_MISSING_CALLBACK) { + DEBUG_FUNCTION_LINE_WARN("CallMenuClosedCallback is missing for %s", plugin.getMetaInformation().getName().c_str()); + } } else { - CallHook(*plugin, WUPS_LOADER_HOOK_CONFIG_CLOSED_DEPRECATED); + CallHook(plugin, WUPS_LOADER_HOOK_CONFIG_CLOSED_DEPRECATED); } } diff --git a/source/utils/exports.cpp b/source/utils/exports.cpp index 4551069..9047ff9 100644 --- a/source/utils/exports.cpp +++ b/source/utils/exports.cpp @@ -97,7 +97,7 @@ extern "C" PluginBackendApiErrorType WUPSGetPluginMetaInformation(WUPSBackendGet return PLUGIN_BACKEND_API_ERROR_INVALID_ARG; } - std::unique_ptr pluginInfo; + std::optional pluginInfo; PluginParseErrors error = PLUGIN_PARSE_ERROR_UNKNOWN; if (inputType == PLUGIN_INFORMATION_INPUT_TYPE_PATH && path != nullptr) { pluginInfo = PluginMetaInformationFactory::loadPlugin(path, error); @@ -136,8 +136,8 @@ extern "C" PluginBackendApiErrorType WUPSGetPluginDataForContainerHandles(const auto handle = plugin_container_handle_list[i]; bool found = false; for (const auto &curContainer : gLoadedPlugins) { - if (curContainer->getHandle() == handle) { - auto pluginData = curContainer->getPluginDataCopy(); + if (curContainer.getHandle() == handle) { + auto pluginData = curContainer.getPluginDataCopy(); plugin_data_list[i] = (uint32_t) pluginData->getHandle(); gLoadedData.insert(std::move(pluginData)); found = true; @@ -160,8 +160,8 @@ extern "C" PluginBackendApiErrorType WUPSGetMetaInformation(const wups_backend_p auto handle = plugin_container_handle_list[i]; bool found = false; for (const auto &curContainer : gLoadedPlugins) { - if (curContainer->getHandle() == handle) { - const auto &metaInfo = curContainer->getMetaInformation(); + if (curContainer.getHandle() == handle) { + const auto &metaInfo = curContainer.getMetaInformation(); plugin_information_list[i].plugin_information_version = WUPS_BACKEND_PLUGIN_INFORMATION_VERSION; strncpy(plugin_information_list[i].storageId, metaInfo.getStorageId().c_str(), sizeof(plugin_information_list[i].storageId) - 1); @@ -196,7 +196,7 @@ extern "C" PluginBackendApiErrorType WUPSGetLoadedPlugins(wups_backend_plugin_co uint32_t counter = 0; for (const auto &plugin : gLoadedPlugins) { if (counter < buffer_size) { - io_handles[counter] = plugin->getHandle(); + io_handles[counter] = plugin.getHandle(); counter++; } else { break; @@ -245,9 +245,9 @@ extern "C" PluginBackendApiErrorType WUPSGetSectionInformationForPlugin(const wu if (handle != 0 && plugin_section_list != nullptr && buffer_size != 0) { bool found = false; for (const auto &curContainer : gLoadedPlugins) { - if (curContainer->getHandle() == handle) { + if (curContainer.getHandle() == handle) { found = true; - const auto §ionInfoList = curContainer->getPluginInformation().getSectionInfoList(); + const auto §ionInfoList = curContainer.getPluginInformation().getSectionInfoList(); uint32_t offset = 0; for (auto const &[key, sectionInfo] : sectionInfoList) { @@ -255,9 +255,9 @@ extern "C" PluginBackendApiErrorType WUPSGetSectionInformationForPlugin(const wu break; } plugin_section_list[offset].plugin_section_info_version = WUPS_BACKEND_PLUGIN_SECTION_INFORMATION_VERSION; - strncpy(plugin_section_list[offset].name, sectionInfo->getName().c_str(), sizeof(plugin_section_list[offset].name) - 1); - plugin_section_list[offset].address = (void *) sectionInfo->getAddress(); - plugin_section_list[offset].size = sectionInfo->getSize(); + strncpy(plugin_section_list[offset].name, sectionInfo.getName().c_str(), sizeof(plugin_section_list[offset].name) - 1); + plugin_section_list[offset].address = (void *) sectionInfo.getAddress(); + plugin_section_list[offset].size = sectionInfo.getSize(); offset++; } if (out_count != nullptr) { @@ -289,9 +289,9 @@ extern "C" PluginBackendApiErrorType WUPSGetSectionMemoryAddresses(wups_backend_ return PLUGIN_BACKEND_API_ERROR_INVALID_ARG; } for (const auto &curContainer : gLoadedPlugins) { - if (curContainer->getHandle() == handle) { - *textAddress = (void *) curContainer->getPluginInformation().getTextMemory().data(); - *dataAddress = (void *) curContainer->getPluginInformation().getDataMemory().data(); + if (curContainer.getHandle() == handle) { + *textAddress = (void *) curContainer.getPluginInformation().getTextMemory().data(); + *dataAddress = (void *) curContainer.getPluginInformation().getDataMemory().data(); return PLUGIN_BACKEND_API_ERROR_NONE; } }