mirror of
https://github.com/wiiu-env/WiiUPluginLoaderBackend.git
synced 2024-12-23 19:41:49 +01:00
Rename PluginInformation to PluginLinkInformation and make it optional in PluginContainer
This commit is contained in:
parent
1524f0a6a9
commit
ab99e6dcf7
@ -2,7 +2,7 @@
|
|||||||
#include "NotificationsUtils.h"
|
#include "NotificationsUtils.h"
|
||||||
#include "hooks.h"
|
#include "hooks.h"
|
||||||
#include "plugin/PluginContainer.h"
|
#include "plugin/PluginContainer.h"
|
||||||
#include "plugin/PluginInformationFactory.h"
|
#include "plugin/PluginLinkInformationFactory.h"
|
||||||
#include "plugin/PluginMetaInformationFactory.h"
|
#include "plugin/PluginMetaInformationFactory.h"
|
||||||
#include "utils/ElfUtils.h"
|
#include "utils/ElfUtils.h"
|
||||||
#include "utils/StringTools.h"
|
#include "utils/StringTools.h"
|
||||||
@ -24,14 +24,14 @@ PluginManagement::loadPlugins(const std::set<std::shared_ptr<PluginData>, Plugin
|
|||||||
|
|
||||||
auto metaInfo = PluginMetaInformationFactory::loadPlugin(*pluginData, error);
|
auto metaInfo = PluginMetaInformationFactory::loadPlugin(*pluginData, error);
|
||||||
if (metaInfo && error == PLUGIN_PARSE_ERROR_NONE) {
|
if (metaInfo && error == PLUGIN_PARSE_ERROR_NONE) {
|
||||||
auto info = PluginInformationFactory::load(*pluginData, trampolineData, sTrampolineID++);
|
auto linkInfo = PluginLinkInformationFactory::load(*pluginData, trampolineData, sTrampolineID++);
|
||||||
if (!info) {
|
if (!linkInfo) {
|
||||||
auto errMsg = string_format("Failed to load plugin: %s", pluginData->getSource().c_str());
|
auto errMsg = string_format("Failed to load plugin: %s", pluginData->getSource().c_str());
|
||||||
DEBUG_FUNCTION_LINE_ERR("%s", errMsg.c_str());
|
DEBUG_FUNCTION_LINE_ERR("%s", errMsg.c_str());
|
||||||
DisplayErrorNotificationMessage(errMsg, 15.0f);
|
DisplayErrorNotificationMessage(errMsg, 15.0f);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
plugins.emplace_back(std::move(*metaInfo), std::move(*info), pluginData);
|
plugins.emplace_back(std::move(*metaInfo), std::move(linkInfo), pluginData);
|
||||||
} else {
|
} else {
|
||||||
auto errMsg = string_format("Failed to load plugin: %s", pluginData->getSource().c_str());
|
auto errMsg = string_format("Failed to load plugin: %s", pluginData->getSource().c_str());
|
||||||
if (error == PLUGIN_PARSE_ERROR_INCOMPATIBLE_VERSION) {
|
if (error == PLUGIN_PARSE_ERROR_INCOMPATIBLE_VERSION) {
|
||||||
@ -138,10 +138,13 @@ bool PluginManagement::doRelocations(const std::vector<PluginContainer> &plugins
|
|||||||
OSDynLoad_SetAllocator(CustomDynLoadAlloc, CustomDynLoadFree);
|
OSDynLoad_SetAllocator(CustomDynLoadAlloc, CustomDynLoadFree);
|
||||||
|
|
||||||
for (const auto &pluginContainer : plugins) {
|
for (const auto &pluginContainer : plugins) {
|
||||||
|
if (!pluginContainer.isPluginLinkedAndLoaded()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
DEBUG_FUNCTION_LINE_VERBOSE("Doing relocations for plugin: %s", pluginContainer.getMetaInformation().getName().c_str());
|
DEBUG_FUNCTION_LINE_VERBOSE("Doing relocations for plugin: %s", pluginContainer.getMetaInformation().getName().c_str());
|
||||||
if (!PluginManagement::doRelocation(pluginContainer.getPluginInformation().getRelocationDataList(),
|
if (!PluginManagement::doRelocation(pluginContainer.getPluginLinkInformation()->getRelocationDataList(),
|
||||||
trampData,
|
trampData,
|
||||||
pluginContainer.getPluginInformation().getTrampolineId(),
|
pluginContainer.getPluginLinkInformation()->getTrampolineId(),
|
||||||
usedRPls)) {
|
usedRPls)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -154,7 +157,10 @@ bool PluginManagement::doRelocations(const std::vector<PluginContainer> &plugins
|
|||||||
|
|
||||||
bool PluginManagement::RestoreFunctionPatches(std::vector<PluginContainer> &plugins) {
|
bool PluginManagement::RestoreFunctionPatches(std::vector<PluginContainer> &plugins) {
|
||||||
for (auto &cur : std::ranges::reverse_view(plugins)) {
|
for (auto &cur : std::ranges::reverse_view(plugins)) {
|
||||||
for (auto &curFunction : std::ranges::reverse_view(cur.getPluginInformation().getFunctionDataList())) {
|
if (!cur.isPluginLinkedAndLoaded()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (auto &curFunction : std::ranges::reverse_view(cur.getPluginLinkInformation()->getFunctionDataList())) {
|
||||||
if (!curFunction.RemovePatch()) {
|
if (!curFunction.RemovePatch()) {
|
||||||
DEBUG_FUNCTION_LINE_ERR("Failed to remove function patch for: plugin %s", cur.getMetaInformation().getName().c_str());
|
DEBUG_FUNCTION_LINE_ERR("Failed to remove function patch for: plugin %s", cur.getMetaInformation().getName().c_str());
|
||||||
return false;
|
return false;
|
||||||
@ -166,7 +172,10 @@ bool PluginManagement::RestoreFunctionPatches(std::vector<PluginContainer> &plug
|
|||||||
|
|
||||||
bool PluginManagement::DoFunctionPatches(std::vector<PluginContainer> &plugins) {
|
bool PluginManagement::DoFunctionPatches(std::vector<PluginContainer> &plugins) {
|
||||||
for (auto &cur : plugins) {
|
for (auto &cur : plugins) {
|
||||||
for (auto &curFunction : cur.getPluginInformation().getFunctionDataList()) {
|
if (!cur.isPluginLinkedAndLoaded()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (auto &curFunction : cur.getPluginLinkInformation()->getFunctionDataList()) {
|
||||||
if (!curFunction.AddPatch()) {
|
if (!curFunction.AddPatch()) {
|
||||||
DEBUG_FUNCTION_LINE_ERR("Failed to add function patch for: plugin %s", cur.getMetaInformation().getName().c_str());
|
DEBUG_FUNCTION_LINE_ERR("Failed to add function patch for: plugin %s", cur.getMetaInformation().getName().c_str());
|
||||||
return false;
|
return false;
|
||||||
|
@ -44,6 +44,9 @@ void CallHook(const std::vector<PluginContainer> &plugins, const wups_loader_hoo
|
|||||||
void CallHook(const std::vector<PluginContainer> &plugins, const wups_loader_hook_type_t hook_type, const std::function<bool(const PluginContainer &)> &pred) {
|
void CallHook(const std::vector<PluginContainer> &plugins, const wups_loader_hook_type_t hook_type, const std::function<bool(const PluginContainer &)> &pred) {
|
||||||
DEBUG_FUNCTION_LINE_VERBOSE("Calling hook of type %s [%d]", hook_names[hook_type], hook_type);
|
DEBUG_FUNCTION_LINE_VERBOSE("Calling hook of type %s [%d]", hook_names[hook_type], hook_type);
|
||||||
for (const auto &plugin : plugins) {
|
for (const auto &plugin : plugins) {
|
||||||
|
if (!plugin.isPluginLinkedAndLoaded()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (pred(plugin)) {
|
if (pred(plugin)) {
|
||||||
CallHook(plugin, hook_type);
|
CallHook(plugin, hook_type);
|
||||||
}
|
}
|
||||||
@ -51,7 +54,10 @@ void CallHook(const std::vector<PluginContainer> &plugins, const wups_loader_hoo
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CallHook(const PluginContainer &plugin, wups_loader_hook_type_t hook_type) {
|
void CallHook(const PluginContainer &plugin, wups_loader_hook_type_t hook_type) {
|
||||||
for (const auto &hook : plugin.getPluginInformation().getHookDataList()) {
|
if (!plugin.isPluginLinkedAndLoaded()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const auto &hook : plugin.getPluginLinkInformation()->getHookDataList()) {
|
||||||
if (hook.getType() == hook_type) {
|
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);
|
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();
|
void *func_ptr = hook.getFunctionPointer();
|
||||||
|
@ -217,7 +217,7 @@ void CleanupPlugins(std::vector<PluginContainer> &&pluginsToDeinit) {
|
|||||||
|
|
||||||
for (const auto &pluginContainer : pluginsToDeinit) {
|
for (const auto &pluginContainer : pluginsToDeinit) {
|
||||||
for (auto &cur : gTrampData) {
|
for (auto &cur : gTrampData) {
|
||||||
if (cur.id != pluginContainer.getPluginInformation().getTrampolineId()) {
|
if (!pluginContainer.isPluginLinkedAndLoaded() || cur.id != pluginContainer.getPluginLinkInformation()->getTrampolineId()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
cur.status = RELOC_TRAMP_FREE;
|
cur.status = RELOC_TRAMP_FREE;
|
||||||
@ -227,7 +227,10 @@ void CleanupPlugins(std::vector<PluginContainer> &&pluginsToDeinit) {
|
|||||||
void CheckCleanupCallbackUsage(const std::vector<PluginContainer> &plugins) {
|
void CheckCleanupCallbackUsage(const std::vector<PluginContainer> &plugins) {
|
||||||
auto *curThread = OSGetCurrentThread();
|
auto *curThread = OSGetCurrentThread();
|
||||||
for (const auto &cur : plugins) {
|
for (const auto &cur : plugins) {
|
||||||
const auto textSection = cur.getPluginInformation().getSectionInfo(".text");
|
if (!cur.isPluginLinkedAndLoaded()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto textSection = cur.getPluginLinkInformation()->getSectionInfo(".text");
|
||||||
if (!textSection) {
|
if (!textSection) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,10 @@ DECL_FUNCTION(uint32_t, SC17_FindClosestSymbol,
|
|||||||
char *moduleNameBuffer,
|
char *moduleNameBuffer,
|
||||||
uint32_t moduleNameBufferLength) {
|
uint32_t moduleNameBufferLength) {
|
||||||
for (const auto &plugin : gLoadedPlugins) {
|
for (const auto &plugin : gLoadedPlugins) {
|
||||||
const auto sectionInfo = plugin.getPluginInformation().getSectionInfo(".text");
|
if (!plugin.isPluginLinkedAndLoaded()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto sectionInfo = plugin.getPluginLinkInformation()->getSectionInfo(".text");
|
||||||
if (!sectionInfo) {
|
if (!sectionInfo) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -158,7 +161,7 @@ DECL_FUNCTION(uint32_t, SC17_FindClosestSymbol,
|
|||||||
}
|
}
|
||||||
|
|
||||||
strncpy(moduleNameBuffer, plugin.getMetaInformation().getName().c_str(), moduleNameBufferLength - 1);
|
strncpy(moduleNameBuffer, plugin.getMetaInformation().getName().c_str(), moduleNameBufferLength - 1);
|
||||||
if (const auto functionSymbolData = plugin.getPluginInformation().getNearestFunctionSymbolData(addr)) {
|
if (const auto functionSymbolData = plugin.getPluginLinkInformation()->getNearestFunctionSymbolData(addr)) {
|
||||||
strncpy(symbolNameBuffer, functionSymbolData->getName().c_str(), moduleNameBufferLength - 1);
|
strncpy(symbolNameBuffer, functionSymbolData->getName().c_str(), moduleNameBufferLength - 1);
|
||||||
if (outDistance) {
|
if (outDistance) {
|
||||||
*outDistance = addr - reinterpret_cast<uint32_t>(functionSymbolData->getAddress());
|
*outDistance = addr - reinterpret_cast<uint32_t>(functionSymbolData->getAddress());
|
||||||
@ -180,7 +183,10 @@ DECL_FUNCTION(uint32_t, SC17_FindClosestSymbol,
|
|||||||
|
|
||||||
DECL_FUNCTION(uint32_t, KiGetAppSymbolName, uint32_t addr, char *buffer, int32_t bufSize) {
|
DECL_FUNCTION(uint32_t, KiGetAppSymbolName, uint32_t addr, char *buffer, int32_t bufSize) {
|
||||||
for (const auto &plugin : gLoadedPlugins) {
|
for (const auto &plugin : gLoadedPlugins) {
|
||||||
const auto sectionInfo = plugin.getPluginInformation().getSectionInfo(".text");
|
if (!plugin.isPluginLinkedAndLoaded()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto sectionInfo = plugin.getPluginLinkInformation()->getSectionInfo(".text");
|
||||||
if (!sectionInfo) {
|
if (!sectionInfo) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -196,7 +202,7 @@ DECL_FUNCTION(uint32_t, KiGetAppSymbolName, uint32_t addr, char *buffer, int32_t
|
|||||||
}
|
}
|
||||||
strncpy(buffer, plugin.getMetaInformation().getName().c_str(), bufSize - 1);
|
strncpy(buffer, plugin.getMetaInformation().getName().c_str(), bufSize - 1);
|
||||||
|
|
||||||
if (const auto functionSymbolData = plugin.getPluginInformation().getNearestFunctionSymbolData(addr)) {
|
if (const auto functionSymbolData = plugin.getPluginLinkInformation()->getNearestFunctionSymbolData(addr)) {
|
||||||
buffer[pluginNameLen] = '|';
|
buffer[pluginNameLen] = '|';
|
||||||
buffer[pluginNameLen + 1] = '\0';
|
buffer[pluginNameLen + 1] = '\0';
|
||||||
strncpy(buffer + pluginNameLen + 1, functionSymbolData->getName().c_str(), spaceLeftInBuffer - 1);
|
strncpy(buffer + pluginNameLen + 1, functionSymbolData->getName().c_str(), spaceLeftInBuffer - 1);
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
#include "PluginContainer.h"
|
#include "PluginContainer.h"
|
||||||
#include "utils/storage/StorageUtils.h"
|
#include "utils/storage/StorageUtils.h"
|
||||||
|
|
||||||
PluginContainer::PluginContainer(PluginMetaInformation metaInformation, PluginInformation pluginInformation, std::shared_ptr<PluginData> pluginData)
|
PluginContainer::PluginContainer(PluginMetaInformation metaInformation, std::optional<PluginLinkInformation> pluginLinkInformation, std::shared_ptr<PluginData> pluginData)
|
||||||
: mMetaInformation(std::move(metaInformation)),
|
: mMetaInformation(std::move(metaInformation)),
|
||||||
mPluginInformation(std::move(pluginInformation)),
|
mPluginLinkInformation(std::move(pluginLinkInformation)),
|
||||||
mPluginData(std::move(pluginData)) {
|
mPluginData(std::move(pluginData)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginContainer::PluginContainer(PluginContainer &&src) noexcept : mMetaInformation(std::move(src.mMetaInformation)),
|
|
||||||
mPluginInformation(std::move(src.mPluginInformation)),
|
PluginContainer::PluginContainer(PluginContainer &&src) : mMetaInformation(std::move(src.mMetaInformation)),
|
||||||
|
mPluginLinkInformation(std::move(src.mPluginLinkInformation)),
|
||||||
mPluginData(std::move(src.mPluginData)),
|
mPluginData(std::move(src.mPluginData)),
|
||||||
mPluginConfigData(std::move(src.mPluginConfigData)),
|
mPluginConfigData(std::move(src.mPluginConfigData)),
|
||||||
mStorageRootItem(src.mStorageRootItem),
|
mStorageRootItem(src.mStorageRootItem),
|
||||||
@ -22,7 +23,7 @@ PluginContainer::PluginContainer(PluginContainer &&src) noexcept : mMetaInformat
|
|||||||
PluginContainer &PluginContainer::operator=(PluginContainer &&src) noexcept {
|
PluginContainer &PluginContainer::operator=(PluginContainer &&src) noexcept {
|
||||||
if (this != &src) {
|
if (this != &src) {
|
||||||
this->mMetaInformation = std::move(src.mMetaInformation);
|
this->mMetaInformation = std::move(src.mMetaInformation);
|
||||||
this->mPluginInformation = std::move(src.mPluginInformation);
|
this->mPluginLinkInformation = std::move(src.mPluginLinkInformation);
|
||||||
this->mPluginData = std::move(src.mPluginData);
|
this->mPluginData = std::move(src.mPluginData);
|
||||||
this->mPluginConfigData = std::move(src.mPluginConfigData);
|
this->mPluginConfigData = std::move(src.mPluginConfigData);
|
||||||
this->mStorageRootItem = src.mStorageRootItem;
|
this->mStorageRootItem = src.mStorageRootItem;
|
||||||
@ -38,12 +39,22 @@ const PluginMetaInformation &PluginContainer::getMetaInformation() const {
|
|||||||
return this->mMetaInformation;
|
return this->mMetaInformation;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PluginInformation &PluginContainer::getPluginInformation() const {
|
bool PluginContainer::isPluginLinkedAndLoaded() const {
|
||||||
return this->mPluginInformation;
|
return this->mPluginLinkInformation.has_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginInformation &PluginContainer::getPluginInformation() {
|
const PluginLinkInformation *PluginContainer::getPluginLinkInformation() const {
|
||||||
return this->mPluginInformation;
|
if (this->mPluginLinkInformation.has_value()) {
|
||||||
|
return this->mPluginLinkInformation.operator->();
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
PluginLinkInformation *PluginContainer::getPluginLinkInformation() {
|
||||||
|
if (this->mPluginLinkInformation.has_value()) {
|
||||||
|
return this->mPluginLinkInformation.operator->();
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<PluginData> PluginContainer::getPluginDataCopy() const {
|
std::shared_ptr<PluginData> PluginContainer::getPluginDataCopy() const {
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include "PluginConfigData.h"
|
#include "PluginConfigData.h"
|
||||||
#include "PluginData.h"
|
#include "PluginData.h"
|
||||||
#include "PluginInformation.h"
|
#include "PluginLinkInformation.h"
|
||||||
#include "PluginMetaInformation.h"
|
#include "PluginMetaInformation.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -28,21 +28,24 @@
|
|||||||
|
|
||||||
class PluginContainer {
|
class PluginContainer {
|
||||||
public:
|
public:
|
||||||
PluginContainer(PluginMetaInformation metaInformation, PluginInformation pluginInformation, std::shared_ptr<PluginData> pluginData);
|
PluginContainer(PluginMetaInformation metaInformation, std::optional<PluginLinkInformation> pluginLinkInformation, std::shared_ptr<PluginData> pluginData);
|
||||||
|
|
||||||
PluginContainer(const PluginContainer &) = delete;
|
PluginContainer(const PluginContainer &) = delete;
|
||||||
|
|
||||||
PluginContainer(PluginContainer &&src) noexcept;
|
PluginContainer(PluginContainer &&src);
|
||||||
|
|
||||||
PluginContainer &operator=(PluginContainer &&src) noexcept;
|
PluginContainer &operator=(PluginContainer &&src);
|
||||||
|
|
||||||
[[nodiscard]] const PluginMetaInformation &getMetaInformation() const;
|
[[nodiscard]] const PluginMetaInformation &getMetaInformation() const;
|
||||||
|
|
||||||
[[nodiscard]] const PluginInformation &getPluginInformation() const;
|
[[nodiscard]] const PluginLinkInformation *getPluginLinkInformation() const;
|
||||||
[[nodiscard]] PluginInformation &getPluginInformation();
|
|
||||||
|
[[nodiscard]] PluginLinkInformation *getPluginLinkInformation();
|
||||||
|
|
||||||
[[nodiscard]] std::shared_ptr<PluginData> getPluginDataCopy() const;
|
[[nodiscard]] std::shared_ptr<PluginData> getPluginDataCopy() const;
|
||||||
|
|
||||||
|
[[nodiscard]] bool isPluginLinkedAndLoaded() const;
|
||||||
|
|
||||||
[[nodiscard]] uint32_t getHandle() const;
|
[[nodiscard]] uint32_t getHandle() const;
|
||||||
|
|
||||||
[[nodiscard]] const std::optional<PluginConfigData> &getConfigData() const;
|
[[nodiscard]] const std::optional<PluginConfigData> &getConfigData() const;
|
||||||
@ -61,10 +64,10 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
PluginMetaInformation mMetaInformation;
|
PluginMetaInformation mMetaInformation;
|
||||||
PluginInformation mPluginInformation;
|
std::optional<PluginLinkInformation> mPluginLinkInformation;
|
||||||
std::shared_ptr<PluginData> mPluginData;
|
std::shared_ptr<PluginData> mPluginData;
|
||||||
|
|
||||||
std::optional<PluginConfigData> mPluginConfigData;
|
std::optional<PluginConfigData> mPluginConfigData = std::nullopt;
|
||||||
wups_storage_root_item mStorageRootItem = nullptr;
|
wups_storage_root_item mStorageRootItem = nullptr;
|
||||||
bool mInitDone = false;
|
bool mInitDone = false;
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "PluginInformation.h"
|
#include "PluginLinkInformation.h"
|
||||||
|
|
||||||
PluginInformation::PluginInformation(PluginInformation &&src) : mHookDataList(std::move(src.mHookDataList)),
|
PluginLinkInformation::PluginLinkInformation(PluginLinkInformation &&src) : mHookDataList(std::move(src.mHookDataList)),
|
||||||
mFunctionDataList(std::move(src.mFunctionDataList)),
|
mFunctionDataList(std::move(src.mFunctionDataList)),
|
||||||
mRelocationDataList(std::move(src.mRelocationDataList)),
|
mRelocationDataList(std::move(src.mRelocationDataList)),
|
||||||
mSymbolDataList(std::move(src.mSymbolDataList)),
|
mSymbolDataList(std::move(src.mSymbolDataList)),
|
||||||
@ -13,7 +13,7 @@ PluginInformation::PluginInformation(PluginInformation &&src) : mHookDataList(st
|
|||||||
src.mTrampolineId = {};
|
src.mTrampolineId = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginInformation &PluginInformation::operator=(PluginInformation &&src) {
|
PluginLinkInformation &PluginLinkInformation::operator=(PluginLinkInformation &&src) {
|
||||||
if (this != &src) {
|
if (this != &src) {
|
||||||
this->mHookDataList = std::move(src.mHookDataList);
|
this->mHookDataList = std::move(src.mHookDataList);
|
||||||
this->mFunctionDataList = std::move(src.mFunctionDataList);
|
this->mFunctionDataList = std::move(src.mFunctionDataList);
|
||||||
@ -28,62 +28,63 @@ PluginInformation &PluginInformation::operator=(PluginInformation &&src) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginInformation::addHookData(const HookData &hook_data) {
|
void PluginLinkInformation::addHookData(const HookData &hook_data) {
|
||||||
mHookDataList.push_back(hook_data);
|
mHookDataList.push_back(hook_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<HookData> &PluginInformation::getHookDataList() const {
|
const std::vector<HookData> &PluginLinkInformation::getHookDataList() const {
|
||||||
return mHookDataList;
|
return mHookDataList;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginInformation::addFunctionData(FunctionData function_data) {
|
void PluginLinkInformation::addFunctionData(FunctionData function_data) {
|
||||||
mFunctionDataList.push_back(std::move(function_data));
|
mFunctionDataList.push_back(std::move(function_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<FunctionData> &PluginInformation::getFunctionDataList() const {
|
const std::vector<FunctionData> &PluginLinkInformation::getFunctionDataList() const {
|
||||||
return mFunctionDataList;
|
return mFunctionDataList;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<FunctionData> &PluginInformation::getFunctionDataList() {
|
std::vector<FunctionData> &PluginLinkInformation::getFunctionDataList() {
|
||||||
return mFunctionDataList;
|
return mFunctionDataList;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginInformation::addRelocationData(RelocationData relocation_data) {
|
void PluginLinkInformation::addRelocationData(RelocationData relocation_data) {
|
||||||
mRelocationDataList.push_back(std::move(relocation_data));
|
mRelocationDataList.push_back(std::move(relocation_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<RelocationData> &PluginInformation::getRelocationDataList() const {
|
const std::vector<RelocationData> &PluginLinkInformation::getRelocationDataList() const {
|
||||||
return mRelocationDataList;
|
return mRelocationDataList;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginInformation::addFunctionSymbolData(const FunctionSymbolData &symbol_data) {
|
void PluginLinkInformation::addFunctionSymbolData(const FunctionSymbolData &symbol_data) {
|
||||||
mSymbolDataList.insert(symbol_data);
|
mSymbolDataList.insert(symbol_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginInformation::addSectionInfo(const SectionInfo §ionInfo) {
|
void PluginLinkInformation::addSectionInfo(const SectionInfo §ionInfo) {
|
||||||
mSectionInfoList.insert(std::pair(sectionInfo.getName(), sectionInfo));
|
mSectionInfoList.insert(std::pair(sectionInfo.getName(), sectionInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::map<std::string, SectionInfo> &PluginInformation::getSectionInfoList() const {
|
const std::map<std::string, SectionInfo> &PluginLinkInformation::getSectionInfoList() const {
|
||||||
return mSectionInfoList;
|
return mSectionInfoList;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<SectionInfo> PluginInformation::getSectionInfo(const std::string §ionName) const {
|
std::optional<SectionInfo> PluginLinkInformation::getSectionInfo(const std::string §ionName) const {
|
||||||
if (getSectionInfoList().contains(sectionName)) {
|
if (getSectionInfoList().contains(sectionName)) {
|
||||||
return mSectionInfoList.at(sectionName);
|
return mSectionInfoList.at(sectionName);
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginInformation::setTrampolineId(const uint8_t trampolineId) {
|
|
||||||
|
void PluginLinkInformation::setTrampolineId(const uint8_t trampolineId) {
|
||||||
this->mTrampolineId = trampolineId;
|
this->mTrampolineId = trampolineId;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t PluginInformation::getTrampolineId() const {
|
uint8_t PluginLinkInformation::getTrampolineId() const {
|
||||||
return mTrampolineId;
|
return mTrampolineId;
|
||||||
}
|
}
|
||||||
|
|
||||||
const FunctionSymbolData *PluginInformation::getNearestFunctionSymbolData(const uint32_t address) const {
|
const FunctionSymbolData *PluginLinkInformation::getNearestFunctionSymbolData(uint32_t address) const {
|
||||||
const FunctionSymbolData *result = nullptr;
|
const FunctionSymbolData *result = nullptr;
|
||||||
|
|
||||||
bool foundHit = false;
|
bool foundHit = false;
|
||||||
@ -103,10 +104,10 @@ const FunctionSymbolData *PluginInformation::getNearestFunctionSymbolData(const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const HeapMemoryFixedSize &PluginInformation::getTextMemory() const {
|
const HeapMemoryFixedSize &PluginLinkInformation::getTextMemory() const {
|
||||||
return mAllocatedTextMemoryAddress;
|
return mAllocatedTextMemoryAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
const HeapMemoryFixedSize &PluginInformation::getDataMemory() const {
|
const HeapMemoryFixedSize &PluginLinkInformation::getDataMemory() const {
|
||||||
return mAllocatedDataMemoryAddress;
|
return mAllocatedDataMemoryAddress;
|
||||||
}
|
}
|
@ -37,13 +37,13 @@ struct FunctionSymbolDataComparator {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class PluginInformation {
|
class PluginLinkInformation {
|
||||||
public:
|
public:
|
||||||
PluginInformation(const PluginInformation &) = delete;
|
PluginLinkInformation(const PluginLinkInformation &) = delete;
|
||||||
|
|
||||||
PluginInformation(PluginInformation &&src);
|
PluginLinkInformation(PluginLinkInformation &&src) noexcept;
|
||||||
|
|
||||||
PluginInformation &operator=(PluginInformation &&src);
|
PluginLinkInformation &operator=(PluginLinkInformation &&src);
|
||||||
|
|
||||||
[[nodiscard]] const std::vector<HookData> &getHookDataList() const;
|
[[nodiscard]] const std::vector<HookData> &getHookDataList() const;
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ public:
|
|||||||
[[nodiscard]] const HeapMemoryFixedSize &getDataMemory() const;
|
[[nodiscard]] const HeapMemoryFixedSize &getDataMemory() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PluginInformation() = default;
|
PluginLinkInformation() = default;
|
||||||
|
|
||||||
void addHookData(const HookData &hook_data);
|
void addHookData(const HookData &hook_data);
|
||||||
|
|
||||||
@ -91,5 +91,5 @@ private:
|
|||||||
HeapMemoryFixedSize mAllocatedTextMemoryAddress;
|
HeapMemoryFixedSize mAllocatedTextMemoryAddress;
|
||||||
HeapMemoryFixedSize mAllocatedDataMemoryAddress;
|
HeapMemoryFixedSize mAllocatedDataMemoryAddress;
|
||||||
|
|
||||||
friend class PluginInformationFactory;
|
friend class PluginLinkInformationFactory;
|
||||||
};
|
};
|
@ -15,7 +15,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "PluginInformationFactory.h"
|
#include "PluginLinkInformationFactory.h"
|
||||||
#include "utils/ElfUtils.h"
|
#include "utils/ElfUtils.h"
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
@ -26,8 +26,8 @@
|
|||||||
|
|
||||||
using namespace ELFIO;
|
using namespace ELFIO;
|
||||||
|
|
||||||
std::optional<PluginInformation>
|
std::optional<PluginLinkInformation>
|
||||||
PluginInformationFactory::load(const PluginData &pluginData, std::vector<relocation_trampoline_entry_t> &trampolineData, uint8_t trampolineId) {
|
PluginLinkInformationFactory::load(const PluginData &pluginData, std::vector<relocation_trampoline_entry_t> &trampolineData, uint8_t trampolineId) {
|
||||||
auto buffer = pluginData.getBuffer();
|
auto buffer = pluginData.getBuffer();
|
||||||
if (buffer.empty()) {
|
if (buffer.empty()) {
|
||||||
DEBUG_FUNCTION_LINE_ERR("Buffer was empty");
|
DEBUG_FUNCTION_LINE_ERR("Buffer was empty");
|
||||||
@ -40,7 +40,7 @@ PluginInformationFactory::load(const PluginData &pluginData, std::vector<relocat
|
|||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginInformation pluginInfo;
|
PluginLinkInformation pluginInfo;
|
||||||
|
|
||||||
uint32_t sec_num = reader.sections.size();
|
uint32_t sec_num = reader.sections.size();
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ PluginInformationFactory::load(const PluginData &pluginData, std::vector<relocat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PluginInformationFactory::addImportRelocationData(pluginInfo, reader, destinations)) {
|
if (!PluginLinkInformationFactory::addImportRelocationData(pluginInfo, reader, destinations)) {
|
||||||
DEBUG_FUNCTION_LINE_ERR("addImportRelocationData failed");
|
DEBUG_FUNCTION_LINE_ERR("addImportRelocationData failed");
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
@ -264,7 +264,7 @@ PluginInformationFactory::load(const PluginData &pluginData, std::vector<relocat
|
|||||||
return pluginInfo;
|
return pluginInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PluginInformationFactory::addImportRelocationData(PluginInformation &pluginInfo, const elfio &reader, const std::span<uint8_t *> destinations) {
|
bool PluginLinkInformationFactory::addImportRelocationData(PluginLinkInformation &pluginInfo, const elfio &reader, const std::span<uint8_t *> destinations) {
|
||||||
std::map<uint32_t, std::shared_ptr<ImportRPLInformation>> infoMap;
|
std::map<uint32_t, std::shared_ptr<ImportRPLInformation>> infoMap;
|
||||||
|
|
||||||
uint32_t sec_num = reader.sections.size();
|
uint32_t sec_num = reader.sections.size();
|
||||||
@ -335,7 +335,7 @@ bool PluginInformationFactory::addImportRelocationData(PluginInformation &plugin
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data,
|
bool PluginLinkInformationFactory::linkSection(const elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data,
|
||||||
std::vector<relocation_trampoline_entry_t> &trampolineData, uint8_t trampolineId) {
|
std::vector<relocation_trampoline_entry_t> &trampolineData, uint8_t trampolineId) {
|
||||||
uint32_t sec_num = reader.sections.size();
|
uint32_t sec_num = reader.sections.size();
|
||||||
|
|
@ -17,21 +17,22 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "PluginData.h"
|
#include "PluginData.h"
|
||||||
#include "PluginInformation.h"
|
#include "PluginLinkInformation.h"
|
||||||
|
|
||||||
#include <elfio/elfio.hpp>
|
#include <elfio/elfio.hpp>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <wums/defines/relocation_defines.h>
|
#include <wums/defines/relocation_defines.h>
|
||||||
|
|
||||||
class PluginInformationFactory {
|
class PluginLinkInformationFactory {
|
||||||
public:
|
public:
|
||||||
static std::optional<PluginInformation>
|
static std::optional<PluginLinkInformation>
|
||||||
load(const PluginData &pluginData, std::vector<relocation_trampoline_entry_t> &trampolineData, uint8_t trampolineId);
|
load(const PluginData &pluginData, std::vector<relocation_trampoline_entry_t> &trampolineData, uint8_t trampolineId);
|
||||||
|
|
||||||
|
private:
|
||||||
static bool
|
static bool
|
||||||
linkSection(const ELFIO::elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data,
|
linkSection(const ELFIO::elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data,
|
||||||
std::vector<relocation_trampoline_entry_t> &trampolineData, uint8_t trampolineId);
|
std::vector<relocation_trampoline_entry_t> &trampolineData, uint8_t trampolineId);
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
addImportRelocationData(PluginInformation &pluginInfo, const ELFIO::elfio &reader, std::span<uint8_t *> destinations);
|
addImportRelocationData(PluginLinkInformation &pluginInfo, const ELFIO::elfio &reader, std::span<uint8_t *> destinations);
|
||||||
};
|
};
|
@ -77,6 +77,9 @@ void ConfigUtils::displayMenu() {
|
|||||||
|
|
||||||
std::vector<ConfigDisplayItem> configs;
|
std::vector<ConfigDisplayItem> configs;
|
||||||
for (const auto &plugin : gLoadedPlugins) {
|
for (const auto &plugin : gLoadedPlugins) {
|
||||||
|
if (!plugin.isPluginLinkedAndLoaded()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
GeneralConfigInformation info;
|
GeneralConfigInformation info;
|
||||||
info.name = plugin.getMetaInformation().getName();
|
info.name = plugin.getMetaInformation().getName();
|
||||||
info.author = plugin.getMetaInformation().getAuthor();
|
info.author = plugin.getMetaInformation().getAuthor();
|
||||||
@ -99,7 +102,7 @@ void ConfigUtils::displayMenu() {
|
|||||||
DEBUG_FUNCTION_LINE_ERR("Failed to create config for plugin: \"%s\"", info.name.c_str());
|
DEBUG_FUNCTION_LINE_ERR("Failed to create config for plugin: \"%s\"", info.name.c_str());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (const auto &hook : plugin.getPluginInformation().getHookDataList()) {
|
for (const auto &hook : plugin.getPluginLinkInformation()->getHookDataList()) {
|
||||||
if (hook.getType() == WUPS_LOADER_HOOK_GET_CONFIG_DEPRECATED) {
|
if (hook.getType() == WUPS_LOADER_HOOK_GET_CONFIG_DEPRECATED) {
|
||||||
if (hook.getFunctionPointer() == nullptr) {
|
if (hook.getFunctionPointer() == nullptr) {
|
||||||
DEBUG_FUNCTION_LINE_ERR("Hook had invalid ptr");
|
DEBUG_FUNCTION_LINE_ERR("Hook had invalid ptr");
|
||||||
|
@ -276,9 +276,9 @@ extern "C" PluginBackendApiErrorType WUPSGetSectionInformationForPlugin(const wu
|
|||||||
if (handle != 0 && plugin_section_list != nullptr && buffer_size != 0) {
|
if (handle != 0 && plugin_section_list != nullptr && buffer_size != 0) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (const auto &curContainer : gLoadedPlugins) {
|
for (const auto &curContainer : gLoadedPlugins) {
|
||||||
if (curContainer.getHandle() == handle) {
|
if (curContainer.isPluginLinkedAndLoaded() && curContainer.getHandle() == handle) {
|
||||||
found = true;
|
found = true;
|
||||||
const auto §ionInfoList = curContainer.getPluginInformation().getSectionInfoList();
|
const auto §ionInfoList = curContainer.getPluginLinkInformation()->getSectionInfoList();
|
||||||
|
|
||||||
uint32_t offset = 0;
|
uint32_t offset = 0;
|
||||||
for (auto const §ionInfo : sectionInfoList | std::views::values) {
|
for (auto const §ionInfo : sectionInfoList | std::views::values) {
|
||||||
@ -320,9 +320,9 @@ extern "C" PluginBackendApiErrorType WUPSGetSectionMemoryAddresses(const wups_ba
|
|||||||
return PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
|
return PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
|
||||||
}
|
}
|
||||||
for (const auto &curContainer : gLoadedPlugins) {
|
for (const auto &curContainer : gLoadedPlugins) {
|
||||||
if (curContainer.getHandle() == handle) {
|
if (curContainer.isPluginLinkedAndLoaded() && curContainer.getHandle() == handle) {
|
||||||
*textAddress = const_cast<void *>(curContainer.getPluginInformation().getTextMemory().data());
|
*textAddress = const_cast<void *>(curContainer.getPluginLinkInformation()->getTextMemory().data());
|
||||||
*dataAddress = const_cast<void *>(curContainer.getPluginInformation().getDataMemory().data());
|
*dataAddress = const_cast<void *>(curContainer.getPluginLinkInformation()->getDataMemory().data());
|
||||||
return PLUGIN_BACKEND_API_ERROR_NONE;
|
return PLUGIN_BACKEND_API_ERROR_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user