mirror of
https://github.com/wiiu-env/WiiUPluginLoaderBackend.git
synced 2026-08-28 22:05:29 -05:00
Remove unnecessary std::unique_ptr usages
This commit is contained in:
@@ -14,7 +14,7 @@ public:
|
||||
mClosedCallback(closedCallback) {
|
||||
}
|
||||
|
||||
std::optional<WUPSConfigHandle> createConfig() {
|
||||
[[nodiscard]] std::optional<WUPSConfigHandle> 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;
|
||||
}
|
||||
|
||||
@@ -28,18 +28,49 @@
|
||||
|
||||
class PluginContainer {
|
||||
public:
|
||||
PluginContainer(std::unique_ptr<PluginMetaInformation> metaInformation, std::unique_ptr<PluginInformation> pluginInformation, std::shared_ptr<PluginData> pluginData)
|
||||
PluginContainer(PluginMetaInformation metaInformation, PluginInformation pluginInformation, std::shared_ptr<PluginData> 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<PluginData> getPluginDataCopy() const {
|
||||
@@ -88,9 +119,9 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
const std::unique_ptr<PluginMetaInformation> mMetaInformation;
|
||||
const std::unique_ptr<PluginInformation> mPluginInformation;
|
||||
const std::shared_ptr<PluginData> mPluginData;
|
||||
PluginMetaInformation mMetaInformation;
|
||||
PluginInformation mPluginInformation;
|
||||
std::shared_ptr<PluginData> mPluginData;
|
||||
|
||||
std::optional<PluginConfigData> mPluginConfigData;
|
||||
wups_storage_root_item storageRootItem = nullptr;
|
||||
|
||||
@@ -34,53 +34,89 @@
|
||||
#include <vector>
|
||||
|
||||
struct FunctionSymbolDataComparator {
|
||||
bool operator()(const std::unique_ptr<FunctionSymbolData> &lhs,
|
||||
const std::unique_ptr<FunctionSymbolData> &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<HookData> 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<std::unique_ptr<HookData>> &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<HookData> &getHookDataList() const {
|
||||
return mHookDataList;
|
||||
}
|
||||
|
||||
void addFunctionData(std::unique_ptr<FunctionData> function_data) {
|
||||
void addFunctionData(FunctionData function_data) {
|
||||
mFunctionDataList.push_back(std::move(function_data));
|
||||
}
|
||||
|
||||
[[nodiscard]] const std::vector<std::unique_ptr<FunctionData>> &getFunctionDataList() const {
|
||||
[[nodiscard]] const std::vector<FunctionData> &getFunctionDataList() const {
|
||||
return mFunctionDataList;
|
||||
}
|
||||
|
||||
void addRelocationData(std::unique_ptr<RelocationData> relocation_data) {
|
||||
[[nodiscard]] std::vector<FunctionData> &getFunctionDataList() {
|
||||
return mFunctionDataList;
|
||||
}
|
||||
|
||||
void addRelocationData(RelocationData relocation_data) {
|
||||
mRelocationDataList.push_back(std::move(relocation_data));
|
||||
}
|
||||
|
||||
[[nodiscard]] const std::vector<std::unique_ptr<RelocationData>> &getRelocationDataList() const {
|
||||
[[nodiscard]] const std::vector<RelocationData> &getRelocationDataList() const {
|
||||
return mRelocationDataList;
|
||||
}
|
||||
|
||||
void addFunctionSymbolData(std::unique_ptr<FunctionSymbolData> symbol_data) {
|
||||
mSymbolDataList.insert(std::move(symbol_data));
|
||||
void addFunctionSymbolData(const FunctionSymbolData &symbol_data) {
|
||||
mSymbolDataList.insert(symbol_data);
|
||||
}
|
||||
|
||||
void addSectionInfo(std::unique_ptr<SectionInfo> sectionInfo) {
|
||||
mSectionInfoList[sectionInfo->getName()] = std::move(sectionInfo);
|
||||
void addSectionInfo(const SectionInfo §ionInfo) {
|
||||
mSectionInfoList.insert(std::pair(sectionInfo.getName(), sectionInfo));
|
||||
}
|
||||
|
||||
[[nodiscard]] const std::map<std::string, std::unique_ptr<SectionInfo>> &getSectionInfoList() const {
|
||||
[[nodiscard]] const std::map<std::string, SectionInfo> &getSectionInfoList() const {
|
||||
return mSectionInfoList;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::optional<SectionInfo> 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<std::unique_ptr<HookData>> mHookDataList;
|
||||
std::vector<std::unique_ptr<FunctionData>> mFunctionDataList;
|
||||
std::vector<std::unique_ptr<RelocationData>> mRelocationDataList;
|
||||
std::set<std::unique_ptr<FunctionSymbolData>, FunctionSymbolDataComparator> mSymbolDataList;
|
||||
std::map<std::string, std::unique_ptr<SectionInfo>> mSectionInfoList;
|
||||
PluginInformation(){
|
||||
|
||||
}
|
||||
std::vector<HookData> mHookDataList;
|
||||
std::vector<FunctionData> mFunctionDataList;
|
||||
std::vector<RelocationData> mRelocationDataList;
|
||||
std::set<FunctionSymbolData, FunctionSymbolDataComparator> mSymbolDataList;
|
||||
std::map<std::string, SectionInfo> mSectionInfoList;
|
||||
|
||||
uint8_t mTrampolineId = 0;
|
||||
|
||||
|
||||
@@ -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 <coreinit/cache.h>
|
||||
@@ -28,32 +27,28 @@
|
||||
|
||||
using namespace ELFIO;
|
||||
|
||||
std::unique_ptr<PluginInformation>
|
||||
std::optional<PluginInformation>
|
||||
PluginInformationFactory::load(const PluginData &pluginData, std::vector<relocation_trampoline_entry_t> &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<const char *>(buffer.data()), buffer.size())) {
|
||||
DEBUG_FUNCTION_LINE_ERR("Can't process PluginData in elfio");
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto pluginInfo = make_unique_nothrow<PluginInformation>();
|
||||
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<uint8_t *[]>(sec_num);
|
||||
if (!destinationsData) {
|
||||
DEBUG_FUNCTION_LINE_ERR("Failed alloc memory for destinations array");
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
}
|
||||
std::span<uint8_t *> destinations(destinationsData.get(), sec_num);
|
||||
|
||||
@@ -85,13 +80,13 @@ PluginInformationFactory::load(const PluginData &pluginData, std::vector<relocat
|
||||
HeapMemoryFixedSize text_data(text_size);
|
||||
if (!text_data) {
|
||||
DEBUG_FUNCTION_LINE_ERR("Failed to alloc memory for the .text section (%d bytes)", text_size);
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
HeapMemoryFixedSize data_data(data_size);
|
||||
if (!data_data) {
|
||||
DEBUG_FUNCTION_LINE_ERR("Failed to alloc memory for the .data section (%d bytes)", data_size);
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < sec_num; ++i) {
|
||||
@@ -125,10 +120,10 @@ PluginInformationFactory::load(const PluginData &pluginData, std::vector<relocat
|
||||
}
|
||||
} else if (address >= 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<relocat
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Copy section %s %08X -> %08X (%d bytes)", psec->get_name().c_str(), p, destination, sectionSize);
|
||||
memcpy((void *) destination, p, sectionSize);
|
||||
}
|
||||
|
||||
auto sectionInfo = make_unique_nothrow<SectionInfo>(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::vector<relocat
|
||||
if (!linkSection(reader, psec->get_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::vector<relocat
|
||||
DCFlushRange((void *) data_data.data(), data_data.size());
|
||||
ICInvalidateRange((void *) data_data.data(), data_data.size());
|
||||
|
||||
pluginInfo->setTrampolineId(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::vector<relocat
|
||||
for (size_t j = 0; j < entries_count; j++) {
|
||||
wups_loader_hook_t *hook = &entries[j];
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Saving hook of plugin Type: %08X, target: %08X", hook->type, (void *) hook->target);
|
||||
auto hookData = make_unique_nothrow<HookData>((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<relocat
|
||||
cur_function->_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<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);
|
||||
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::vector<relocat
|
||||
if (type == STT_FUNC) { // We only care about functions.
|
||||
auto sectionVal = reader.sections[section];
|
||||
auto offsetVal = value - sectionVal->get_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<FunctionSymbolData>(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<relocat
|
||||
|
||||
if (totalSize > 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<RelocationData>(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]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
class PluginInformationFactory {
|
||||
public:
|
||||
static std::unique_ptr<PluginInformation>
|
||||
static std::optional<PluginInformation>
|
||||
load(const PluginData &pluginData, std::vector<relocation_trampoline_entry_t> &trampolineData, uint8_t trampolineId);
|
||||
|
||||
static bool
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -23,8 +23,6 @@
|
||||
|
||||
class PluginMetaInformation {
|
||||
public:
|
||||
PluginMetaInformation(const PluginMetaInformation &other);
|
||||
|
||||
[[nodiscard]] const std::string &getName() const {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -22,11 +22,11 @@
|
||||
#include "utils/wiiu_zlib.hpp"
|
||||
#include <memory>
|
||||
|
||||
std::unique_ptr<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(const PluginData &pluginData, PluginParseErrors &error) {
|
||||
std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(const PluginData &pluginData, PluginParseErrors &error) {
|
||||
return loadPlugin(pluginData.getBuffer(), error);
|
||||
}
|
||||
|
||||
std::unique_ptr<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(std::string_view filePath, PluginParseErrors &error) {
|
||||
std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(std::string_view filePath, PluginParseErrors &error) {
|
||||
std::vector<uint8_t> buffer;
|
||||
if (FSUtils::LoadFileToMem(filePath, buffer) < 0) {
|
||||
DEBUG_FUNCTION_LINE_ERR("Failed to load file to memory");
|
||||
@@ -36,7 +36,7 @@ std::unique_ptr<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(
|
||||
return loadPlugin(buffer, error);
|
||||
}
|
||||
|
||||
std::unique_ptr<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(std::span<const uint8_t> buffer, PluginParseErrors &error) {
|
||||
std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(std::span<const uint8_t> 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<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(
|
||||
if (!reader.load(reinterpret_cast<const char *>(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<PluginMetaInformation>(new PluginMetaInformation);
|
||||
PluginMetaInformation pluginInfo;
|
||||
|
||||
uint32_t sec_num = reader.sections.size();
|
||||
|
||||
@@ -89,28 +89,28 @@ std::unique_ptr<PluginMetaInformation> 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<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(
|
||||
}
|
||||
}
|
||||
|
||||
pluginInfo->setSize(pluginSize);
|
||||
pluginInfo.setSize(pluginSize);
|
||||
|
||||
error = PLUGIN_PARSE_ERROR_NONE;
|
||||
|
||||
|
||||
@@ -36,9 +36,9 @@ enum PluginParseErrors {
|
||||
|
||||
class PluginMetaInformationFactory {
|
||||
public:
|
||||
static std::unique_ptr<PluginMetaInformation> loadPlugin(const PluginData &pluginData, PluginParseErrors &error);
|
||||
static std::optional<PluginMetaInformation> loadPlugin(const PluginData &pluginData, PluginParseErrors &error);
|
||||
|
||||
static std::unique_ptr<PluginMetaInformation> loadPlugin(std::string_view filePath, PluginParseErrors &error);
|
||||
static std::optional<PluginMetaInformation> loadPlugin(std::string_view filePath, PluginParseErrors &error);
|
||||
|
||||
static std::unique_ptr<PluginMetaInformation> loadPlugin(std::span<const uint8_t> buffer, PluginParseErrors &error);
|
||||
static std::optional<PluginMetaInformation> loadPlugin(std::span<const uint8_t> buffer, PluginParseErrors &error);
|
||||
};
|
||||
|
||||
@@ -9,8 +9,6 @@ public:
|
||||
(static_cast<uint64_t>(minor) << 16) |
|
||||
static_cast<uint64_t>(revision)) {}
|
||||
|
||||
WUPSVersion(const WUPSVersion &other) = default;
|
||||
|
||||
static std::optional<WUPSVersion> createFromString(const std::string &versionStr) {
|
||||
char *end;
|
||||
errno = 0; // Initialize errno before calling strtol
|
||||
|
||||
Reference in New Issue
Block a user