fc73ef0dc5
Replace redundant PhOpenProcess calls in the process properties pages (general, job, threads, token) and run-as dialog with the process item's existing QueryHandle/IsHandleValid, referencing the item where needed. This avoids extra open/close cycles and failure paths. Also tidy the general page: avoid leaking/auto-releasing the Win32 file name by using PhMoveReference/PhClearReference, disable the secondary open/inspect buttons (IDC_OPENFILENAME2/IDC_INSPECT2) alongside the primary ones, and always focus the permissions button initially.
128 lines
3.7 KiB
C
128 lines
3.7 KiB
C
/*
|
|
* Copyright (c) 2022 Winsider Seminars & Solutions, Inc. All rights reserved.
|
|
*
|
|
* This file is part of System Informer.
|
|
*
|
|
* Authors:
|
|
*
|
|
* wj32 2009-2016
|
|
* dmex 2018-2022
|
|
*
|
|
*/
|
|
|
|
#include <phapp.h>
|
|
#include <procprp.h>
|
|
#include <procprv.h>
|
|
|
|
_Function_class_(PH_OPEN_OBJECT)
|
|
NTSTATUS NTAPI PhpOpenProcessTokenForPage(
|
|
_Out_ PHANDLE Handle,
|
|
_In_ ACCESS_MASK DesiredAccess,
|
|
_In_ PVOID Context
|
|
)
|
|
{
|
|
NTSTATUS status;
|
|
PPH_PROCESS_ITEM processItem;
|
|
HANDLE processHandle;
|
|
|
|
if (!PH_IS_REAL_PROCESS_ID(Context))
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
if (!(processItem = PhReferenceProcessItem((HANDLE)Context)))
|
|
return STATUS_INVALID_HANDLE;
|
|
|
|
if (!(processHandle = processItem->QueryHandle))
|
|
{
|
|
PhDereferenceObject(processItem);
|
|
return STATUS_INVALID_HANDLE;
|
|
}
|
|
|
|
if (!NT_SUCCESS(status = PhOpenProcessToken(
|
|
processHandle,
|
|
DesiredAccess | TOKEN_READ | TOKEN_ADJUST_DEFAULT | READ_CONTROL,
|
|
Handle
|
|
)))
|
|
{
|
|
if (!NT_SUCCESS(status = PhOpenProcessToken(
|
|
processHandle,
|
|
DesiredAccess | TOKEN_READ | TOKEN_ADJUST_DEFAULT,
|
|
Handle
|
|
)))
|
|
{
|
|
status = PhOpenProcessToken(
|
|
processHandle,
|
|
DesiredAccess,
|
|
Handle
|
|
);
|
|
}
|
|
}
|
|
|
|
PhDereferenceObject(processItem);
|
|
|
|
return status;
|
|
}
|
|
|
|
_Function_class_(PH_CLOSE_OBJECT)
|
|
NTSTATUS PhpCloseProcessTokenForPage(
|
|
_In_opt_ HANDLE Handle,
|
|
_In_opt_ BOOLEAN Release,
|
|
_In_opt_ PVOID Context
|
|
)
|
|
{
|
|
if (Handle) NtClose(Handle);
|
|
return STATUS_SUCCESS;
|
|
}
|
|
|
|
static VOID PhpInitializeProcessTokenPageLayout(
|
|
_In_ HWND WindowHandle
|
|
)
|
|
{
|
|
PPH_LAYOUT_ITEM dialogItem;
|
|
|
|
PhSetWindowStyle(WindowHandle, WS_CLIPCHILDREN | WS_CLIPSIBLINGS, WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
|
|
|
|
// This is a big violation of abstraction...
|
|
|
|
dialogItem = PhAddPropPageLayoutItem(WindowHandle, WindowHandle, PH_PROP_PAGE_TAB_CONTROL_PARENT, PH_ANCHOR_ALL);
|
|
PhAddPropPageLayoutItem(WindowHandle, GetDlgItem(WindowHandle, IDC_USER), dialogItem, PH_ANCHOR_LEFT | PH_ANCHOR_TOP | PH_ANCHOR_RIGHT);
|
|
PhAddPropPageLayoutItem(WindowHandle, GetDlgItem(WindowHandle, IDC_USERSID), dialogItem, PH_ANCHOR_LEFT | PH_ANCHOR_TOP | PH_ANCHOR_RIGHT);
|
|
PhAddPropPageLayoutItem(WindowHandle, GetDlgItem(WindowHandle, IDC_VIRTUALIZED), dialogItem, PH_ANCHOR_LEFT | PH_ANCHOR_TOP | PH_ANCHOR_RIGHT);
|
|
PhAddPropPageLayoutItem(WindowHandle, GetDlgItem(WindowHandle, IDC_GROUPS), dialogItem, PH_ANCHOR_ALL);
|
|
PhAddPropPageLayoutItem(WindowHandle, GetDlgItem(WindowHandle, IDC_DEFAULTPERM), dialogItem, PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);
|
|
PhAddPropPageLayoutItem(WindowHandle, GetDlgItem(WindowHandle, IDC_PERMISSIONS), dialogItem, PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);
|
|
PhAddPropPageLayoutItem(WindowHandle, GetDlgItem(WindowHandle, IDC_INTEGRITY), dialogItem, PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);
|
|
PhAddPropPageLayoutItem(WindowHandle, GetDlgItem(WindowHandle, IDC_ADVANCED), dialogItem, PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);
|
|
|
|
PhDoPropPageLayout(WindowHandle);
|
|
}
|
|
|
|
INT_PTR CALLBACK PhpProcessTokenHookProc(
|
|
_In_ HWND hwndDlg,
|
|
_In_ UINT uMsg,
|
|
_In_ WPARAM wParam,
|
|
_In_ LPARAM lParam
|
|
)
|
|
{
|
|
switch (uMsg)
|
|
{
|
|
case WM_DESTROY:
|
|
{
|
|
if (PhGetWindowContext(hwndDlg, 0xD))
|
|
PhRemoveWindowContext(hwndDlg, 0xD);
|
|
}
|
|
break;
|
|
case WM_SHOWWINDOW:
|
|
{
|
|
if (!PhGetWindowContext(hwndDlg, 0xD)) // LayoutInitialized
|
|
{
|
|
PhpInitializeProcessTokenPageLayout(hwndDlg);
|
|
|
|
PhSetWindowContext(hwndDlg, 0xD, UlongToPtr(TRUE));
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
return FALSE;
|
|
}
|