Get the thread ID and entry address of a process

Source: Internet
Author: User

1#include <windows.h>2#include <tlhelp32.h>3#include"iostream"4 using namespacestd;5 voidPass_tpthread (WCHAR processname[]);6 typedef LONG NTSTATUS;7typedef NTSTATUS (WINAPI *ntqueryinformationthread) (8 HANDLE Threadhandle,9 ULONG Threadinformationclass,Ten PVOID threadinformation, One ULONG Threadinformationlength, A Pulong returnlength); -typedefenum_threadinfoclass - { the Threadbasicinformation, - Threadtimes, - ThreadPriority, - threadbasepriority, + Threadaffinitymask, - Threadimpersonationtoken, + Threaddescriptortableentry, A Threadenablealignmentfaultfixup, at threadeventpair_reusable, - threadquerysetwin32startaddress, - Threadzerotlscell, - Threadperformancecount, - Threadamilastthread, - Threadidealprocessor, in Threadpriorityboost, -Threadsettlsarrayaddress,//Obsolete to threadisiopending, + Threadhidefromdebugger, - Threadbreakontermination, the Threadswitchlegacystate, * threadisterminated, $ Threadlastsystemcall,Panax Notoginseng threadiopriority, - Threadcycletime, the threadpagepriority, + threadactualbasepriority, A Threadtebinformation, theThreadcswitchmon,//Obsolete + THREADCSWITCHPMU, - Threadwow64context, $ Threadgroupinformation, $Threadumsinformation,//UMS - threadcounterprofiling, - Threadidealprocessorex, the Maxthreadinfoclass - } threadinfoclass;Wuyi DWORD getprocess (WCHAR processname[]) the { -DWORD ProcessID =NULL; WuGetWindowThreadProcessId (Findwindoww (NULL, ProcessName), &ProcessID); -     returnProcessID; About } $ voidPass_tpthread (WCHAR processname[]) - { -DWORD dwstaaddr =NULL; -DWORD dwreturnlength =NULL; AHANDLE Threadhwnd =NULL; + THREADENTRY32 te32; theTe32.dwsize =sizeof(TE32); -Hmodule Hntdll = Loadlibraryw (L"Ntdll.dll"); $Ntqueryinformationthread Ntqueryinformationthread =NULL; theNtqueryinformationthread =(Ntqueryinformationthread) theGetProcAddress (Hntdll,"Ntqueryinformationthread"); the  theHANDLE Snapshot =CreateToolhelp32Snapshot (Th32cs_snapthread, NULL); -     if(Thread32first (Snapshot, &te32)) in     { the          Do the         { AboutThreadhwnd =Openthread (thread_all_access, FALSE, te32.th32threadid); the Ntqueryinformationthread (Threadhwnd, threadquerysetwin32startaddress, the&AMP;DWSTAADDR,sizeof(DWSTAADDR), &dwreturnlength); theDWORD PID =getprocess (ProcessName); +              -             if(GetProcess (ProcessName) = =Getprocessidofthread (Threadhwnd)) the             {BayiCOUT.SETF (Ios::showbase |ios::uppercase); thecout<<dec<<"game thread ID:"<<Te32.th32threadid; thecout << Hex <<"Thread entry Address:"<< dwstaaddr <<Endl; -             } -              the} while(Thread32next (Snapshot, &te32)); the     } the } the  - intMain () the { thePass_tpthread (L"QQ"); thecout <<"Main thread id="<< GetWindowThreadProcessId (Findwindoww (NULL, L"QQ"), NULL) <<Endl;94 GetChar (); the}

Get the thread ID and entry address of a process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.