From adfb830b4da15b368806fbc9d5d65a55bc85c714 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Wed, 15 Jul 2026 00:08:19 -0600 Subject: [PATCH] hook: Fix thunk re-resolution on Windows --- src/dusk/mods/svc/hook.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/dusk/mods/svc/hook.cpp b/src/dusk/mods/svc/hook.cpp index b5eb60c216..34d7d54aa7 100644 --- a/src/dusk/mods/svc/hook.cpp +++ b/src/dusk/mods/svc/hook.cpp @@ -118,10 +118,19 @@ void sort_hooks(std::vector& hooks) { }); } +// Once a hook is installed, funchook has patched the target's entry: its bytes lead to the +// detour, not the function, so canonicalization must stop there. +[[maybe_unused]] bool installed_target(void* addr) { + return s_installed.contains(reinterpret_cast(addr)); +} + // Follow E9/FF25 chains to skip MSVC incremental-link and import stubs. void* resolve_import_thunk(void* addr) { #if defined(_WIN32) && (defined(_M_X64) || defined(__x86_64__)) for (int i = 0; i < 8; ++i) { + if (installed_target(addr)) { + break; + } const auto* p = static_cast(addr); if (p[0] == 0x48 && p[1] == 0xFF && p[2] == 0x25) { // lld emits a REX.W prefix ++p; @@ -145,6 +154,9 @@ void* resolve_import_thunk(void* addr) { // incremental-link stubs are a plain `b`, or `adrp x16; add x16, x16, #off; br x16` // range-extension thunks when the target is out of B range. for (int i = 0; i < 8; ++i) { + if (installed_target(addr)) { + break; + } const auto* p = static_cast(addr); uint32_t insn0, insn1, insn2; std::memcpy(&insn0, p, 4);