add plugins-extra

This commit is contained in:
AirDog46
2025-05-13 19:49:49 +03:00
parent c5fab8aa94
commit 3575d86c17
531 changed files with 70258 additions and 1 deletions

View File

@@ -0,0 +1,82 @@
/*
* Process Hacker Plugins -
* Update Checker Plugin
*
* Copyright (C) 2016 dmex
*
* This file is part of Process Hacker.
*
* Process Hacker is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Process Hacker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
*/
#include "..\main.h"
static TASKDIALOG_BUTTON TaskDialogButtonArray[] =
{
{ IDOK, L"Install" }
};
HRESULT CALLBACK CheckForUpdatesCallbackProc(
_In_ HWND hwndDlg,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam,
_In_ LONG_PTR dwRefData
)
{
PPH_UPDATER_CONTEXT context = (PPH_UPDATER_CONTEXT)dwRefData;
switch (uMsg)
{
case TDN_NAVIGATED:
break;
case TDN_BUTTON_CLICKED:
{
if ((INT)wParam == IDOK)
{
ShowCheckingForUpdatesDialog(context);
return S_FALSE;
}
}
break;
}
return S_OK;
}
VOID ShowCheckForUpdatesDialog(
_In_ PPH_UPDATER_CONTEXT Context
)
{
TASKDIALOGCONFIG config;
memset(&config, 0, sizeof(TASKDIALOGCONFIG));
config.cbSize = sizeof(TASKDIALOGCONFIG);
config.dwFlags = TDF_USE_HICON_MAIN | TDF_ALLOW_DIALOG_CANCELLATION | TDF_ENABLE_HYPERLINKS;
config.dwCommonButtons = TDCBF_CLOSE_BUTTON;
config.hMainIcon = Context->IconLargeHandle;
config.pszWindowTitle = L"Process Hacker";
config.pszMainInstruction = L"Install ABC??";
//config.pszContent = L"The updater will check for new Process Hacker releases and optionally download and install the update.\r\n\r\nClick the check for updates button to continue.";
config.pszContent = L"Name: ToolStatus.dll\r\nName: ToolStatus.dll\r\nName: ToolStatus.dll\r\nName: ToolStatus.dll\r\n\r\nClick the check for updates button to continue.";
config.cxWidth = 200;
config.pButtons = TaskDialogButtonArray;
config.cButtons = ARRAYSIZE(TaskDialogButtonArray);
config.pfCallback = CheckForUpdatesCallbackProc;
config.lpCallbackData = (LONG_PTR)Context;
SendMessage(Context->DialogHandle, TDM_NAVIGATE_PAGE, 0, (LPARAM)&config);
}

View File

@@ -0,0 +1,71 @@
/*
* Process Hacker Plugins -
* Update Checker Plugin
*
* Copyright (C) 2016 dmex
*
* This file is part of Process Hacker.
*
* Process Hacker is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Process Hacker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
*/
#include "..\main.h"
HRESULT CALLBACK CheckingForUpdatesCallbackProc(
_In_ HWND hwndDlg,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam,
_In_ LONG_PTR dwRefData
)
{
PPH_UPDATER_CONTEXT context = (PPH_UPDATER_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);
//PhQueueItemWorkQueue(PhGetGlobalWorkQueue(), UpdateCheckThread, context);
}
break;
}
return S_OK;
}
VOID ShowCheckingForUpdatesDialog(
_In_ PPH_UPDATER_CONTEXT Context
)
{
TASKDIALOGCONFIG config;
memset(&config, 0, sizeof(TASKDIALOGCONFIG));
config.cbSize = sizeof(TASKDIALOGCONFIG);
config.dwFlags = TDF_USE_HICON_MAIN | TDF_ALLOW_DIALOG_CANCELLATION | TDF_SHOW_MARQUEE_PROGRESS_BAR;
config.dwCommonButtons = TDCBF_CLOSE_BUTTON;
config.hMainIcon = Context->IconLargeHandle;
config.pszWindowTitle = L"Process Hacker";
//config.pszMainInstruction = L"Installing ToolStatus plugin";
config.pszContent = L"Checking plugin signature...";
config.cxWidth = 200;
config.pfCallback = CheckingForUpdatesCallbackProc;
config.lpCallbackData = (LONG_PTR)Context;
SendMessage(Context->DialogHandle, TDM_NAVIGATE_PAGE, 0, (LPARAM)&config);
}

View File

@@ -0,0 +1,100 @@
/*
* Process Hacker Plugins -
* Update Checker Plugin
*
* Copyright (C) 2016 dmex
*
* This file is part of Process Hacker.
*
* Process Hacker is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Process Hacker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
*/
#include "..\main.h"
static TASKDIALOG_BUTTON TaskDialogButtonArray[] =
{
{ IDOK, L"Download" }
};
HRESULT CALLBACK ShowAvailableCallbackProc(
_In_ HWND hwndDlg,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam,
_In_ LONG_PTR dwRefData
)
{
PPH_UPDATER_CONTEXT context = (PPH_UPDATER_CONTEXT)dwRefData;
switch (uMsg)
{
case TDN_NAVIGATED:
break;
case TDN_BUTTON_CLICKED:
{
if ((INT)wParam == IDOK)
{
//if (UpdaterInstalledUsingSetup())
{
ShowProgressDialog(context);
return S_FALSE;
}
//else
{
//PhShellExecute(hwndDlg, L"https://wj32.org/processhacker/downloads.php", NULL);
}
}
}
break;
case TDN_HYPERLINK_CLICKED:
{
//TaskDialogLinkClicked(context);
}
break;
}
return S_OK;
}
VOID ShowAvailableDialog(
_In_ PPH_UPDATER_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_ENABLE_HYPERLINKS | TDF_SHOW_PROGRESS_BAR;
config.dwCommonButtons = TDCBF_CANCEL_BUTTON;
config.hMainIcon = Context->IconLargeHandle;
config.pszWindowTitle = L"Process Hacker - Plugin Manager";
config.pszMainInstruction = PhIsNullOrEmptyString(Context->Node->Name) ? PhGetStringOrEmpty(Context->Node->InternalName) : PhGetStringOrEmpty(Context->Node->Name);
config.pszContent = PhaFormatString(L"%s\r\n\r\nAuthor: %s\r\nVersion: %s\r\nUpdated: %s",
PhGetStringOrEmpty(Context->Node->Description),
PhGetStringOrEmpty(Context->Node->Author),
PhGetStringOrEmpty(Context->Node->Version),
PhGetStringOrEmpty(Context->Node->UpdatedTime)
)->Buffer;
//config.pszExpandedInformation = L"<A HREF=\"executablestring\">View Changelog</A>";
config.cxWidth = 200;
config.pButtons = TaskDialogButtonArray;
config.cButtons = ARRAYSIZE(TaskDialogButtonArray);
config.lpCallbackData = (LONG_PTR)Context;
config.pfCallback = ShowAvailableCallbackProc;
SendMessage(Context->DialogHandle, TDM_NAVIGATE_PAGE, 0, (LPARAM)&config);
}

View File

@@ -0,0 +1,77 @@
/*
* Process Hacker Plugins -
* Update Checker Plugin
*
* Copyright (C) 2016 dmex
*
* This file is part of Process Hacker.
*
* Process Hacker is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Process Hacker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
*/
#include "..\main.h"
HRESULT CALLBACK ShowProgressCallbackProc(
_In_ HWND hwndDlg,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam,
_In_ LONG_PTR dwRefData
)
{
PPH_UPDATER_CONTEXT context = (PPH_UPDATER_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);
PhQueueItemWorkQueue(PhGetGlobalWorkQueue(), UpdateDownloadThread, context);
}
break;
case TDN_HYPERLINK_CLICKED:
{
TaskDialogLinkClicked(context);
}
break;
}
return S_OK;
}
VOID ShowProgressDialog(
_In_ PPH_UPDATER_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_ENABLE_HYPERLINKS | TDF_SHOW_PROGRESS_BAR;
config.dwCommonButtons = TDCBF_CANCEL_BUTTON;
config.hMainIcon = Context->IconLargeHandle;
config.pszWindowTitle = L"Process Hacker - Plugin Manager";
config.pszMainInstruction = L"Downloading 0.0.0.0...";
config.pszContent = L"Downloaded: ~ of ~ (0%)\r\nSpeed: ~ KB/s";
//config.pszExpandedInformation = L"<A HREF=\"executablestring\">View Changelog</A>";
config.cxWidth = 200;
config.lpCallbackData = (LONG_PTR)Context;
config.pfCallback = ShowProgressCallbackProc;
SendMessage(Context->DialogHandle, TDM_NAVIGATE_PAGE, 0, (LPARAM)&config);
}

View File

@@ -0,0 +1,227 @@
/*
* Process Hacker Plugins -
* Update Checker Plugin
*
* Copyright (C) 2016 dmex
*
* This file is part of Process Hacker.
*
* Process Hacker is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Process Hacker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
*/
#include "..\main.h"
#include <shellapi.h>
#include <shlobj.h>
static TASKDIALOG_BUTTON TaskDialogButtonArray[] =
{
{ IDYES, L"Restart" }
};
HRESULT CALLBACK RestartTaskDialogCallbackProc(
_In_ HWND hwndDlg,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam,
_In_ LONG_PTR dwRefData
)
{
PPH_UPDATER_CONTEXT context = (PPH_UPDATER_CONTEXT)dwRefData;
switch (uMsg)
{
case TDN_BUTTON_CLICKED:
{
if ((INT)wParam == IDYES)
{
SHELLEXECUTEINFO info = { sizeof(SHELLEXECUTEINFO) };
/* if (PhIsNullOrEmptyString(context->SetupFilePath))
break;*/
info.lpFile = L"ProcessHacker.exe";
info.nShow = SW_SHOW;
info.hwnd = hwndDlg;
//info.lpParameters = L"-plugin dmex.ExtraPlugins:INSTALL -plugin dmex.ExtraPlugins:hex64value";
ProcessHacker_PrepareForEarlyShutdown(PhMainWndHandle);
if (ShellExecuteEx(&info))
{
NtTerminateProcess(NtCurrentProcess(), STATUS_SUCCESS);
}
else
{
// Install failed, cancel the shutdown
ProcessHacker_CancelEarlyShutdown(PhMainWndHandle);
// Set button text for next action
//Button_SetText(GetDlgItem(hwndDlg, IDOK), L"Retry");
return S_FALSE;
}
}
}
break;
}
return S_OK;
}
HRESULT CALLBACK FinalTaskDialogCallbackProc(
_In_ HWND hwndDlg,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam,
_In_ LONG_PTR dwRefData
)
{
PPH_UPDATER_CONTEXT context = (PPH_UPDATER_CONTEXT)dwRefData;
switch (uMsg)
{
case TDN_NAVIGATED:
{
if (!PhGetOwnTokenAttributes().Elevated)
{
SendMessage(hwndDlg, TDM_SET_BUTTON_ELEVATION_REQUIRED_STATE, IDYES, TRUE);
}
}
break;
case TDN_BUTTON_CLICKED:
break;
}
return S_OK;
}
VOID ShowInstallRestartDialog(
_In_ PPH_UPDATER_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_CLOSE_BUTTON;
config.hMainIcon = Context->IconLargeHandle;
config.pszWindowTitle = L"Process Hacker - Plugin Manager";
config.pszMainInstruction = L"Process Hacker needs to restart";
config.pszContent = L"Changes may require a restart to take effect...";
config.pButtons = TaskDialogButtonArray;
config.cButtons = ARRAYSIZE(TaskDialogButtonArray);
config.cxWidth = 200;
config.pfCallback = RestartTaskDialogCallbackProc;
config.lpCallbackData = (LONG_PTR)Context;
SendMessage(Context->DialogHandle, TDM_NAVIGATE_PAGE, 0, (LPARAM)&config);
}
VOID ShowUninstallRestartDialog(
_In_ PPH_UPDATER_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_CLOSE_BUTTON;
config.hMainIcon = Context->IconLargeHandle;
config.pszWindowTitle = L"Process Hacker - Plugin Manager";
config.pszMainInstruction = L"Process Hacker needs to restart";
config.pszContent = L"Changes may require a restart to take effect...";
config.pButtons = TaskDialogButtonArray;
config.cButtons = ARRAYSIZE(TaskDialogButtonArray);
config.cxWidth = 200;
config.pfCallback = RestartTaskDialogCallbackProc;
config.lpCallbackData = (LONG_PTR)Context;
SendMessage(Context->DialogHandle, TDM_NAVIGATE_PAGE, 0, (LPARAM)&config);
}
VOID ShowLatestVersionDialog(
_In_ PPH_UPDATER_CONTEXT Context
)
{
PPH_UPDATER_CONTEXT context;
TASKDIALOGCONFIG config;
context = (PPH_UPDATER_CONTEXT)Context;
memset(&config, 0, sizeof(TASKDIALOGCONFIG));
config.cbSize = sizeof(TASKDIALOGCONFIG);
config.dwFlags = TDF_USE_HICON_MAIN | TDF_ALLOW_DIALOG_CANCELLATION | TDF_CAN_BE_MINIMIZED | TDF_ENABLE_HYPERLINKS;
config.dwCommonButtons = TDCBF_CLOSE_BUTTON;
config.hMainIcon = context->IconLargeHandle;
config.pszWindowTitle = L"Process Hacker - Plugin Manager";
config.pszMainInstruction = L"You're running the latest version.";
//config.pszContent = PhaFormatString(
// L"Stable release build: v%lu.%lu.%lu\r\n\r\n<A HREF=\"executablestring\">View Changelog</A>",
// context->CurrentMajorVersion,
// context->CurrentMinorVersion,
// context->CurrentRevisionVersion
// )->Buffer;
config.cxWidth = 200;
config.pfCallback = FinalTaskDialogCallbackProc;
config.lpCallbackData = (LONG_PTR)Context;
SendMessage(Context->DialogHandle, TDM_NAVIGATE_PAGE, 0, (LPARAM)&config);
}
VOID ShowUpdateFailedDialog(
_In_ PPH_UPDATER_CONTEXT Context,
_In_ BOOLEAN HashFailed,
_In_ BOOLEAN SignatureFailed
)
{
TASKDIALOGCONFIG config;
memset(&config, 0, sizeof(TASKDIALOGCONFIG));
config.cbSize = sizeof(TASKDIALOGCONFIG);
//config.pszMainIcon = MAKEINTRESOURCE(65529);
config.dwFlags = TDF_USE_HICON_MAIN | TDF_ALLOW_DIALOG_CANCELLATION | TDF_CAN_BE_MINIMIZED;
config.dwCommonButtons = TDCBF_CLOSE_BUTTON | TDCBF_RETRY_BUTTON;
config.hMainIcon = Context->IconLargeHandle;
config.pszWindowTitle = L"Process Hacker - Plugin Manager";
config.pszMainInstruction = L"Error downloading plugin files.";
if (SignatureFailed)
{
config.pszContent = L"Signature check failed. Click Retry to download the plugin again.";
}
else if (HashFailed)
{
config.pszContent = L"Hash check failed. Click Retry to download the plugin again.";
}
else
{
config.pszContent = L"Click Retry to download the plugin again.";
}
config.cxWidth = 200;
config.pfCallback = FinalTaskDialogCallbackProc;
config.lpCallbackData = (LONG_PTR)Context;
SendMessage(Context->DialogHandle, TDM_NAVIGATE_PAGE, 0, (LPARAM)&config);
}

View File

@@ -0,0 +1,81 @@
#include "..\main.h"
#include <shellapi.h>
#include <shlobj.h>
static TASKDIALOG_BUTTON TaskDialogButtonArray[] =
{
{ IDYES, L"Uninstall" }
};
HRESULT CALLBACK TaskDialogUninstallCallbackProc(
_In_ HWND hwndDlg,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam,
_In_ LONG_PTR dwRefData
)
{
PPH_UPDATER_CONTEXT context = (PPH_UPDATER_CONTEXT)dwRefData;
switch (uMsg)
{
case TDN_NAVIGATED:
{
//PhQueueItemWorkQueue(PhGetGlobalWorkQueue(), SetupExtractBuild, context);
}
break;
case TDN_BUTTON_CLICKED:
{
if ((INT)wParam == IDYES)
{
PPH_STRING baseNameString;
PPH_STRING fileNameString;
PPH_STRING bakNameString;
context->Node->State = PLUGIN_STATE_RESTART;
fileNameString = PhGetFileName(context->Node->FilePath);
baseNameString = PhGetBaseName(context->Node->FilePath);
bakNameString = PhConcatStrings(2, PhGetString(fileNameString), L".bak");
if (RtlDoesFileExists_U(PhGetString(fileNameString)))
{
MoveFileEx(PhGetString(fileNameString), PhGetString(bakNameString), MOVEFILE_REPLACE_EXISTING);
}
PhDereferenceObject(bakNameString);
PhDereferenceObject(baseNameString);
PhDereferenceObject(fileNameString);
PostMessage(context->DialogHandle, PH_UPDATENEWER, 0, 0);
return S_FALSE;
}
}
break;
}
return S_OK;
}
VOID ShowPluginUninstallDialog(
_In_ PPH_UPDATER_CONTEXT Context
)
{
PPH_UPDATER_CONTEXT context;
TASKDIALOGCONFIG config = { sizeof(TASKDIALOGCONFIG) };
context = (PPH_UPDATER_CONTEXT)Context;
config.cxWidth = 200;
config.pszWindowTitle = L"Process Hacker - Plugin Manager";
config.pszMainInstruction = PhaFormatString(L"Uninstall %s?", PhIsNullOrEmptyString(Context->Node->Name) ? PhGetStringOrEmpty(Context->Node->InternalName) : PhGetStringOrEmpty(Context->Node->Name))->Buffer;
config.dwFlags = TDF_USE_HICON_MAIN | TDF_ALLOW_DIALOG_CANCELLATION | TDF_CAN_BE_MINIMIZED;
config.dwCommonButtons = TDCBF_CLOSE_BUTTON;
config.hMainIcon = context->IconLargeHandle;
config.pfCallback = TaskDialogUninstallCallbackProc;
config.lpCallbackData = (LONG_PTR)Context;
config.pButtons = TaskDialogButtonArray;
config.cButtons = ARRAYSIZE(TaskDialogButtonArray);
SendMessage(Context->DialogHandle, TDM_NAVIGATE_PAGE, 0, (LPARAM)&config);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,206 @@
#include "..\main.h"
static UCHAR ExtraPluginsPublicKey[] =
{
0x45, 0x43, 0x53, 0x31, 0x20, 0x00, 0x00, 0x00, 0x24, 0x33, 0x0F, 0x97,
0x6B, 0xBA, 0x8B, 0xDD, 0x18, 0x2F, 0x7A, 0xAC, 0x53, 0x8F, 0xE3, 0x2A,
0x30, 0xA8, 0x8A, 0x47, 0x12, 0x3A, 0x4D, 0xCB, 0x11, 0x6A, 0x7E, 0x61,
0x32, 0xEE, 0xF8, 0xE9, 0x6A, 0x9B, 0x85, 0x23, 0x9F, 0x08, 0xEB, 0xC3,
0x8C, 0x60, 0xFD, 0xDE, 0xD3, 0x73, 0xCB, 0xFE, 0x53, 0xF6, 0x08, 0xCB,
0xE6, 0xF9, 0x34, 0x4B, 0x14, 0x37, 0x17, 0x74, 0xAF, 0xFF, 0xCC, 0xAB
};
BOOLEAN UpdaterInitializeHash(
_Out_ PUPDATER_HASH_CONTEXT *Context
)
{
ULONG querySize;
PUPDATER_HASH_CONTEXT hashContext;
hashContext = PhAllocate(sizeof(UPDATER_HASH_CONTEXT));
memset(hashContext, 0, sizeof(UPDATER_HASH_CONTEXT));
if (!NT_SUCCESS(BCryptOpenAlgorithmProvider(
&hashContext->SignAlgHandle,
BCRYPT_ECDSA_P256_ALGORITHM,
NULL,
0
)))
{
goto error;
}
if (!NT_SUCCESS(BCryptImportKeyPair(
hashContext->SignAlgHandle,
NULL,
BCRYPT_ECCPUBLIC_BLOB,
&hashContext->KeyHandle,
ExtraPluginsPublicKey,
sizeof(ExtraPluginsPublicKey),
0
)))
{
goto error;
}
if (!NT_SUCCESS(BCryptOpenAlgorithmProvider(
&hashContext->HashAlgHandle,
BCRYPT_SHA256_ALGORITHM,
NULL,
0
)))
{
goto error;
}
if (!NT_SUCCESS(BCryptGetProperty(
hashContext->HashAlgHandle,
BCRYPT_OBJECT_LENGTH,
(PUCHAR)&hashContext->HashObjectSize,
sizeof(ULONG),
&querySize,
0
)))
{
goto error;
}
if (!NT_SUCCESS(BCryptGetProperty(
hashContext->HashAlgHandle,
BCRYPT_HASH_LENGTH,
(PUCHAR)&hashContext->HashSize,
sizeof(ULONG),
&querySize,
0
)))
{
goto error;
}
if (!(hashContext->HashObject = PhAllocate(hashContext->HashObjectSize)))
goto error;
if (!(hashContext->Hash = PhAllocate(hashContext->HashSize)))
goto error;
if (!NT_SUCCESS(BCryptCreateHash(
hashContext->HashAlgHandle,
&hashContext->HashHandle,
hashContext->HashObject,
hashContext->HashObjectSize,
NULL,
0,
0
)))
{
goto error;
}
*Context = hashContext;
return TRUE;
error:
UpdaterDestroyHash(hashContext);
return FALSE;
}
BOOLEAN UpdaterUpdateHash(
_Inout_ PUPDATER_HASH_CONTEXT Context,
_In_reads_bytes_(Length) PVOID Buffer,
_In_ ULONG Length
)
{
return NT_SUCCESS(BCryptHashData(Context->HashHandle, Buffer, Length, 0));
}
BOOLEAN UpdaterVerifyHash(
_Inout_ PUPDATER_HASH_CONTEXT Context,
_In_ PPH_STRING Sha2Hash
)
{
PPH_STRING sha2HexString;
// Compute the final hash.
if (!NT_SUCCESS(BCryptFinishHash(
Context->HashHandle,
Context->Hash,
Context->HashSize,
0
)))
{
return FALSE;
}
if (!(sha2HexString = PhBufferToHexString(Context->Hash, Context->HashSize)))
return FALSE;
if (!PhEqualString2(sha2HexString, PhGetStringOrEmpty(Sha2Hash), TRUE))
{
PhDereferenceObject(sha2HexString);
return FALSE;
}
PhDereferenceObject(sha2HexString);
return TRUE;
}
BOOLEAN UpdaterVerifySignature(
_Inout_ PUPDATER_HASH_CONTEXT Context,
_In_ PPH_STRING HexSignature
)
{
ULONG signatureLength;
PUCHAR signatureBuffer;
signatureLength = (ULONG)HexSignature->Length / sizeof(WCHAR) / 2;
signatureBuffer = PhAllocate(signatureLength);
if (!PhHexStringToBuffer(&HexSignature->sr, signatureBuffer))
{
PhFree(signatureBuffer);
return FALSE;
}
// Verify the signature.
if (!NT_SUCCESS(BCryptVerifySignature(
Context->KeyHandle,
NULL,
Context->Hash,
Context->HashSize,
signatureBuffer,
signatureLength,
0
)))
{
PhFree(signatureBuffer);
return FALSE;
}
PhFree(signatureBuffer);
return TRUE;
}
VOID UpdaterDestroyHash(
_Inout_ PUPDATER_HASH_CONTEXT Context
)
{
if (Context->HashAlgHandle)
BCryptCloseAlgorithmProvider(Context->HashAlgHandle, 0);
if (Context->SignAlgHandle)
BCryptCloseAlgorithmProvider(Context->SignAlgHandle, 0);
if (Context->HashHandle)
BCryptDestroyHash(Context->HashHandle);
if (Context->KeyHandle)
BCryptDestroyKey(Context->KeyHandle);
if (Context->HashObject)
PhFree(Context->HashObject);
if (Context->Hash)
PhFree(Context->Hash);
PhFree(Context);
}