请问DebugActiveProcess  WaitforDebugEvent  ContinueDebugEvent SetThreadContext  这些函数如何使用  MSDN中都是英文没能完全理解  
希望能够用这些函数写个例子给我看看      小弟万分感谢

解决方案 »

  1.   

    CreateProcess(..., DEBUG_PROCESS, ...) or DebugActiveProcess(dwProcessId)DEBUG_EVENT de;
    BOOL bContinue = TRUE;
    DWORD dwContinueStatus;while(bContinue)
    {
      bContinue = WaitForDebugEvent(&de, INFINITE);  switch(de.dwDebugEventCode)
      {
      ...
      default:
        {
          dwContinueStatus = DBG_CONTINUE;
          break;
        }
      }  ContinueDebugEvent(de.dwProcessId, de.dwThreadId, dwContinueStatus);
    }
      

  2.   

    先是DebugActiveProcess,
    BOOL DebugActiveProcess(
    DWORD dwProcessId // process to be debugged
    );
    参数就一个就是目标进程的ID,可以用我前面说的方法来得到。当开始调试一个进程后,就可以使用WaitForDebugEvent,
    BOOL WaitForDebugEvent(
    LPDEBUG_EVENT lpDebugEvent, // pointer to debug event structure
    DWORD dwMilliseconds // milliseconds to wait for event
    );
    来等待DEBUG事件了~
    DEBUG_EVENT的结构定义是这样的:
    *************************************************************
    typedef struct _DEBUG_EVENT { // de 
    DWORD dwDebugEventCode; 
    DWORD dwProcessId; 
    DWORD dwThreadId; 
    union { 
    EXCEPTION_DEBUG_INFO Exception; 
    CREATE_THREAD_DEBUG_INFO CreateThread; 
    CREATE_PROCESS_DEBUG_INFO CreateProcessInfo; 
    EXIT_THREAD_DEBUG_INFO ExitThread; 
    EXIT_PROCESS_DEBUG_INFO ExitProcess; 
    LOAD_DLL_DEBUG_INFO LoadDll; 
    UNLOAD_DLL_DEBUG_INFO UnloadDll; 
    OUTPUT_DEBUG_STRING_INFO DebugString; 
    RIP_INFO RipInfo; 
    } u; 
    } DEBUG_EVENT; typedef struct _EXCEPTION_RECORD { // exr 
    DWORD ExceptionCode; 
    DWORD ExceptionFlags; 
    struct _EXCEPTION_RECORD *ExceptionRecord; 
    PVOID ExceptionAddress; 
    DWORD NumberParameters; 
    DWORD ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS]; 
    } EXCEPTION_RECORD; typedef struct _EXCEPTION_DEBUG_INFO { // exdi 
    EXCEPTION_RECORD ExceptionRecord; 
    DWORD dwFirstChance; 
    } EXCEPTION_DEBUG_INFO; 
    *************************************************************
    在众多事件中,我们关心的只有EXCEPTION_DEBUG_EVENT,当dwDebugEventCode==EXCEPTION_DEBUG_EVENT时,U的结构展开是这样的!ExceptionCode表明了DEBUG事件产生的原因;可能的值中,需要我们关心的只有EXCEPTION_BREAKPOINT。当目标执行到指令INT3时就会触发上面的EXCEPTION_BREAKPOINT时间,所以,我们大可以在SEND/RECV等API入口处放一个INT3指令,
    当游戏调用该API时就触发了一个调试事件,进程被挂起,然后通知调试进程,这个时候,我们就可以从游戏程序的堆栈中读取参数,
    甚至修改~~最后,做了一些必要的出来后记得调用ContinueDebugEvent来继续游戏程序的执行~
      

  3.   

    //遍历进程
    #include <stdio.h>
    #include <windows.h>
    #include <tlhelp32.h>
    #include <tchar.h>int main()
    {
    HANDLE hSnapshot;
    PROCESSENTRY32 pe;
    BOOL bSucceed;
    TCHAR * szFileName = NULL;
    DWORD dwProcessID = 0;

    hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); bSucceed = Process32First(hSnapshot, &pe); while(bSucceed)
    {
    szFileName = _tcsrchr(pe.szExeFile, '\\');
    if(!szFileName)
    szFileName = pe.szExeFile;
    else
    szFileName ++;
    printf("\n%d\t%s",pe.th32ProcessID,szFileName);
    //判断创建这个进程的文件是不是explorer.exe
    if(!_tcsnicmp(szFileName, "Explorer.exe", 12))
    {
    //保存继承的ID
    dwProcessID = pe.th32ProcessID;
    break;
    }
    //转到下一个进程
    bSucceed = Process32Next(hSnapshot, &pe);
    }
    CloseHandle(hSnapshot);
    return 0;
    }
    里边可以得到所有的PID,根据自己的需求,钩挂PID,就可以作调试了。