#include <windows.h>
#include <tlhelp32.h>
#include "iostream"
using namespace std;
void PASS_TPTHREAD(WCHAR ProcessName[]);
typedef LONG NTSTATUS;
typedef NTSTATUS(WINAPI *NTQUERYINFORMATIONTHREAD)(
HANDLE ThreadHandle,
ULONG ThreadInformationClass,
PVOID ThreadInformation,
ULONG ThreadInformationLength,
PULONG ReturnLength);
typedef enum _THREADINFOCLASS
{
ThreadBasicInformation,
ThreadTimes,
ThreadPriority,
ThreadBasePriority,
ThreadAffinityMask,
ThreadImpersonationToken,
ThreadDescriptorTableEntry,
ThreadEnableAlignmentFaultFixup,
ThreadEventPair_Reusable,
ThreadQuerySetWin32StartAddress,
ThreadZeroTlsCell,
ThreadPerformanceCount,
ThreadAmILastThread,
ThreadIdealProcessor,
ThreadPriorityBoost,
ThreadSetTlsArrayAddress, // Obsolete
ThreadIsIoPending,
ThreadHideFromDebugger,
ThreadBreakOnTermination,
ThreadSwitchLegacyState,
ThreadIsTerminated,
ThreadLastSystemCall,
ThreadIoPriority,
ThreadCycleTime,
ThreadPagePriority,
ThreadActualBasePriority,
ThreadTebInformation,
ThreadCSwitchMon, // Obsolete
ThreadCSwitchPmu,
ThreadWow64Context,
ThreadGroupInformation,
ThreadUmsInformation, // UMS
ThreadCounterProfiling,
ThreadIdealProcessorEx,
MaxThreadInfoClass
} THREADINFOCLASS;
DWORD GetProcess(WCHAR ProcessName[])
{
DWORD ProcessID = NULL;
GetWindowThreadProcessId(FindWindowW(NULL, ProcessName), &ProcessID);
return ProcessID;
}
void PASS_TPTHREAD(WCHAR ProcessName[])
{
DWORD dwStaAddr = NULL;
DWORD dwReturnLength = NULL;
HANDLE ThreadHWND = NULL;
THREADENTRY32 te32;
te32.dwSize = sizeof(te32);
HMODULE hNtdll = LoadLibraryW(L"ntdll.dll");
NTQUERYINFORMATIONTHREAD NtQueryInformationThread = NULL;
NtQueryInformationThread = (NTQUERYINFORMATIONTHREAD)
GetProcAddress(hNtdll, "NtQueryInformationThread");
HANDLE Snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, NULL);
if (Thread32First(Snapshot, &te32))
{
do
{
ThreadHWND = OpenThread(THREAD_ALL_ACCESS, FALSE, te32.th32ThreadID);
NtQueryInformationThread(ThreadHWND, ThreadQuerySetWin32StartAddress,
&dwStaAddr, sizeof(dwStaAddr), &dwReturnLength);
DWORD PID = GetProcess(ProcessName);
if (GetProcess(ProcessName) == GetProcessIdOfThread(ThreadHWND))
{
cout.setf(ios::showbase | ios::uppercase);
cout<<dec<<"游戏线程ID:" << te32.th32ThreadID;
cout << hex << " 线程入口地址:" << dwStaAddr << endl;
}
} while (Thread32Next(Snapshot, &te32));
}
}
int main()
{
PASS_TPTHREAD(L"QQ");
cout << "主线程ID=" << GetWindowThreadProcessId(FindWindowW(NULL, L"QQ"), NULL) << endl;
getchar();
}