91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何根據線程號獲取模塊信息

發布時間:2020-06-14 10:51:16 來源:網絡 閱讀:1395 作者:gongwan33 欄目:編程語言

在得到線程之后,便可以通過openThread得到HANDLE,之后通過ZwQueryInformationThread獲取線程信息。


Part1 準備:

#include <psapi.h>

#include <locale.h>

#include <iostream>

#pragma comment(lib,"psapi.lib")  


typedef enum _THREADINFOCLASS {

    ThreadBasicInformation,

    ThreadTimes,

    ThreadPriority,

    ThreadBasePriority,

    ThreadAffinityMask,

    ThreadImpersonationToken,

    ThreadDescriptorTableEntry,

    ThreadEnableAlignmentFaultFixup,

    ThreadEventPair_Reusable,

    ThreadQuerySetWin32StartAddress,

    ThreadZeroTlsCell,

    ThreadPerformanceCount,

    ThreadAmILastThread,

    ThreadIdealProcessor,

    ThreadPriorityBoost,

    ThreadSetTlsArrayAddress,

    ThreadIsIoPending,

    ThreadHideFromDebugger,

    ThreadBreakOnTermination,

    MaxThreadInfoClass

} THREADINFOCLASS;

typedef struct _CLIENT_ID {

    HANDLE UniqueProcess;

    HANDLE UniqueThread;

} CLIENT_ID;

typedef CLIENT_ID *PCLIENT_ID;

typedef struct _THREAD_BASIC_INFORMATION { // Information Class 0

    LONG     ExitStatus;

    PVOID    TebBaseAddress;

    CLIENT_ID ClientId;

    LONG AffinityMask;

    LONG Priority;

    LONG BasePriority;

} THREAD_BASIC_INFORMATION, *PTHREAD_BASIC_INFORMATION;

extern "C" LONG (__stdcall *ZwQueryInformationThread) (

    IN HANDLE ThreadHandle,

    IN THREADINFOCLASS ThreadInformationClass,

    OUT PVOID ThreadInformation,

    IN ULONG ThreadInformationLength,

    OUT PULONG ReturnLength OPTIONAL

    ) = NULL;


主函數中需要做的準備工作:

    setlocale (LC_ALL, ".ACP");

    HINSTANCE hNTDLL = ::GetModuleHandle (TEXT ("ntdll"));

    (FARPROC&)ZwQueryInformationThread  = ::GetProcAddress (hNTDLL,   "ZwQueryInformationThread");



Part 2 獲取相關信息

    THREAD_BASIC_INFORMATION    tbi;

    PVOID                       startaddr;

    LONG                        status;

    HANDLE                      thread, process;

        

    thread = ::OpenThread (THREAD_ALL_ACCESS, FALSE, dwThreadId);

    if (thread == NULL)

{

printf("cannot open thread handle\n");

        return FALSE;

}

status = ZwQueryInformationThread(thread,ThreadQuerySetWin32StartAddress, &startaddr, sizeof (startaddr), NULL);

    if (status < 0)

    {

        CloseHandle (thread);

printf("cannot get status1\n");

        return FALSE;

    };

    printf("線程 %08x 的起始地址為 %p\n", dwThreadId, startaddr);

    status = ZwQueryInformationThread (thread, 

            ThreadBasicInformation, 

            &tbi, 

            sizeof (tbi), 

            NULL);

    if (status < 0)

{

        CloseHandle (thread);

printf("cannot get status2\n");

        return FALSE;

};

printf("線程 %08x 所在進程ID為 %08x\n", dwThreadId, (DWORD)tbi.ClientId.UniqueProcess);

process = ::OpenProcess (PROCESS_ALL_ACCESS, 

FALSE, 

(DWORD)tbi.ClientId.UniqueProcess);

if (process == NULL)

{

DWORD error = ::GetLastError ();

CloseHandle (thread);

SetLastError (error);

return FALSE;

};

TCHAR modname [0x100];

::GetModuleFileNameEx (process, NULL, modname, 0x100);

printf("線程 %08x 所在進程映象為 %s\n", dwThreadId, modname);

GetMappedFileName(process, 

startaddr, 

modname, 

0x100);

        std::string stName(pName);

std::string stModName(modname);

if(stModName.find(stName) != std::string::npos)

{

printf("線程 %08x 可執行代碼所在模塊為 %s\n", dwThreadId, modname);

ret = TRUE;

}

CloseHandle (process);

CloseHandle (thread);




向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

巫山县| 孟连| 嵩明县| 长岭县| 宿州市| 海伦市| 天气| 惠水县| 防城港市| 诸暨市| 呼和浩特市| 利津县| 邢台市| 连江县| 行唐县| 牡丹江市| 资兴市| 米脂县| 普洱| 肥乡县| 安平县| 乐清市| 七台河市| 微山县| 丹阳市| 东至县| 依安县| 全椒县| 梨树县| 女性| 勐海县| 广水市| 金溪县| SHOW| 海丰县| 镇赉县| 盐池县| 广东省| 乌审旗| 封开县| 台东市|