DebugActiveProcess(pid);
for(;

{
(WaitForDebugEvent (&DebugEv, INFINITE));
{
switch (DebugEv.dwDebugEventCode)
{
case EXCEPTION_DEBUG_EVENT:
switch (DebugEv.u.Exception.ExceptionRecord.ExceptionCode)
{
case EXCEPTION_BREAKPOINT:
if (DoneOnce == FALSE)//Breakpoint sent by windows
{
MessageBox(NULL, "windows breakpoint", "warning!", MB_OK);
dwContinueStatus = DBG_CONTINUE;
DoneOnce = TRUE;
break;
}
if (DoneOnce == TRUE)
{
if (DebugEv.u.Exception.ExceptionRecord.ExceptionAddress==((LPVOID)0x00401824))
// If the breakpoint come from 0x401824 address then Message Box breakpoint ok
{
MessageBox(NULL, "Breakpoint ok!!!", "warning!", MB_OK);
Context.ContextFlags = CONTEXT_CONTROL;
//WriteProcessMemory(hand, (void*)0x00401824, &OriginalByte,1, &bytes);
//GetThreadContext(DebugEv.u.CreateProcessInfo.hThread, &Context);
//Context.Eip--;
//SetThreadContext(DebugEv.u.CreateProcessInfo.hThread, &Context);
dwContinueStatus = DBG_CONTINUE;
break;
}
else // Message box Breakpoint not handled
{
MessageBox(NULL, "breakpoint Not handled", "warning!", MB_OK);
dwContinueStatus = DBG_EXCEPTION_NOT_HANDLED;
break;
}
}
break;
case EXCEPTION_ACCESS_VIOLATION:// Message box access violation
MessageBox(NULL, "Access Violation", "warning!", MB_OK);
dwContinueStatus = DBG_EXCEPTION_NOT_HANDLED;
break;
case EXCEPTION_SINGLE_STEP:// Never raise
MessageBox(NULL, "SingleStep", "warning!", MB_OK);
dwContinueStatus = DBG_EXCEPTION_NOT_HANDLED;
break;
default:
// Handle other exceptions
MessageBox(NULL, "Other exception", "warning!", MB_OK);
dwContinueStatus = DBG_EXCEPTION_NOT_HANDLED;
break;
}
break;
case EXIT_PROCESS_DEBUG_EVENT: //Exit message box
MessageBox(NULL, "Exiting", "warning!", MB_OK);
dwContinueStatus = DBG_CONTINUE;
exit(1);
break;
}
}
ContinueDebugEvent (DebugEv.dwProcessId,DebugEv.dwThreadId,dwContinueStatus);
}