Skip to content

Commit

Permalink
Merge branch 'master' into master-dm
Browse files Browse the repository at this point in the history
  • Loading branch information
DartVanya committed Dec 9, 2024
2 parents ebac1fa + a6aea48 commit b5a1ec7
Show file tree
Hide file tree
Showing 66 changed files with 4,980 additions and 3,197 deletions.
871 changes: 435 additions & 436 deletions SystemInformer/SystemInformer.def

Large diffs are not rendered by default.

871 changes: 435 additions & 436 deletions SystemInformer/SystemInformer.def.h

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions SystemInformer/SystemInformer.rc
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,7 @@ CAPTION "Mappings"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CONTROL "",IDC_LIST,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_SHAREIMAGELISTS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,7,7,286,246
LTEXT "Static",IDC_TEXT,7,7,286,246,NOT WS_VISIBLE
END

IDD_MODIFIEDPAGES DIALOGEX 0, 0, 351, 307
Expand Down
130 changes: 79 additions & 51 deletions SystemInformer/actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -2306,6 +2306,29 @@ BOOLEAN PhUiRestartProcess(
if (Process->ProcessId == NtCurrentProcessId())
return FALSE;

// Special handling for the current shell process. (dmex)
{
CLIENT_ID shellClientId;

if (NT_SUCCESS(PhGetWindowClientId(PhGetShellWindow(), &shellClientId)))
{
if (Process->ProcessId == shellClientId.UniqueProcess)
{
status = PhOpenProcess(
&processHandle,
PROCESS_TERMINATE,
Process->ProcessId
);

if (NT_SUCCESS(status))
{
PhTerminateProcess(processHandle, STATUS_SUCCESS);
NtClose(processHandle);
}
}
}
}

fileNameWin32 = Process->FileName ? PhGetFileName(Process->FileName) : NULL;

if (PhIsNullOrEmptyString(fileNameWin32) || !PhDoesFileExistWin32(PhGetString(fileNameWin32)))
Expand Down Expand Up @@ -2939,7 +2962,7 @@ BOOLEAN PhUiSetEcoModeProcess(
BOOLEAN PhUiSetExecutionRequiredProcess(
_In_ HWND WindowHandle,
_In_ PPH_PROCESS_ITEM Process
)
)
{
NTSTATUS status;

Expand Down Expand Up @@ -3067,7 +3090,7 @@ BOOLEAN PhUiLoadDllProcess(
LARGE_INTEGER timeout;

timeout.QuadPart = -(LONGLONG)UInt32x32To64(5, PH_TIMEOUT_SEC);
status = PhLoadDllProcess(processHandle, &fileName->sr, &timeout);
status = PhLoadDllProcess(processHandle, &fileName->sr, FALSE, &timeout);

NtClose(processHandle);
}
Expand Down Expand Up @@ -3346,7 +3369,6 @@ typedef struct _PH_UI_SERVICE_PROGRESS_DIALOG
HWND WindowHandle;
HWND ParentWindowHandle;

PCWSTR Object;
PCWSTR Verb;
PCWSTR Message;

Expand Down Expand Up @@ -3385,6 +3407,30 @@ VOID PhShowServiceProgressDialogStatusPage(
);
#pragma endregion

VOID PhpShowServiceProgressInitializeText(
_In_ PPH_UI_SERVICE_PROGRESS_DIALOG Context,
_Out_ PPH_STRING* Verb,
_Out_ PPH_STRING* VerbCaps,
_Out_ PPH_STRING* Action,
_Out_ PCWSTR* Object
)
{
if (Context->ServiceItemList->Count == 1)
*Object = L"the selected service";
else
*Object = L"the selected services";

// Make sure the verb is all lowercase.
*Verb = PhaLowerString(PhaCreateString(Context->Verb));

// "terminate" -> "Terminate"
*VerbCaps = PhaDuplicateString(*Verb);
if (!PhIsNullOrEmptyString(*VerbCaps)) (*VerbCaps)->Buffer[0] = PhUpcaseUnicodeChar((*VerbCaps)->Buffer[0]);

// "terminate", "the process" -> "terminate the process"
*Action = PhaConcatStrings(3, (*Verb)->Buffer, L" ", *Object);
}

HRESULT CALLBACK PhpUiServiceErrorDialogCallbackProc(
_In_ HWND WindowHandle,
_In_ UINT WindowMessage,
Expand Down Expand Up @@ -3677,6 +3723,12 @@ VOID PhShowServiceProgressDialogStatusPage(
)
{
TASKDIALOGCONFIG config;
PPH_STRING verb;
PPH_STRING verbCaps;
PPH_STRING action;
PCWSTR object;

PhpShowServiceProgressInitializeText(Context, &verb, &verbCaps, &action, &object);

memset(&config, 0, sizeof(TASKDIALOGCONFIG));
config.cbSize = sizeof(TASKDIALOGCONFIG);
Expand All @@ -3686,7 +3738,7 @@ VOID PhShowServiceProgressDialogStatusPage(
config.dwCommonButtons = TDCBF_CANCEL_BUTTON;
config.lpCallbackData = (LONG_PTR)Context;
config.pfCallback = PhpUiServiceProgressDialogCallbackProc;
config.pszMainInstruction = PhaConcatStrings(5, L"Attempting to ", Context->Verb, L" ", Context->Object, L"...")->Buffer;
config.pszMainInstruction = PhaConcatStrings(5, L"Attempting to ", verb, L" ", object, L"...")->Buffer;
config.cxWidth = 200;

PhTaskDialogNavigatePage(Context->WindowHandle, &config);
Expand Down Expand Up @@ -3720,29 +3772,6 @@ HRESULT CALLBACK PhpUiServiceConfirmDialogCallbackProc(
return S_OK;
}

VOID PhpShowServiceProgressInitializeText(
_In_ PPH_UI_SERVICE_PROGRESS_DIALOG Context,
_Out_ PPH_STRING* Verb,
_Out_ PPH_STRING* VerbCaps,
_Out_ PPH_STRING* Action
)
{
if (Context->ServiceItemList->Count == 1)
Context->Object = L"the selected service";
else
Context->Object = L"the selected services";

// Make sure the verb is all lowercase.
*Verb = PhaLowerString(PhaCreateString(Context->Verb));

// "terminate" -> "Terminate"
*VerbCaps = PhaDuplicateString(*Verb);
if (!PhIsNullOrEmptyString(*VerbCaps)) (*VerbCaps)->Buffer[0] = PhUpcaseUnicodeChar((*VerbCaps)->Buffer[0]);

// "terminate", "the process" -> "terminate the process"
*Action = PhaConcatStrings(3, (*Verb)->Buffer, L" ", Context->Object);
}

VOID PhShowServiceProgressDialogConfirmMessage(
_In_ PPH_UI_SERVICE_PROGRESS_DIALOG Context
)
Expand All @@ -3752,8 +3781,9 @@ VOID PhShowServiceProgressDialogConfirmMessage(
PPH_STRING verb;
PPH_STRING verbCaps;
PPH_STRING action;
PCWSTR object;

PhpShowServiceProgressInitializeText(Context, &verb, &verbCaps, &action);
PhpShowServiceProgressInitializeText(Context, &verb, &verbCaps, &action, &object);

memset(&config, 0, sizeof(TASKDIALOGCONFIG));
config.cbSize = sizeof(TASKDIALOGCONFIG);
Expand Down Expand Up @@ -3950,7 +3980,6 @@ VOID PhShowServiceProgressDialog(
context = PhCreateServiceProgressContext();
context->ParentWindowHandle = WindowHandle;
context->Verb = Verb;
context->Object = NumberOfServices == 1 ? L"the selected service" : L"the selected services";
context->Message = Message;
context->Warning = Warning;
context->ActionCallback = ActionCallback;
Expand Down Expand Up @@ -6076,7 +6105,7 @@ BOOLEAN PhUiCloseHandles(
)
{
NTSTATUS status;
BOOLEAN cont = FALSE;
BOOLEAN result = FALSE;
BOOLEAN success = TRUE;
HANDLE processHandle;

Expand All @@ -6085,7 +6114,7 @@ BOOLEAN PhUiCloseHandles(

if (Warn && PhGetIntegerSetting(L"EnableWarnings"))
{
cont = PhShowConfirmMessage(
result = PhShowConfirmMessage(
WindowHandle,
L"close",
NumberOfHandles == 1 ? L"the selected handle" : L"the selected handles",
Expand All @@ -6095,10 +6124,10 @@ BOOLEAN PhUiCloseHandles(
}
else
{
cont = TRUE;
result = TRUE;
}

if (!cont)
if (!result)
return FALSE;

if (NT_SUCCESS(status = PhOpenProcess(
Expand Down Expand Up @@ -6141,7 +6170,7 @@ BOOLEAN PhUiCloseHandles(

if (critical && strict)
{
cont = PhShowConfirmMessage(
result = PhShowConfirmMessage(
WindowHandle,
L"close",
L"critical process handle(s)",
Expand All @@ -6150,11 +6179,26 @@ BOOLEAN PhUiCloseHandles(
);
}

if (!cont)
if (!result)
return FALSE;

for (ULONG i = 0; i < NumberOfHandles; i++)
{
if (FlagOn(Handles[i]->Attributes, OBJ_PROTECT_CLOSE))
{
if (!PhpShowErrorHandle(
WindowHandle,
L"close",
NULL,
Handles[i],
STATUS_HANDLE_NOT_CLOSABLE,
0
))
{
break;
}
}

status = NtDuplicateObject(
processHandle,
Handles[i]->Handle,
Expand All @@ -6179,22 +6223,6 @@ BOOLEAN PhUiCloseHandles(
))
break;
}
// If handle is protected from closing NtDuplicateObject doesn't close handle but returns STATUS_SUCCESS.
// Show error to notify user that "Protected" attribute should be removed first (Dart Vanya)
else if (Handles[i]->Attributes & OBJ_PROTECT_CLOSE)
{
success = FALSE;

if (!PhpShowErrorHandle(
WindowHandle,
L"close",
L".\nRemove \"Protected\" attribute from menu and try again.",
Handles[i],
STATUS_HANDLE_NOT_CLOSABLE,
0
))
break;
}
}

NtClose(processHandle);
Expand Down
2 changes: 1 addition & 1 deletion SystemInformer/anawait.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ BOOLEAN NTAPI PhpWalkThreadStackAnalyzeCallback(
{
PhAppendFormatStringBuilder(
&context->StringBuilder,
L"Thread is sleeping. Timeout: %I64u milliseconds.",
L"Thread is sleeping. Timeout: %llu milliseconds.",
-timeout / PH_TIMEOUT_MS
);
}
Expand Down
Loading

0 comments on commit b5a1ec7

Please sign in to comment.