abe198c0f0
This changeset tightens cache file path handling in phlib by validating leaf names, honoring native vs Win32 path modes consistently, and using the correct directory creation path. It also fixes several functional regressions across the app and plugins: module list filter refresh after highlight toggles, ETW endpoint/port mapping, aggregate sort field usage, graph child window clipping, safer uninstall status text handling, previous-instance shutdown in setup, and improved window-message timeout handling. Additional updates clean up initialization/casts, remove dead code, and address small correctness issues in formatting and utility logic.
453 lines
12 KiB
C
453 lines
12 KiB
C
/*
|
|
* Copyright (c) 2022 Winsider Seminars & Solutions, Inc. All rights reserved.
|
|
*
|
|
* This file is part of System Informer.
|
|
*
|
|
* Authors:
|
|
*
|
|
* dmex
|
|
*
|
|
*/
|
|
|
|
#include "setup.h"
|
|
|
|
/**
|
|
* Uninstalls System Informer.
|
|
*
|
|
* \param Context The setup context.
|
|
* \return Successful or errant status.
|
|
*/
|
|
_Function_class_(USER_THREAD_START_ROUTINE)
|
|
NTSTATUS CALLBACK SetupUninstallBuild(
|
|
_In_ PPH_SETUP_CONTEXT Context
|
|
)
|
|
{
|
|
NTSTATUS status;
|
|
|
|
//
|
|
// Stop the application.
|
|
//
|
|
|
|
if (!NT_SUCCESS(status = SetupShutdownApplication(Context)))
|
|
{
|
|
Context->LastStatus = status;
|
|
goto CleanupExit;
|
|
}
|
|
|
|
//
|
|
// Stop the kernel driver.
|
|
//
|
|
|
|
if (!NT_SUCCESS(status = SetupUninstallDriver(Context)))
|
|
{
|
|
Context->LastStatus = status;
|
|
goto CleanupExit;
|
|
}
|
|
|
|
//
|
|
// Remove all Windows Options (registry cleanup)
|
|
//
|
|
|
|
SetupDeleteWindowsOptions(Context);
|
|
|
|
//
|
|
// Remove Windows Error Reporting.
|
|
//
|
|
|
|
SetupDeleteLocalDumpsKey();
|
|
|
|
//
|
|
// Remove all shortcuts.
|
|
//
|
|
SetupDeleteShortcuts(Context, TRUE, TRUE);
|
|
|
|
//
|
|
// Remove the uninstaller.
|
|
//
|
|
|
|
SetupDeleteUninstallFile(Context);
|
|
|
|
//
|
|
// Remove the ARP uninstall entry.
|
|
//
|
|
|
|
SetupDeleteUninstallKey();
|
|
|
|
//
|
|
// Remove the previous installation.
|
|
//
|
|
|
|
if (!NT_SUCCESS(PhDeleteDirectoryWin32(&Context->SetupInstallPath->sr)))
|
|
{
|
|
static CONST PH_STRINGREF ksiFileName = PH_STRINGREF_INIT(L"ksi.dll");
|
|
static CONST PH_STRINGREF ksiOldFileName = PH_STRINGREF_INIT(L"ksi.dll-old");
|
|
PPH_STRING ksiFile;
|
|
PPH_STRING ksiOldFile;
|
|
|
|
ksiFile = PhConcatStringRef3(
|
|
&Context->SetupInstallPath->sr,
|
|
&PhNtPathSeparatorString,
|
|
&ksiFileName
|
|
);
|
|
|
|
ksiOldFile = PhConcatStringRef3(
|
|
&Context->SetupInstallPath->sr,
|
|
&PhNtPathSeparatorString,
|
|
&ksiOldFileName
|
|
);
|
|
|
|
PhMoveFileWin32(PhGetString(ksiFile), PhGetString(ksiOldFile), FALSE);
|
|
|
|
MoveFileEx(PhGetString(ksiOldFile), NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
|
|
MoveFileEx(PhGetString(Context->SetupInstallPath), NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
|
|
|
|
PhDereferenceObject(ksiOldFile);
|
|
PhDereferenceObject(ksiFile);
|
|
|
|
Context->NeedsReboot = TRUE;
|
|
}
|
|
|
|
//
|
|
// Remove the application data.
|
|
//
|
|
if (Context->SetupRemoveAppData)
|
|
SetupDeleteAppdataDirectory(Context);
|
|
|
|
SetupSetProgressText(Context, L"Uninstall complete.", NULL);
|
|
SetupSetProgressValue(Context, 100);
|
|
Context->SetupProgressActive = FALSE;
|
|
PostMessage(Context->DialogHandle, SETUP_SHOWUNINSTALLFINAL, 0, 0);
|
|
return STATUS_SUCCESS;
|
|
|
|
CleanupExit:
|
|
SetupSetProgressText(Context, L"Uninstall failed.", NULL);
|
|
Context->SetupProgressActive = FALSE;
|
|
PostMessage(Context->DialogHandle, SETUP_SHOWUNINSTALLERROR, 0, 0);
|
|
return STATUS_UNSUCCESSFUL;
|
|
}
|
|
|
|
/**
|
|
* Callback for the uninstall confirmation task dialog.
|
|
*
|
|
* \param hwndDlg The task dialog window handle.
|
|
* \param uMsg The notification message.
|
|
* \param wParam Additional message information.
|
|
* \param lParam Additional message information.
|
|
* \param dwRefData The setup context.
|
|
* \return S_OK to continue, otherwise an HRESULT value.
|
|
*/
|
|
HRESULT CALLBACK TaskDialogUninstallConfirmCallbackProc(
|
|
_In_ HWND hwndDlg,
|
|
_In_ UINT uMsg,
|
|
_In_ WPARAM wParam,
|
|
_In_ LPARAM lParam,
|
|
_In_ LONG_PTR dwRefData
|
|
)
|
|
{
|
|
PPH_SETUP_CONTEXT context = (PPH_SETUP_CONTEXT)dwRefData;
|
|
|
|
switch (uMsg)
|
|
{
|
|
case TDN_NAVIGATED:
|
|
{
|
|
PhCenterWindow(hwndDlg, NULL);
|
|
|
|
if (!PhGetOwnTokenAttributes().Elevated)
|
|
{
|
|
SendMessage(hwndDlg, TDM_SET_BUTTON_ELEVATION_REQUIRED_STATE, IDYES, TRUE);
|
|
}
|
|
}
|
|
break;
|
|
case TDN_BUTTON_CLICKED:
|
|
{
|
|
if ((INT)wParam == IDYES)
|
|
{
|
|
#ifndef FORCE_TEST_UPDATE_LOCAL_INSTALL
|
|
if (PhGetOwnTokenAttributes().Elevated)
|
|
{
|
|
ShowUninstallingPageDialog(context);
|
|
return S_FALSE;
|
|
}
|
|
else
|
|
{
|
|
NTSTATUS status;
|
|
PPH_STRING applicationFileName;
|
|
PH_STRINGREF applicationCommandLine;
|
|
|
|
if (!NT_SUCCESS(status = PhGetProcessCommandLineStringRef(&applicationCommandLine)))
|
|
{
|
|
context->LastStatus = status;
|
|
return S_FALSE;
|
|
}
|
|
if (!(applicationFileName = PhGetApplicationFileNameWin32()))
|
|
{
|
|
context->LastStatus = STATUS_NO_MEMORY;
|
|
return S_FALSE;
|
|
}
|
|
|
|
if (NT_SUCCESS(status = PhShellExecuteEx(
|
|
hwndDlg,
|
|
PhGetString(applicationFileName),
|
|
PhGetStringRefZ(&applicationCommandLine),
|
|
NULL,
|
|
SW_SHOW,
|
|
PH_SHELL_EXECUTE_ADMIN,
|
|
0,
|
|
&context->SubProcessHandle
|
|
)))
|
|
{
|
|
ShowWindow(hwndDlg, SW_HIDE);
|
|
}
|
|
else
|
|
{
|
|
context->LastStatus = status;
|
|
PhDereferenceObject(applicationFileName);
|
|
return S_FALSE;
|
|
}
|
|
}
|
|
#else
|
|
ShowUninstallingPageDialog(context);
|
|
return S_FALSE;
|
|
#endif
|
|
}
|
|
}
|
|
break;
|
|
case TDN_VERIFICATION_CLICKED:
|
|
{
|
|
context->SetupRemoveAppData = !!(BOOL)wParam;
|
|
}
|
|
break;
|
|
}
|
|
|
|
return S_OK;
|
|
}
|
|
|
|
/**
|
|
* Callback for the uninstall error task dialog.
|
|
*
|
|
* \param hwndDlg The task dialog window handle.
|
|
* \param uMsg The notification message.
|
|
* \param wParam Additional message information.
|
|
* \param lParam Additional message information.
|
|
* \param dwRefData The setup context.
|
|
* \return S_OK to continue, otherwise an HRESULT value.
|
|
*/
|
|
HRESULT CALLBACK TaskDialogUninstallErrorCallbackProc(
|
|
_In_ HWND hwndDlg,
|
|
_In_ UINT uMsg,
|
|
_In_ WPARAM wParam,
|
|
_In_ LPARAM lParam,
|
|
_In_ LONG_PTR dwRefData
|
|
)
|
|
{
|
|
PPH_SETUP_CONTEXT context = (PPH_SETUP_CONTEXT)dwRefData;
|
|
|
|
switch (uMsg)
|
|
{
|
|
case TDN_BUTTON_CLICKED:
|
|
{
|
|
if ((INT)wParam == IDRETRY)
|
|
{
|
|
ShowUninstallingPageDialog(context);
|
|
return S_FALSE;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
return S_OK;
|
|
}
|
|
|
|
/**
|
|
* Callback for the uninstall progress task dialog.
|
|
*
|
|
* \param hwndDlg The task dialog window handle.
|
|
* \param uMsg The notification message.
|
|
* \param wParam Additional message information.
|
|
* \param lParam Additional message information.
|
|
* \param dwRefData The setup context.
|
|
* \return S_OK to continue, otherwise an HRESULT value.
|
|
*/
|
|
HRESULT CALLBACK TaskDialogUninstallCallbackProc(
|
|
_In_ HWND hwndDlg,
|
|
_In_ UINT uMsg,
|
|
_In_ WPARAM wParam,
|
|
_In_ LPARAM lParam,
|
|
_In_ LONG_PTR dwRefData
|
|
)
|
|
{
|
|
PPH_SETUP_CONTEXT context = (PPH_SETUP_CONTEXT)dwRefData;
|
|
|
|
switch (uMsg)
|
|
{
|
|
case TDN_NAVIGATED:
|
|
{
|
|
SendMessage(hwndDlg, TDM_SET_MARQUEE_PROGRESS_BAR, TRUE, 0);
|
|
SendMessage(hwndDlg, TDM_SET_PROGRESS_BAR_MARQUEE, TRUE, 1);
|
|
|
|
PhCreateThread2(SetupUninstallBuild, context);
|
|
}
|
|
break;
|
|
}
|
|
|
|
return S_OK;
|
|
}
|
|
|
|
/**
|
|
* Callback for the uninstall completed task dialog.
|
|
*
|
|
* \param hwndDlg The task dialog window handle.
|
|
* \param uMsg The notification message.
|
|
* \param wParam Additional message information.
|
|
* \param lParam Additional message information.
|
|
* \param dwRefData The setup context.
|
|
* \return S_OK to continue, otherwise an HRESULT value.
|
|
*/
|
|
HRESULT CALLBACK TaskDialogUninstallCompleteCallbackProc(
|
|
_In_ HWND hwndDlg,
|
|
_In_ UINT uMsg,
|
|
_In_ WPARAM wParam,
|
|
_In_ LPARAM lParam,
|
|
_In_ LONG_PTR dwRefData
|
|
)
|
|
{
|
|
PPH_SETUP_CONTEXT context = (PPH_SETUP_CONTEXT)dwRefData;
|
|
|
|
switch (uMsg)
|
|
{
|
|
case TDN_NAVIGATED:
|
|
SetupApplyDarkModeToPage(hwndDlg);
|
|
SendMessage(hwndDlg, TDM_SET_PROGRESS_BAR_POS, 100, 0);
|
|
break;
|
|
}
|
|
|
|
return S_OK;
|
|
}
|
|
|
|
/**
|
|
* Shows the uninstall completed page.
|
|
*
|
|
* \param Context The setup context.
|
|
*/
|
|
VOID ShowUninstallCompletedPageDialog(
|
|
_In_ PPH_SETUP_CONTEXT Context
|
|
)
|
|
{
|
|
TASKDIALOGCONFIG config;
|
|
|
|
memset(&config, 0, sizeof(TASKDIALOGCONFIG));
|
|
config.cbSize = sizeof(TASKDIALOGCONFIG);
|
|
config.dwFlags = TDF_USE_HICON_MAIN | TDF_ALLOW_DIALOG_CANCELLATION | TDF_CAN_BE_MINIMIZED | TDF_SHOW_PROGRESS_BAR;
|
|
config.dwCommonButtons = TDCBF_CLOSE_BUTTON;
|
|
config.hMainIcon = Context->IconLargeHandle;
|
|
config.pfCallback = TaskDialogUninstallCompleteCallbackProc;
|
|
config.lpCallbackData = (LONG_PTR)Context;
|
|
|
|
config.cxWidth = 200;
|
|
config.pszWindowTitle = PhApplicationName;
|
|
config.pszMainInstruction = L"System Informer has been uninstalled.";
|
|
if (Context->NeedsReboot)
|
|
config.pszContent = L"A reboot is required to complete the uninstall.";
|
|
else
|
|
config.pszContent = L"Click close to exit setup.";
|
|
|
|
PhTaskDialogNavigatePage(Context->DialogHandle, &config);
|
|
}
|
|
|
|
/**
|
|
* Shows the uninstall progress page.
|
|
*
|
|
* \param Context The setup context.
|
|
*/
|
|
VOID ShowUninstallingPageDialog(
|
|
_In_ PPH_SETUP_CONTEXT Context
|
|
)
|
|
{
|
|
TASKDIALOGCONFIG config;
|
|
|
|
memset(&config, 0, sizeof(TASKDIALOGCONFIG));
|
|
config.cbSize = sizeof(TASKDIALOGCONFIG);
|
|
config.dwFlags = TDF_USE_HICON_MAIN | TDF_ALLOW_DIALOG_CANCELLATION | TDF_CAN_BE_MINIMIZED | TDF_SHOW_MARQUEE_PROGRESS_BAR;
|
|
config.dwCommonButtons = TDCBF_CANCEL_BUTTON;
|
|
config.hMainIcon = Context->IconLargeHandle;
|
|
config.pfCallback = TaskDialogUninstallCallbackProc;
|
|
config.lpCallbackData = (LONG_PTR)Context;
|
|
|
|
config.cxWidth = 200;
|
|
config.pszWindowTitle = PhApplicationName;
|
|
config.pszMainInstruction = L"Uninstalling System Informer...";
|
|
|
|
PhTaskDialogNavigatePage(Context->DialogHandle, &config);
|
|
}
|
|
|
|
/**
|
|
* Shows the uninstall error page.
|
|
*
|
|
* \param Context The setup context.
|
|
*/
|
|
VOID ShowUninstallErrorPageDialog(
|
|
_In_ PPH_SETUP_CONTEXT Context
|
|
)
|
|
{
|
|
TASKDIALOGCONFIG config;
|
|
|
|
memset(&config, 0, sizeof(TASKDIALOGCONFIG));
|
|
config.cbSize = sizeof(TASKDIALOGCONFIG);
|
|
config.dwFlags = TDF_USE_HICON_MAIN | TDF_ALLOW_DIALOG_CANCELLATION | TDF_CAN_BE_MINIMIZED;
|
|
config.dwCommonButtons = TDCBF_RETRY_BUTTON | TDCBF_CLOSE_BUTTON;
|
|
config.hMainIcon = Context->IconLargeHandle;
|
|
config.pfCallback = TaskDialogUninstallErrorCallbackProc;
|
|
config.lpCallbackData = (LONG_PTR)Context;
|
|
|
|
config.cxWidth = 200;
|
|
config.pszWindowTitle = PhApplicationName;
|
|
PPH_STRING statusMessage = NULL;
|
|
|
|
if (Context->LastStatus)
|
|
statusMessage = PhGetStatusMessage(Context->LastStatus, 0);
|
|
if (statusMessage)
|
|
config.pszMainInstruction = statusMessage->Buffer;
|
|
else
|
|
config.pszMainInstruction = L"Uninstall failed with an error.";
|
|
config.pszContent = L"Click retry to try again or close to exit setup.";
|
|
|
|
PhTaskDialogNavigatePage(Context->DialogHandle, &config);
|
|
}
|
|
|
|
/**
|
|
* Shows the uninstall confirmation page.
|
|
*
|
|
* \param Context The setup context.
|
|
*/
|
|
VOID ShowUninstallPageDialog(
|
|
_In_ PPH_SETUP_CONTEXT Context
|
|
)
|
|
{
|
|
TASKDIALOG_BUTTON buttonArray[] =
|
|
{
|
|
{ IDYES, L"Uninstall" }
|
|
};
|
|
TASKDIALOGCONFIG config;
|
|
|
|
memset(&config, 0, sizeof(TASKDIALOGCONFIG));
|
|
config.cbSize = sizeof(TASKDIALOGCONFIG);
|
|
config.dwFlags = TDF_USE_HICON_MAIN | TDF_ALLOW_DIALOG_CANCELLATION | TDF_CAN_BE_MINIMIZED;
|
|
config.hMainIcon = Context->IconLargeHandle;
|
|
config.pButtons = buttonArray;
|
|
config.cButtons = ARRAYSIZE(buttonArray);
|
|
config.pfCallback = TaskDialogUninstallConfirmCallbackProc;
|
|
config.lpCallbackData = (LONG_PTR)Context;
|
|
|
|
config.cxWidth = 200;
|
|
config.pszWindowTitle = PhApplicationName;
|
|
config.pszMainInstruction = PhApplicationName;
|
|
config.pszContent = L"Are you sure you want to uninstall System Informer?";
|
|
if (PhGetOwnTokenAttributes().Elevated)
|
|
config.pszVerificationText = L"Remove application settings";
|
|
config.dwCommonButtons = TDCBF_CANCEL_BUTTON;
|
|
config.nDefaultButton = IDCANCEL;
|
|
|
|
PhTaskDialogNavigatePage(Context->DialogHandle, &config);
|
|
}
|
|
|