mirror of
https://github.com/wiiu-env/WiiUPluginLoaderBackend.git
synced 2026-10-01 07:10:52 -05:00
Improve error message when parsing a plugin failed
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#include "utils/logger.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
PluginData::PluginData(const std::vector<uint8_t> &input) : length(input.size()) {
|
||||
PluginData::PluginData(const std::vector<uint8_t> &input, std::string source) : length(input.size()), mSource(std::move(source)) {
|
||||
auto data_copy = make_unique_nothrow<uint8_t[]>(length);
|
||||
if (!data_copy) {
|
||||
DEBUG_FUNCTION_LINE_ERR("Failed to allocate space on default heap");
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
class PluginData {
|
||||
public:
|
||||
explicit PluginData(const std::vector<uint8_t> &buffer);
|
||||
explicit PluginData(const std::vector<uint8_t> &buffer, std::string source);
|
||||
|
||||
uint32_t getHandle() {
|
||||
return (uint32_t) this;
|
||||
@@ -33,4 +33,5 @@ public:
|
||||
|
||||
size_t length = 0;
|
||||
std::unique_ptr<uint8_t[]> buffer;
|
||||
std::string mSource;
|
||||
};
|
||||
|
||||
@@ -81,15 +81,15 @@ std::optional<std::unique_ptr<PluginData>> PluginDataFactory::load(const std::st
|
||||
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Loaded file!");
|
||||
|
||||
return load(result);
|
||||
return load(result, filename);
|
||||
}
|
||||
|
||||
std::optional<std::unique_ptr<PluginData>> PluginDataFactory::load(const std::vector<uint8_t> &buffer) {
|
||||
std::optional<std::unique_ptr<PluginData>> PluginDataFactory::load(const std::vector<uint8_t> &buffer, const std::string &source) {
|
||||
if (buffer.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto res = make_unique_nothrow<PluginData>(buffer);
|
||||
auto res = make_unique_nothrow<PluginData>(buffer, source);
|
||||
if (!res) {
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -31,5 +31,5 @@ public:
|
||||
|
||||
static std::optional<std::unique_ptr<PluginData>> load(const std::string &path);
|
||||
|
||||
static std::optional<std::unique_ptr<PluginData>> load(const std::vector<uint8_t> &buffer);
|
||||
static std::optional<std::unique_ptr<PluginData>> load(const std::vector<uint8_t> &buffer, const std::string &source);
|
||||
};
|
||||
|
||||
@@ -22,50 +22,55 @@
|
||||
#include "utils/wiiu_zlib.hpp"
|
||||
#include <memory>
|
||||
|
||||
std::optional<std::unique_ptr<PluginMetaInformation>> PluginMetaInformationFactory::loadPlugin(const std::shared_ptr<PluginData> &pluginData) {
|
||||
std::optional<std::unique_ptr<PluginMetaInformation>> PluginMetaInformationFactory::loadPlugin(const std::shared_ptr<PluginData> &pluginData, PluginParseErrors &error) {
|
||||
if (!pluginData->buffer) {
|
||||
error = PLUGIN_PARSE_ERROR_BUFFER_EMPTY;
|
||||
DEBUG_FUNCTION_LINE_ERR("Buffer is empty");
|
||||
return {};
|
||||
}
|
||||
ELFIO::elfio reader(new wiiu_zlib);
|
||||
if (!reader.load(reinterpret_cast<const char *>(pluginData->buffer.get()), pluginData->length)) {
|
||||
error = PLUGIN_PARSE_ERROR_ELFIO_PARSE_FAILED;
|
||||
DEBUG_FUNCTION_LINE_ERR("Can't process PluginData in elfio");
|
||||
return {};
|
||||
}
|
||||
return loadPlugin(reader);
|
||||
return loadPlugin(reader, error);
|
||||
}
|
||||
|
||||
std::optional<std::unique_ptr<PluginMetaInformation>> PluginMetaInformationFactory::loadPlugin(const std::string &filePath) {
|
||||
std::optional<std::unique_ptr<PluginMetaInformation>> PluginMetaInformationFactory::loadPlugin(const std::string &filePath, PluginParseErrors &error) {
|
||||
ELFIO::elfio reader(new wiiu_zlib);
|
||||
|
||||
uint8_t *buffer = nullptr;
|
||||
uint32_t length = 0;
|
||||
if (FSUtils::LoadFileToMem(filePath.c_str(), &buffer, &length) < 0) {
|
||||
DEBUG_FUNCTION_LINE_ERR("Failed to load file to memory");
|
||||
error = PLUGIN_PARSE_ERROR_IO_ERROR;
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!reader.load(reinterpret_cast<const char *>(buffer), length)) {
|
||||
error = PLUGIN_PARSE_ERROR_ELFIO_PARSE_FAILED;
|
||||
DEBUG_FUNCTION_LINE_ERR("Can't process PluginData in elfio");
|
||||
return {};
|
||||
}
|
||||
auto res = loadPlugin(reader);
|
||||
auto res = loadPlugin(reader, error);
|
||||
free(buffer);
|
||||
return res;
|
||||
}
|
||||
|
||||
std::optional<std::unique_ptr<PluginMetaInformation>> PluginMetaInformationFactory::loadPlugin(char *buffer, size_t size) {
|
||||
std::optional<std::unique_ptr<PluginMetaInformation>> PluginMetaInformationFactory::loadPlugin(char *buffer, size_t size, PluginParseErrors &error) {
|
||||
ELFIO::elfio reader(new wiiu_zlib);
|
||||
|
||||
if (!reader.load(reinterpret_cast<const char *>(buffer), size)) {
|
||||
error = PLUGIN_PARSE_ERROR_ELFIO_PARSE_FAILED;
|
||||
DEBUG_FUNCTION_LINE_ERR("Can't find or process ELF file");
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return loadPlugin(reader);
|
||||
return loadPlugin(reader, error);
|
||||
}
|
||||
|
||||
std::optional<std::unique_ptr<PluginMetaInformation>> PluginMetaInformationFactory::loadPlugin(const ELFIO::elfio &reader) {
|
||||
std::optional<std::unique_ptr<PluginMetaInformation>> PluginMetaInformationFactory::loadPlugin(const ELFIO::elfio &reader, PluginParseErrors &error) {
|
||||
size_t pluginSize = 0;
|
||||
|
||||
auto pluginInfo = std::unique_ptr<PluginMetaInformation>(new PluginMetaInformation);
|
||||
@@ -120,6 +125,7 @@ std::optional<std::unique_ptr<PluginMetaInformation>> PluginMetaInformationFacto
|
||||
pluginInfo->setStorageId(value);
|
||||
} else if (key == "wups") {
|
||||
if (value != "0.7.1") {
|
||||
error = PLUGIN_PARSE_ERROR_INCOMPATIBLE_VERSION;
|
||||
DEBUG_FUNCTION_LINE_ERR("Warning: Ignoring plugin - Unsupported WUPS version: %s.", value.c_str());
|
||||
return std::nullopt;
|
||||
}
|
||||
@@ -132,5 +138,7 @@ std::optional<std::unique_ptr<PluginMetaInformation>> PluginMetaInformationFacto
|
||||
|
||||
pluginInfo->setSize(pluginSize);
|
||||
|
||||
error = PLUGIN_PARSE_ERROR_NONE;
|
||||
|
||||
return pluginInfo;
|
||||
}
|
||||
|
||||
@@ -25,13 +25,22 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
enum PluginParseErrors {
|
||||
PLUGIN_PARSE_ERROR_NONE,
|
||||
PLUGIN_PARSE_ERROR_UNKNOWN,
|
||||
PLUGIN_PARSE_ERROR_INCOMPATIBLE_VERSION,
|
||||
PLUGIN_PARSE_ERROR_BUFFER_EMPTY,
|
||||
PLUGIN_PARSE_ERROR_ELFIO_PARSE_FAILED,
|
||||
PLUGIN_PARSE_ERROR_IO_ERROR,
|
||||
};
|
||||
|
||||
class PluginMetaInformationFactory {
|
||||
public:
|
||||
static std::optional<std::unique_ptr<PluginMetaInformation>> loadPlugin(const std::shared_ptr<PluginData> &pluginData);
|
||||
static std::optional<std::unique_ptr<PluginMetaInformation>> loadPlugin(const std::shared_ptr<PluginData> &pluginData, PluginParseErrors &error);
|
||||
|
||||
static std::optional<std::unique_ptr<PluginMetaInformation>> loadPlugin(const std::string &filePath);
|
||||
static std::optional<std::unique_ptr<PluginMetaInformation>> loadPlugin(const std::string &filePath, PluginParseErrors &error);
|
||||
|
||||
static std::optional<std::unique_ptr<PluginMetaInformation>> loadPlugin(char *buffer, size_t size);
|
||||
static std::optional<std::unique_ptr<PluginMetaInformation>> loadPlugin(char *buffer, size_t size, PluginParseErrors &error);
|
||||
|
||||
static std::optional<std::unique_ptr<PluginMetaInformation>> loadPlugin(const ELFIO::elfio &reader);
|
||||
static std::optional<std::unique_ptr<PluginMetaInformation>> loadPlugin(const ELFIO::elfio &reader, PluginParseErrors &error);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user