我想使用进程 ID 和线程 ID 检索进程的线程起始地址。
这是我的代码:
DWORD WINAPI GetThreadStartAddress(DWORD tid, DWORD pid)
{
NTSTATUS ntStatus;
HANDLE hDupHandle;
DWORD dwStartAddress;
HANDLE hProcess;
HANDLE hTread;
pNtQIT NtQueryInformationThread;
hTread = OpenThread(THREAD_ALL_ACCESS, FALSE, tid);
NtQueryInformationThread = (pNtQIT)GetProcAddress(GetModuleHandle(L"ntdll.dll"), "NtQueryInformationThread");
if(NtQueryInformationThread == NULL)
return 0;
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
SuspendThread(hTread);
if(!DuplicateHandle(hProcess, hTread, hProcess, &hDupHandle, THREAD_QUERY_INFORMATION, FALSE, 0)){
SetLastError(ERROR_ACCESS_DENIED);
return 0;
}
ntStatus = NtQueryInformationThread(hDupHandle, ThreadQuerySetWin32StartAddress, &dwStartAddress, sizeof(DWORD), NULL);
ResumeThread(hTread );
CloseHandle(hTread);
CloseHandle(hProcess);
CloseHandle(hDupHandle);
if (ntStatus != 0)
return 0;
return dwStartAddress;
}
但 ntStatus 始终不为 0。为什么?