From 1f18d06f9b6f999c3f406a47122651babffd5f98 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Fri, 29 May 2026 09:18:23 +0800 Subject: [PATCH] Reduced the number of trailing NOPs for MakeCall/Jump * when the trailing length is longer than 4 bytes, it will use a mix of 5-byte long NOPs and single-byte NOPs. --- sfall/Modules/DebugEditor.cpp | 3 +-- sfall/SafeWrite.cpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/sfall/Modules/DebugEditor.cpp b/sfall/Modules/DebugEditor.cpp index 245084f4..0284a59d 100644 --- a/sfall/Modules/DebugEditor.cpp +++ b/sfall/Modules/DebugEditor.cpp @@ -551,8 +551,7 @@ static void DebugModePatch() { // Fix to prevent crashes when there is a '%' character in the printed message if (dbgMode > 1) { - MakeCall(0x4C703F, debug_log_hack); - BlockCall(0x4C7044); // just nop code + MakeCall(0x4C703F, debug_log_hack, 5); } // replace calling debug_printf_ with _debug_func, to avoid buffer overflow with messages longer than 260 bytes MakeCall(0x45540F, op_display_msg_hack); diff --git a/sfall/SafeWrite.cpp b/sfall/SafeWrite.cpp index 7e947ef5..528f26e7 100644 --- a/sfall/SafeWrite.cpp +++ b/sfall/SafeWrite.cpp @@ -24,9 +24,16 @@ static __declspec(noinline) void __stdcall SafeWriteFunc(BYTE code, DWORD addr, *((BYTE*)addr) = code; *((DWORD*)(addr + 1)) = data; - do { + while (len >= 5) { + *((DWORD*)addrMem) = 0x00441F0F; // 5-byte long NOP (0F1F4400-XX) + addrMem += 5; + len -= 5; + } + // Fill the remaining bytes (1-4 bytes) with single-byte NOPs + while (len > 0) { *((BYTE*)addrMem++) = CodeType::Nop; - } while (--len); + len--; + } VirtualProtect((void*)addr, protectLen, oldProtect, &oldProtect); CheckConflict(addr, protectLen);