Recently, iv encountered simlar problems as this when I tried my first DRX hook to a game CFunction using C#.
Ive already got the correct THREAD_ALL_ACCESS handle to the wow main thread which can be used to suspend & resume it. Besides, this handle can be used to retrieve the CONTEXT info(Iv tried to set CONTEXT.ContextFlags=CONTEXT_SEGMENTS and got some EDS,ECS value etc..)
However, when i tried to set CONTEXT.ContextFlags=CONTEXT_DEBUG_REGISTERS and DR0=breakpointaddress, DR6=0, DR7=1, and add an SEH or VEH function, the breakpoint seemed never working.
The C# codes are below
Code:
//My endscene hook
private static uint MyEndScene(IntPtr D3D9Device)
{
Win32.WriteUInt32(VTableAddr + memEndSceneOffset2, (uint)EndSceneOriginalPtr);
//Add a VEH
FilterExceptionHandlerOriginial = Win32.SetUnhandledExceptionFilter(GetGUIDByKeywordHandler);
Win32.MainThreadID = Win32.GetCurrentThreadId();
Win32.MainThreadHandle = Win32.OpenThread(Win32.THREAD_ACCESS.THREAD_ALL_ACCESS, false, Win32.MainThreadID);
return OriginalEndScene(D3D9Device);
}
//Install a DR hook to "GetGUIDByKeyword"
private static void InstallDRHook()
{
Win32.SuspendThread(Win32.MainThreadHandle);
Win32.CONTEXT ctx = new Win32.CONTEXT();
ctx.ContextFlags = Win32.CONTEXT_FLAGS.CONTEXT_DEBUG_REGISTERS;
Win32.GetThreadContext(Win32.MainThreadHandle, ref ctx);
ctx.Dr0 = memGetGUIDByKeyword; //This is the address from INFO DUMP
ctx.Dr6 = 0;
ctx.Dr7 = 1;
Win32.SetThreadContext(Win32.MainThreadHandle, ref ctx);
Win32.ResumeThread(Win32.MainThreadHandle);
}
//SEH
private static Win32.FilterExceptionHandlerDelegate GetGUIDByKeywordHandler = GetGUIDByKeywordException;
private static uint GetGUIDByKeywordException([In] ref Win32.EXCEPTIONS breakException)
{
Log("NOW BREAKPOINT:{0},{1}", breakException.ExceptionRecord.ExceptionCode, breakException.ExceptionRecord.ExceptionAddress);
return 0xffffffff;
}
Could anybody plz show me a way out? AM I missing sth?