-
Notifications
You must be signed in to change notification settings - Fork 333
Description
I'd like to inform you of a bug of mhook 2.4.
The bug causes stack overflow when hooking VirtualProtect and calling the original VirtualProtect from the hooked VirtualProtect, because VirtualProtect called from Mhook_SetHook function calls not the original VirtualProtect but the hooked VirtualProtect, therefore, the hooked VirtualProtect calls the original VirtualProtect recursively until stack overflow is occurred.
Here is simple sample code that causes stack overflow:
BOOL ( WINAPI RealVirtualProtect )( LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWORD lpflOldProtect ) = (BOOL ( WINAPI )( LPVOID, SIZE_T, DWORD, PDWORD )) GetProcAddress( GetModuleHandleA( "kernel32.dll" ), "VirtualProtect" );
BOOL WINAPI HookVirtualProtect( LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWORD lpflOldProtect )
{
return RealVirtualProtect( lpAddress, dwSize, flNewProtect, lpflOldProtect );
}
int main()
{
Mhook_SetHook( (PVOID*) &RealVirtualProtect, HookVirtualProtect );
return 0;
}
My workaround is to call the original VirtualProtect in Mhook_SetHook function.
Thank you in advance.