哦,大家都这样说。可我这里有能实现通过Process ID获得Thread handle的VC代码,<br>他是用未公开的的了一个结构。可我看不大懂,先贴出来,希望谁能翻成delphi并<br>分析一下。<br>关键代码:<br>#include "stdafx.h"<br>#include "InjectCode.h"<br><br>#ifdef _DEBUG<br>#define new DEBUG_NEW<br>#undef THIS_FILE<br>static char THIS_FILE[] = __FILE__;<br>#endif<br><br>typedef struct t_PDB<br>{<br> WORD Type;<br> WORD Refcount;<br> DWORD Unk0;<br> DWORD Unk1;<br> DWORD Unk2;<br> DWORD TermStatus;<br> DWORD Unk3;<br> DWORD DefaultHeap;<br> DWORD MemContext; <br> DWORD Flags;<br> DWORD pPsp;<br> WORD PSPSelector;<br> WORD MTEIndex;<br> WORD nThreads;<br> WORD nThreadsNotTerm;<br> WORD Unk5;<br> WORD nR0Threads;<br> DWORD HeapHandle;<br> WORD K16TDBSel;<br> WORD Unk6;<br> DWORD Unk7;<br> DWORD pEDB;<br> DWORD pHandleTable;<br> struct t_PDB *ParentPDB;<br> DWORD MODREFList;<br> DWORD ThreadList;<br> DWORD DebugeeCB;<br> DWORD LHFreeHead;<br> DWORD InitialR0ID;<br>}PDB, *PPDB;<br><br>typedef struct t_TCB<br>{<br> WORD Type;<br> WORD RefCount;<br> DWORD Unk1;<br> DWORD pvExcept;<br> DWORD TopOfStack;<br> DWORD BaseOfStack;<br> WORD K16TDB;<br> WORD StackSel16;<br> DWORD Unk2;<br> DWORD UserPointer;<br> DWORD pTIB;<br> WORD TIBflags;<br> WORD Win16MutxCnt;<br> DWORD DebugContext;<br> DWORD PtrToCurPri;<br> DWORD MsgQueue;<br> DWORD pTLSarray;<br> PPDB pParentPDB;<br> DWORD SelmanList;<br> DWORD Unk3;<br> DWORD Flags;<br> DWORD Status;<br> WORD TIBsel;<br> WORD EmulatorSel;<br> DWORD HandleCount;<br> DWORD WaitNodeList;<br> DWORD R0hThread;<br> DWORD ptdbx;<br>}TCB, *PTCB;<br><br>typedef DWORD (WINAPI*OTFUNC)(HANDLE*,DWORD,void*,void*);<br>typedef LPVOID (WINAPI *OBFUNC)(DWORD dwPTID);<br>LPVOID WINAPI GetTrueProcAddress(LPSTR lpMod, LPTSTR lpFunc);<br>HANDLE WINAPI OpenThreadNT(DWORD dwThreadID, BOOL bInherit);<br><br>LPVOID WINAPI XORProcessThreadID(DWORD dwPTID)<br>{<br> OBFUNC obfuscate;<br> DWORD dwMain,*lpdw,dw1;<br><br> dwMain = (DWORD)GetTrueProcAddress(_T("KERNEL32"),<br> _T("GetCurrentThreadId"));<br> lpdw = (LPDWORD)((DWORD)dwMain + 8);<br> dw1 = ((DWORD)dwMain + 12);<br><br> obfuscate = (OBFUNC)(dw1+*lpdw);<br><br> return(obfuscate(dwPTID));<br>}<br><br>//这个函数,传给他ThreadID,返回ThreadHandle<br>HANDLE WINAPI OpenThread2(DWORD dwThreadID, BOOL bInherit)<br>{<br> HANDLE hThread,hprc;<br> LPDWORD lp1;<br> DWORD dwProcessID,dwWhere,dwTable;<br> BOOL b1;<br> PTCB lpThreadObj;<br> PPDB ppdb;<br> OSVERSIONINFO osvi;<br><br> osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);<br> GetVersionEx(&osvi);<br><br> SetLastError(50);<br> if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)<br> return OpenThreadNT(dwThreadID, bInherit);<br><br> ppdb = (PPDB)XORProcessThreadID(GetCurrentProcessId());<br> lpThreadObj = (PTCB)XORProcessThreadID(dwThreadID);<br><br> /* check to make sure its valid */<br> if(IsBadReadPtr(lpThreadObj, sizeof(TCB))) return NULL;<br><br> /* object type */<br> if(*(LPBYTE)lpThreadObj != 7) return NULL;<br><br> dwProcessID =<br> (DWORD)XORProcessThreadID((DWORD)lpThreadObj->pParentPDB);<br><br> if(dwProcessID == GetCurrentProcessId())<br> hprc = GetCurrentProcess();<br> else<br> {<br> hprc = OpenProcess(PROCESS_ALL_ACCESS,<br> FALSE, dwProcessID);<br> if(!hprc) return NULL;<br> }<br><br> /*<br> * 4 is the lowest handle in the table.<br> * All processes have this handle.<br> */<br> b1 = DuplicateHandle(hprc,<br> (HANDLE)4,<br> GetCurrentProcess(),<br> &hThread,<br> THREAD_ALL_ACCESS,<br> bInherit, 0);<br><br> if(hprc != GetCurrentProcess())<br> CloseHandle(hprc);<br> if(!b1) return NULL;<br><br> dwWhere = ((DWORD)hThread) >> 2;<br> dwTable = ppdb->pHandleTable;<br> lp1 = (LPDWORD)(dwTable+(dwWhere*8)+8);<br><br> *lp1 = (DWORD)lpThreadObj;<br><br> return(hThread);<br>}<br><br>HANDLE WINAPI OpenThreadNT(DWORD dwThreadID, BOOL bInherit)<br>{<br> HANDLE hThread = NULL;<br> DWORD struct1[] = {0x18, 0, 0, 0, 0, 0};<br> DWORD struct2[] = {0,dwThreadID};<br> HMODULE hLib = LoadLibrary(_T("ntdll.dll"));<br><br> OTFUNC OpenThatNTThread =<br> (OTFUNC)GetProcAddress(hLib, _T("NtOpenThread"));<br><br> struct1[3] = bInherit;<br><br> OpenThatNTThread(&hThread, THREAD_ALL_ACCESS, struct1, struct2);<br><br> FreeLibrary(hLib);<br><br> return hThread;<br>}<br><br>LPVOID WINAPI GetTrueProcAddress(LPSTR lpMod, LPTSTR lpFunc)<br>{<br> LPVOID bla = GetProcAddress(GetModuleHandle(lpMod), lpFunc);<br><br> if(!bla) return NULL;<br><br> if(*(LPBYTE)bla == 0x68)<br> bla = (LPVOID)*(LPDWORD)((DWORD)bla + 1);<br><br> return bla;<br>}<br>