From 21b6b4cf214877c16aeab17fdf1ccd7edf969b74 Mon Sep 17 00:00:00 2001 From: Mr-Wiseguy Date: Thu, 30 Jan 2025 02:57:10 -0500 Subject: [PATCH] Fix issue with regenerating patched functions with no base functions regenerated, add 1kB of padding between mods to mitigate OOB accesses in mods, update N64Recomp --- N64Recomp | 2 +- librecomp/src/mods.cpp | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/N64Recomp b/N64Recomp index b18e0ca..198de1b 160000 --- a/N64Recomp +++ b/N64Recomp @@ -1 +1 @@ -Subproject commit b18e0ca2dd359d62dcc019771f0ccc4a1302bd03 +Subproject commit 198de1b5cf6e58415948588584750c51562d58dd diff --git a/librecomp/src/mods.cpp b/librecomp/src/mods.cpp index 915edc2..c9a0541 100644 --- a/librecomp/src/mods.cpp +++ b/librecomp/src/mods.cpp @@ -1320,13 +1320,15 @@ std::vector recomp::mods::ModContext::regener } // Apply the regenlist. - regenerated_code_handle = apply_regenlist(regenlist, decompressed_rom); - if (!regenerated_code_handle || !regenerated_code_handle->good()) { - regenerated_code_handle.reset(); - ret.emplace_back(ModLoadErrorDetails{ - "", ModLoadError::FailedToLoadCode, error_to_string(CodeModLoadError::InternalError) - }); - return ret; + if (!regenlist.functions.empty()) { + regenerated_code_handle = apply_regenlist(regenlist, decompressed_rom); + if (!regenerated_code_handle || !regenerated_code_handle->good()) { + regenerated_code_handle.reset(); + ret.emplace_back(ModLoadErrorDetails{ + "", ModLoadError::FailedToLoadCode, error_to_string(CodeModLoadError::InternalError) + }); + return ret; + } } if (!regenlist.patched_hooks.empty()) { @@ -1484,6 +1486,8 @@ recomp::mods::CodeModLoadError recomp::mods::ModContext::init_mod_code(uint8_t* cur_section_addr += section.size + section.bss_size; // Align the next section's address to 16 bytes. cur_section_addr = (cur_section_addr + 15) & ~15; + // Add some empty space between mods to act as a buffer for misbehaving mods that have out of bounds accesses. + cur_section_addr += 0x400; } // Iterate over each section again after loading them to perform R_MIPS_32 relocations.