Fix thread analyze wait access not showing information for some processes
@@ -110,29 +110,29 @@ VOID PhUiAnalyzeWaitThread(
{
NTSTATUS status;
HANDLE threadHandle;
-#ifdef _WIN64
HANDLE processHandle;
+#ifdef _WIN64
BOOLEAN isWow64;
#endif
CLIENT_ID clientId;
ANALYZE_WAIT_CONTEXT context;
-#ifdef _WIN64
- // Determine if the process is WOW64. If not, we use the passive method.
-
- if (!NT_SUCCESS(status = PhOpenProcess(&processHandle, PROCESS_QUERY_LIMITED_INFORMATION, ProcessId)))
+ if (!NT_SUCCESS(status = PhOpenProcess(&processHandle, PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, ProcessId)))
{
- PhShowStatus(hWnd, L"Unable to open the process", status, 0);
+ PhShowStatus(hWnd, L"Unable to open the process.", status, 0);
return;
}
+#ifdef _WIN64
+ // Determine if the process is WOW64. If not, we use the passive method.
+
if (!NT_SUCCESS(status = PhGetProcessIsWow64(processHandle, &isWow64)) || !isWow64)
{
PhpAnalyzeWaitPassive(hWnd, ProcessId, ThreadId);
- return;
- }
NtClose(processHandle);
+ return;
+ }
#endif
if (!NT_SUCCESS(status = PhOpenThread(
@@ -142,14 +142,14 @@ VOID PhUiAnalyzeWaitThread(
)))
{
PhShowStatus(hWnd, L"Unable to open the thread.", status, 0);
+ NtClose(processHandle);
return;
}
memset(&context, 0, sizeof(ANALYZE_WAIT_CONTEXT));
context.ProcessId = ProcessId;
context.ThreadId = ThreadId;
-
- context.ProcessHandle = SymbolProvider->ProcessHandle;
+ context.ProcessHandle = processHandle;
context.SymbolProvider = SymbolProvider;
PhInitializeStringBuilder(&context.StringBuilder, 100);
@@ -158,7 +158,7 @@ VOID PhUiAnalyzeWaitThread(
PhWalkThreadStack(
threadHandle,
- SymbolProvider->ProcessHandle,
+ processHandle,
&clientId,
SymbolProvider,
PH_WALK_I386_STACK,
@@ -166,12 +166,13 @@ VOID PhUiAnalyzeWaitThread(
&context
);
NtClose(threadHandle);
+ NtClose(processHandle);
PhpAnalyzeWaitFallbacks(&context);
if (context.Found)
{
- PhShowInformationDialog(hWnd, context.StringBuilder.String->Buffer, 0);
+ PhShowInformationDialog(hWnd, PhFinalStringBuilderString(&context.StringBuilder)->Buffer, 0);
}
else
{
