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.
107 lines
3.0 KiB
C
107 lines
3.0 KiB
C
/*
|
|
* Copyright (c) 2022 Winsider Seminars & Solutions, Inc. All rights reserved.
|
|
*
|
|
* This file is part of System Informer.
|
|
*
|
|
* Authors:
|
|
*
|
|
* wj32 2009-2016
|
|
*
|
|
*/
|
|
|
|
#include <phapp.h>
|
|
#include <procprp.h>
|
|
#include <procprv.h>
|
|
#include <kphuser.h>
|
|
|
|
_Function_class_(PH_OPEN_OBJECT)
|
|
NTSTATUS NTAPI PhpOpenProcessJobForPage(
|
|
_Out_ PHANDLE Handle,
|
|
_In_ ACCESS_MASK DesiredAccess,
|
|
_In_ PVOID Context
|
|
)
|
|
{
|
|
NTSTATUS status;
|
|
PPH_PROCESS_ITEM processItem;
|
|
HANDLE jobHandle = NULL;
|
|
|
|
if (!(processItem = PhReferenceProcessItem((HANDLE)Context)))
|
|
return STATUS_INVALID_HANDLE;
|
|
|
|
if (processItem->QueryHandle)
|
|
status = KphOpenProcessJob(processItem->QueryHandle, DesiredAccess, &jobHandle);
|
|
else
|
|
status = STATUS_INVALID_HANDLE;
|
|
|
|
PhDereferenceObject(processItem);
|
|
|
|
if (NT_SUCCESS(status) && status != STATUS_PROCESS_NOT_IN_JOB && jobHandle)
|
|
{
|
|
*Handle = jobHandle;
|
|
}
|
|
else if (NT_SUCCESS(status))
|
|
{
|
|
status = STATUS_UNSUCCESSFUL;
|
|
}
|
|
|
|
return status;
|
|
}
|
|
|
|
_Function_class_(PH_CLOSE_OBJECT)
|
|
NTSTATUS NTAPI PhpCloseProcessJobForPage(
|
|
_In_ HANDLE Handle,
|
|
_In_ BOOLEAN Release,
|
|
_In_opt_ PVOID Context
|
|
)
|
|
{
|
|
return NtClose(Handle);
|
|
}
|
|
|
|
INT_PTR CALLBACK PhpProcessJobHookProc(
|
|
_In_ HWND hwndDlg,
|
|
_In_ UINT uMsg,
|
|
_In_ WPARAM wParam,
|
|
_In_ LPARAM lParam
|
|
)
|
|
{
|
|
switch (uMsg)
|
|
{
|
|
case WM_DESTROY:
|
|
{
|
|
PhRemoveWindowContext(hwndDlg, PH_WINDOW_CONTEXT_DEFAULT);
|
|
}
|
|
break;
|
|
case WM_SHOWWINDOW:
|
|
{
|
|
if (!PhGetWindowContext(hwndDlg, PH_WINDOW_CONTEXT_DEFAULT)) // LayoutInitialized
|
|
{
|
|
PPH_LAYOUT_ITEM dialogItem;
|
|
|
|
// This is a big violation of abstraction...
|
|
|
|
dialogItem = PhAddPropPageLayoutItem(hwndDlg, hwndDlg,
|
|
PH_PROP_PAGE_TAB_CONTROL_PARENT, PH_ANCHOR_ALL);
|
|
PhAddPropPageLayoutItem(hwndDlg, GetDlgItem(hwndDlg, IDC_NAME),
|
|
dialogItem, PH_ANCHOR_LEFT | PH_ANCHOR_TOP | PH_ANCHOR_RIGHT);
|
|
PhAddPropPageLayoutItem(hwndDlg, GetDlgItem(hwndDlg, IDC_TERMINATE),
|
|
dialogItem, PH_ANCHOR_TOP | PH_ANCHOR_RIGHT);
|
|
PhAddPropPageLayoutItem(hwndDlg, GetDlgItem(hwndDlg, IDC_PROCESSES),
|
|
dialogItem, PH_ANCHOR_LEFT | PH_ANCHOR_TOP | PH_ANCHOR_RIGHT);
|
|
PhAddPropPageLayoutItem(hwndDlg, GetDlgItem(hwndDlg, IDC_ADD),
|
|
dialogItem, PH_ANCHOR_TOP | PH_ANCHOR_RIGHT);
|
|
PhAddPropPageLayoutItem(hwndDlg, GetDlgItem(hwndDlg, IDC_LIMITS),
|
|
dialogItem, PH_ANCHOR_ALL);
|
|
PhAddPropPageLayoutItem(hwndDlg, GetDlgItem(hwndDlg, IDC_ADVANCED),
|
|
dialogItem, PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);
|
|
|
|
PhDoPropPageLayout(hwndDlg);
|
|
|
|
PhSetWindowContext(hwndDlg, PH_WINDOW_CONTEXT_DEFAULT, UlongToPtr(TRUE));
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
return FALSE;
|
|
}
|