diff options
| author | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2025-11-16 12:01:48 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-16 12:01:48 +0000 |
| commit | 9b006b2c8533bae1e528bd123be209453787b9b7 (patch) | |
| tree | 4814be71407fe676feac5fd1e8debb8987c0add5 /src/plugins/HookSystem.cpp | |
| parent | b35f78431f5a8cec1df1ff8595b239fcb0ba3e4c (diff) | |
plugin/hook: disallow multiple hooks per function (#12320)
this was never safe. After recent changes, it's become even less so. Just disallow it.
ref #11992
Diffstat (limited to 'src/plugins/HookSystem.cpp')
| -rw-r--r-- | src/plugins/HookSystem.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/plugins/HookSystem.cpp b/src/plugins/HookSystem.cpp index c5def6a5..031b1def 100644 --- a/src/plugins/HookSystem.cpp +++ b/src/plugins/HookSystem.cpp @@ -144,6 +144,12 @@ bool CFunctionHook::hook() { return false; #endif + if (g_pFunctionHookSystem->m_activeHooks.contains(rc<uint64_t>(m_source))) { + // TODO: return actual error codes... + Debug::log(ERR, "[functionhook] failed, function is already hooked"); + return false; + } + // jmp rel32 // offset for relative addr: 1 static constexpr uint8_t RELATIVE_JMP_ADDRESS[] = {0xE9, 0x00, 0x00, 0x00, 0x00}; @@ -231,6 +237,8 @@ bool CFunctionHook::hook() { m_active = true; m_hookLen = ORIGSIZE; + g_pFunctionHookSystem->m_activeHooks.emplace(rc<uint64_t>(m_source)); + return true; } @@ -243,6 +251,8 @@ bool CFunctionHook::unhook() { if (!m_active) return false; + g_pFunctionHookSystem->m_activeHooks.erase(rc<uint64_t>(m_source)); + // allow write to src mprotect(sc<uint8_t*>(m_source) - rc<uint64_t>(m_source) % sysconf(_SC_PAGE_SIZE), sysconf(_SC_PAGE_SIZE), PROT_READ | PROT_WRITE | PROT_EXEC); |
