From 1b0eae755ab8caa23396d62d4ecf18858d015b17 Mon Sep 17 00:00:00 2001 From: baldurk Date: Sat, 9 Aug 2014 01:44:45 +0100 Subject: [PATCH] Bail out immediately if IAT entry is already hooked * This avoids going into VirtualProtect changing the page access while code may potentially be executing these areas of memory (since the module is hooked, and may have returned to user code) --- renderdoc/os/win32/win32_hook.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/renderdoc/os/win32/win32_hook.cpp b/renderdoc/os/win32/win32_hook.cpp index a69729857..f443d6de4 100644 --- a/renderdoc/os/win32/win32_hook.cpp +++ b/renderdoc/os/win32/win32_hook.cpp @@ -50,6 +50,9 @@ struct FunctionHook { DWORD oldProtection = PAGE_EXECUTE; + if(*IATentry == hookptr) + return; + BOOL success = TRUE; success = VirtualProtect(IATentry, sizeof(void*), PAGE_READWRITE, &oldProtection); @@ -59,7 +62,7 @@ struct FunctionHook return; } - if(origptr && *origptr == NULL && *IATentry != hookptr) *origptr = *IATentry; + if(origptr && *origptr == NULL) *origptr = *IATentry; *IATentry = hookptr;