Esempio n. 1
0
void DebugLoop()
{
    DEBUG_EVENT de;
    DWORD dwContinueStatus;

    // Debuggee 로부터 event 가 발생할 때까지 기다림
    while( WaitForDebugEvent(&de, INFINITE) )
    {
        dwContinueStatus = DBG_CONTINUE;

        // Debuggee 프로세스 생성 혹은 attach 이벤트
        if( CREATE_PROCESS_DEBUG_EVENT == de.dwDebugEventCode )
        {
            OnCreateProcessDebugEvent(&de);
        }
        // 예외 이벤트
        else if( EXCEPTION_DEBUG_EVENT == de.dwDebugEventCode )
        {
            if( OnExceptionDebugEvent(&de) )
                continue;
        }
        // Debuggee 프로세스 종료 이벤트
        else if( EXIT_PROCESS_DEBUG_EVENT == de.dwDebugEventCode )
        {
            // debuggee 종료 -> debugger 종료
            break;
        }

        // Debuggee 의 실행을 재개시킴
        ContinueDebugEvent(de.dwProcessId, de.dwThreadId, dwContinueStatus);
    }
}
void DebugLoop()
{
	DEBUG_EVENT de;
	//int dwContinuesStatus;
	
	//wait for event....
	while(WaitForDebugEvent(&de,INFINITE))
	{
		//dwContinuesStatus=0x00010002;
		//被调试进程生成或者附加事件
		if(CREATE_PROCESS_DEBUG_EVENT==de.dwDebugEventCode) 
			{
				printf("created debug !\n");
				OnCreateProcessDebugEvent(&de);
				printf("seccessfully created int 3\n");
			}
		//异常事件
		else if (EXCEPTION_DEBUG_EVENT==de.dwDebugEventCode) 
			{
				printf("Exception debug event !code =%X\n",de.dwDebugEventCode);
				if(OnExceptionDebugEvent(&de))
					{
						printf("on exception debug event\n");
						continue;
					}
			}
			
	
	//被调试进程终止事件
	else if (EXIT_PROCESS_DEBUG_EVENT==de.dwDebugEventCode) //被调试者终止-调试器终止 
		{
			printf("debugee exited \n");
			break;
		}
	//再次运行被调试者
	ContinueDebugEvent(de.dwProcessId,de.dwThreadId,0x00010002) ;
	}
}