diff options
author | Michael Smith <mikesmiffy128@gmail.com> | 2023-06-10 16:44:19 +0100 |
---|---|---|
committer | Michael Smith <mikesmiffy128@gmail.com> | 2023-06-10 16:51:02 +0100 |
commit | 1c4318331663b152b0b298bd2c9e5c971506a86b (patch) | |
tree | a402681cb84b491819ba5018525c16340110fd4d /src/hook.c | |
parent | 602a18977d500ad068fd63fbedcafb630c29ee72 (diff) |
Prune some comments and tidy up other minor things
Diffstat (limited to 'src/hook.c')
-rw-r--r-- | src/hook.c | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -47,9 +47,8 @@ bool hook_init(void) { void *hook_inline(void *func_, void *target) { uchar *func = func_; - // dumb hack: rather than correcting jmp offsets and having to painstakingly - // track them all, just look for the underlying thing being jmp-ed to and - // hook _that_. + // dumb hack: if we hit some thunk that immediately jumps elsewhere (which + // seems common for win32 API functions), hook the underlying thing instead. while (*func == X86_JMPIW) func += mem_loadoffset(func + 1) + 5; if (!os_mprot(func, 5, PAGE_EXECUTE_READWRITE)) return false; int len = 0; @@ -76,6 +75,7 @@ void *hook_inline(void *func_, void *target) { } // for simplicity, just bump alloc the trampoline. no need to free anyway if (nexttrampoline - trampolines > sizeof(trampolines) - len - 6) goto nosp; + // TODO(opt): stop pretending to be thread-safe, it's just slowing us down uchar *trampoline = (uchar *)InterlockedExchangeAdd( (volatile long *)&nexttrampoline, len + 6); // avoid TOCTOU |