From 43a18b56d79c6bfa028ad30944ce7578a9af5ccf Mon Sep 17 00:00:00 2001 From: Maschell Date: Wed, 8 May 2024 17:49:25 +0200 Subject: [PATCH] Small fixes to the .wps loading, return nullptr instead of OSFatal, add asserts instead of OSFatal --- source/PluginManagement.cpp | 2 +- source/globals.h | 2 +- source/plugin/PluginInformationFactory.cpp | 24 ++++++++++++++++------ source/utils/config/CategoryRenderer.cpp | 13 +++--------- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/source/PluginManagement.cpp b/source/PluginManagement.cpp index 3b97fb8..d5ce618 100644 --- a/source/PluginManagement.cpp +++ b/source/PluginManagement.cpp @@ -42,7 +42,7 @@ PluginManagement::loadPlugins(const std::set> &plugi if (!PluginManagement::DoFunctionPatches(plugins)) { DEBUG_FUNCTION_LINE_ERR("Failed to patch functions"); - OSFatal("Failed to patch functions"); + OSFatal("WiiUPluginLoaderBackend: Failed to patch functions"); } return plugins; diff --git a/source/globals.h b/source/globals.h index 7688c20..4f6222f 100644 --- a/source/globals.h +++ b/source/globals.h @@ -9,7 +9,7 @@ #include #include -#define VERSION "v0.3.1" +#define VERSION "v0.3.2" #define VERSION_FULL VERSION VERSION_EXTRA extern StoredBuffer gStoredTVBuffer; diff --git a/source/plugin/PluginInformationFactory.cpp b/source/plugin/PluginInformationFactory.cpp index c83b911..1e8b929 100644 --- a/source/plugin/PluginInformationFactory.cpp +++ b/source/plugin/PluginInformationFactory.cpp @@ -67,12 +67,12 @@ PluginInformationFactory::load(const PluginData &pluginData, std::vectorget_size(); auto address = (uint32_t) psec->get_address(); if ((address >= 0x02000000) && address < 0x10000000) { - text_size += sectionSize; + text_size += sectionSize + psec->get_addr_align(); } else if ((address >= 0x10000000) && address < 0xC0000000) { - data_size += sectionSize; + data_size += sectionSize + psec->get_addr_align(); } if (psec->get_name().starts_with(".wups.")) { - data_size += sectionSize; + data_size += sectionSize + psec->get_addr_align(); } } } @@ -107,7 +107,10 @@ PluginInformationFactory::load(const PluginData &pluginData, std::vector (uint32_t) text_data.data() + text_size) { DEBUG_FUNCTION_LINE_ERR("Tried to overflow .text buffer. %08X > %08X", destination + sectionSize, (uint32_t) text_data.data() + text_data.size()); - OSFatal("WUPSLoader: Tried to overflow buffer"); + return std::nullopt; + } else if (destination < (uint32_t) text_data.data()) { + DEBUG_FUNCTION_LINE_ERR("Tried to underflow .text buffer. %08X < %08X", destination, (uint32_t) text_data.data()); + return std::nullopt; } } else if ((address >= 0x10000000) && address < 0xC0000000) { destination += (uint32_t) data_data.data(); @@ -115,8 +118,11 @@ PluginInformationFactory::load(const PluginData &pluginData, std::vectorget_index()] = (uint8_t *) data_data.data(); if (destination + sectionSize > (uint32_t) data_data.data() + data_data.size()) { - DEBUG_FUNCTION_LINE_ERR("Tried to overflow .data buffer. %08X > %08X", destination + sectionSize, (uint32_t) text_data.data() + text_data.size()); - OSFatal("WUPSLoader: Tried to overflow buffer"); + DEBUG_FUNCTION_LINE_ERR("Tried to overflow .data buffer. %08X > %08X", destination + sectionSize, (uint32_t) data_data.data() + data_data.size()); + return std::nullopt; + } else if (destination < (uint32_t) data_data.data()) { + DEBUG_FUNCTION_LINE_ERR("Tried to underflow .data buffer. %08X < %08X", destination, (uint32_t) text_data.data()); + return std::nullopt; } } else if (address >= 0xC0000000) { DEBUG_FUNCTION_LINE_ERR("Loading section from 0xC0000000 is NOT supported"); @@ -128,6 +134,12 @@ PluginInformationFactory::load(const PluginData &pluginData, std::vectorget_data(); + uint32_t address_align = psec->get_addr_align(); + if ((destination & (address_align - 1)) != 0) { + DEBUG_FUNCTION_LINE_WARN("Address not aligned: %08X %08X", destination, address_align); + return std::nullopt; + } + if (psec->get_type() == SHT_NOBITS) { DEBUG_FUNCTION_LINE_VERBOSE("memset section %s %08X to 0 (%d bytes)", psec->get_name().c_str(), destination, sectionSize); memset((void *) destination, 0, sectionSize); diff --git a/source/utils/config/CategoryRenderer.cpp b/source/utils/config/CategoryRenderer.cpp index d821176..965976a 100644 --- a/source/utils/config/CategoryRenderer.cpp +++ b/source/utils/config/CategoryRenderer.cpp @@ -11,22 +11,15 @@ CategoryRenderer::CategoryRenderer(const GeneralConfigInformation *info, const W for (uint32_t i = 0; i < cat->getCategories().size() + cat->getItems().size(); i++) { if (i < cat->getCategories().size()) { auto item = make_unique_nothrow(cat->getCategories()[i].get()); - if (!item) { - DEBUG_FUNCTION_LINE_ERR("Failed to alloc ConfigRendererItemCategory"); - OSFatal("WiiUPluginBackend::CategoryRenderer::CategoryRenderer() Failed to alloc ConfigRendererItemCategory"); - } + assert(item); mItemRenderer.push_back(std::move(item)); } else { auto itemIndex = (int32_t) (i - cat->getCategories().size()); if (itemIndex < 0 || itemIndex >= (int32_t) cat->getItems().size()) { - DEBUG_FUNCTION_LINE_ERR("unexpected index"); - OSFatal("WiiUPluginBackend::CategoryRenderer::CategoryRenderer() unexpected index"); + assert(false); } auto item = make_unique_nothrow(cat->getItems()[itemIndex].get()); - if (!item) { - DEBUG_FUNCTION_LINE_ERR("Failed to alloc ConfigRendererItemCategory"); - OSFatal("WiiUPluginBackend::CategoryRenderer::CategoryRenderer() Failed to alloc ConfigRendererItem"); - } + assert(item); mItemRenderer.push_back(std::move(item)); } }