我是用CreateToolhelp32Snapshot枚举到所有进程
然后指定一个进程,想得到该进程的主线程ID
结构里貌似没这个主线程ID,请问怎么得到呢?

解决方案 »

  1.   

    用EnumWindow根据进程ID获得进程的窗口句柄,再用GetWindowThreadProcessId获得线程ID
      

  2.   

    或者你用两次CreateToolhelp32Snapshot,第一次得到进程ID,第二次就用TH32CS_SNAPTHREAD
      

  3.   

    我是想Hook指定进程的conncet函数
    不知道谁有这样的例子代码,我现在只知道进程的ID或者进程名
      

  4.   

    或者你用两次CreateToolhelp32Snapshot,第一次得到进程ID,第二次就用TH32CS_SNAPTHREAD,根据这个进程ID得到线程ID
    typedef struct tagTHREADENTRY32 {  DWORD dwSize;  DWORD cntUsage;  DWORD th32ThreadID;  DWORD th32OwnerProcessID;  LONG tpBasePri;  LONG tpDeltaPri;  DWORD dwFlags;
    } THREADENTRY32, *PTHREADENTRY32;
    dwSize 
    Size of the structure, in bytes. Before calling the Thread32First function, set this member to sizeof(THREADENTRY32). If you do not initialize dwSize, Thread32First fails. 
    cntUsage 
    This member is no longer used and is always set to zero. 
    th32ThreadID 
    Thread identifier, compatible with the thread identifier returned by the CreateProcess function. 
    th32OwnerProcessID 
    Identifier of the process that created the thread. 
    tpBasePri 
    Initial priority level assigned to a thread. This member can be one of the following values (defined in Winbase.h and Winnt.h). 
      

  5.   

    那完全不需要知道主线程ID.
    直接用最简单的IAT HOOK
    注射到目标线程,获取目标线程基址,修改导入表的connect函数。即可,
      

  6.   

    另一种方法是,弄个全局钩子,在里面用GetModuleFileName得到进程名,符合就操作,不符合就直接往下执行。。