show PID or TID in handles view
This commit is contained in:
parent
94035a530a
commit
f8c67ef2ab
|
@ -58,7 +58,7 @@ static DWORD WINAPI getNameThread(LPVOID lpParam)
|
|||
bool HandlesGetName(HANDLE hProcess, HANDLE remoteHandle, String & name, String & typeName)
|
||||
{
|
||||
HANDLE hLocalHandle;
|
||||
if(DuplicateHandle(hProcess, remoteHandle, GetCurrentProcess(), &hLocalHandle, 0, FALSE, 0))
|
||||
if(DuplicateHandle(hProcess, remoteHandle, GetCurrentProcess(), &hLocalHandle, 0, FALSE, DUPLICATE_SAME_ACCESS)) //Needs privileges for PID/TID retrival
|
||||
{
|
||||
ULONG ReturnSize = 0;
|
||||
if(NtQueryObject(hLocalHandle, ObjectTypeInformation, nullptr, 0, &ReturnSize) == STATUS_INFO_LENGTH_MISMATCH)
|
||||
|
@ -80,7 +80,44 @@ bool HandlesGetName(HANDLE hProcess, HANDLE remoteHandle, String & name, String
|
|||
}
|
||||
};
|
||||
|
||||
auto hThread = CreateThread(nullptr, 0, getNameThread, &getName, 0, nullptr);
|
||||
name.clear();
|
||||
if(strcmp(typeName.c_str(), "Process") == 0)
|
||||
{
|
||||
DWORD PID = GetProcessId(hLocalHandle); //Windows XP SP1
|
||||
if(PID > 0)
|
||||
name = StringUtils::sprintf("PID = %X", PID);
|
||||
}
|
||||
else if(strcmp(typeName.c_str(), "Thread") == 0)
|
||||
{
|
||||
DWORD TID = 0;
|
||||
DWORD PID = 0;
|
||||
DWORD(__stdcall * pGetThreadId)(HANDLE);
|
||||
DWORD(__stdcall * pGetProcessIdOfThread)(HANDLE);
|
||||
pGetThreadId = (DWORD(__stdcall*)(HANDLE))GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "GetThreadId");
|
||||
pGetProcessIdOfThread = (DWORD(__stdcall*)(HANDLE))GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "GetProcessIdOfThread");
|
||||
if(pGetThreadId != NULL && pGetProcessIdOfThread != NULL)
|
||||
{
|
||||
TID = pGetThreadId(hLocalHandle); //Vista or Server 2003 only
|
||||
PID = pGetProcessIdOfThread(hLocalHandle); //Vista or Server 2003 only
|
||||
}
|
||||
else //Windows XP
|
||||
{
|
||||
THREAD_BASIC_INFORMATION threadInfo;
|
||||
ULONG threadInfoSize = 0;
|
||||
NTSTATUS isok = NtQueryInformationThread(hLocalHandle, ThreadBasicInformation, &threadInfo, sizeof(threadInfo), &threadInfoSize);
|
||||
if(NT_SUCCESS(isok))
|
||||
{
|
||||
TID = (DWORD)threadInfo.ClientId.UniqueThread;
|
||||
PID = (DWORD)threadInfo.ClientId.UniqueProcess;
|
||||
}
|
||||
}
|
||||
if(TID > 0 && PID > 0)
|
||||
name = StringUtils::sprintf("TID = %X, PID = %X", TID, PID);
|
||||
}
|
||||
if(name.empty())
|
||||
{
|
||||
HANDLE hThread;
|
||||
hThread = CreateThread(nullptr, 0, getNameThread, &getName, 0, nullptr);
|
||||
auto result = WaitForSingleObject(hThread, 200);
|
||||
if(result != WAIT_OBJECT_0)
|
||||
{
|
||||
|
@ -89,7 +126,7 @@ bool HandlesGetName(HANDLE hProcess, HANDLE remoteHandle, String & name, String
|
|||
}
|
||||
else
|
||||
CloseHandle(hThread);
|
||||
|
||||
}
|
||||
CloseHandle(hLocalHandle);
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue