Skip to content

Commit 9e927e6

Browse files
committed
Updater: Fix crash winsiderss#379
1 parent d0f0ee5 commit 9e927e6

File tree

10 files changed

+75
-42
lines changed

10 files changed

+75
-42
lines changed

plugins/Updater/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Process Hacker Plugins -
33
* Update Checker Plugin
44
*
5-
* Copyright (C) 2011-2016 dmex
5+
* Copyright (C) 2011-2019 dmex
66
*
77
* This file is part of Process Hacker.
88
*
@@ -138,10 +138,10 @@ LOGICAL DllMain(
138138
&PluginShowOptionsCallbackRegistration
139139
);
140140

141-
PhAddSettings(settings, ARRAYSIZE(settings));
141+
PhAddSettings(settings, RTL_NUMBER_OF(settings));
142142
}
143143
break;
144144
}
145145

146146
return TRUE;
147-
}
147+
}

plugins/Updater/options.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Process Hacker Plugins -
33
* Update Checker Plugin
44
*
5-
* Copyright (C) 2011-2016 dmex
5+
* Copyright (C) 2011-2019 dmex
66
*
77
* This file is part of Process Hacker.
88
*
@@ -33,8 +33,6 @@ INT_PTR CALLBACK OptionsDlgProc(
3333
{
3434
case WM_INITDIALOG:
3535
{
36-
PhCenterWindow(hwndDlg, GetParent(hwndDlg));
37-
3836
if (PhGetIntegerSetting(SETTING_NAME_AUTO_CHECK))
3937
Button_SetCheck(GetDlgItem(hwndDlg, IDC_AUTOCHECKBOX), BST_CHECKED);
4038
}
@@ -114,4 +112,4 @@ INT_PTR CALLBACK TextDlgProc(
114112
}
115113

116114
return FALSE;
117-
}
115+
}

plugins/Updater/page1.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Process Hacker Plugins -
33
* Update Checker Plugin
44
*
5-
* Copyright (C) 2016 dmex
5+
* Copyright (C) 2016-2019 dmex
66
*
77
* This file is part of Process Hacker.
88
*
@@ -69,7 +69,7 @@ VOID ShowCheckForUpdatesDialog(
6969
config.hMainIcon = Context->IconLargeHandle;
7070
config.cxWidth = 200;
7171
config.pButtons = TaskDialogButtonArray;
72-
config.cButtons = ARRAYSIZE(TaskDialogButtonArray);
72+
config.cButtons = RTL_NUMBER_OF(TaskDialogButtonArray);
7373
config.pfCallback = CheckForUpdatesCallbackProc;
7474
config.lpCallbackData = (LONG_PTR)Context;
7575

@@ -78,5 +78,5 @@ VOID ShowCheckForUpdatesDialog(
7878
//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.";
7979
config.pszContent = L"Select \"check for updates\" to continue.\r\n";
8080

81-
SendMessage(Context->DialogHandle, TDM_NAVIGATE_PAGE, 0, (LPARAM)&config);
82-
}
81+
TaskDialogNavigatePage(Context->DialogHandle, &config);
82+
}

plugins/Updater/page2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Process Hacker Plugins -
33
* Update Checker Plugin
44
*
5-
* Copyright (C) 2016 dmex
5+
* Copyright (C) 2016-2019 dmex
66
*
77
* This file is part of Process Hacker.
88
*
@@ -66,5 +66,5 @@ VOID ShowCheckingForUpdatesDialog(
6666
config.pszWindowTitle = L"Process Hacker - Updater";
6767
config.pszMainInstruction = L"Checking for new releases...";
6868

69-
SendMessage(Context->DialogHandle, TDM_NAVIGATE_PAGE, 0, (LPARAM)&config);
69+
TaskDialogNavigatePage(Context->DialogHandle, &config);
7070
}

plugins/Updater/page3.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Process Hacker Plugins -
33
* Update Checker Plugin
44
*
5-
* Copyright (C) 2016 dmex
5+
* Copyright (C) 2016-2019 dmex
66
*
77
* This file is part of Process Hacker.
88
*
@@ -75,7 +75,7 @@ VOID ShowAvailableDialog(
7575
config.hMainIcon = Context->IconLargeHandle;
7676
config.cxWidth = 200;
7777
config.pButtons = TaskDialogButtonArray;
78-
config.cButtons = ARRAYSIZE(TaskDialogButtonArray);
78+
config.cButtons = RTL_NUMBER_OF(TaskDialogButtonArray);
7979
config.lpCallbackData = (LONG_PTR)Context;
8080
config.pfCallback = ShowAvailableCallbackProc;
8181

@@ -86,5 +86,5 @@ VOID ShowAvailableDialog(
8686
PhGetStringOrEmpty(Context->SetupFileLength)
8787
)->Buffer;
8888

89-
SendMessage(Context->DialogHandle, TDM_NAVIGATE_PAGE, 0, (LPARAM)&config);
90-
}
89+
TaskDialogNavigatePage(Context->DialogHandle, &config);
90+
}

plugins/Updater/page4.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Process Hacker Plugins -
33
* Update Checker Plugin
44
*
5-
* Copyright (C) 2016 dmex
5+
* Copyright (C) 2016-2019 dmex
66
*
77
* This file is part of Process Hacker.
88
*
@@ -73,5 +73,5 @@ VOID ShowProgressDialog(
7373
config.pszMainInstruction = PhaFormatString(L"Downloading update %s...", PhGetStringOrEmpty(Context->Version))->Buffer;
7474
config.pszContent = L"Downloaded: ~ of ~ (0%)\r\nSpeed: ~ KB/s";
7575

76-
SendMessage(Context->DialogHandle, TDM_NAVIGATE_PAGE, 0, (LPARAM)&config);
76+
TaskDialogNavigatePage(Context->DialogHandle, &config);
7777
}

plugins/Updater/page5.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Process Hacker Plugins -
33
* Update Checker Plugin
44
*
5-
* Copyright (C) 2016 dmex
5+
* Copyright (C) 2016-2019 dmex
66
*
77
* This file is part of Process Hacker.
88
*
@@ -196,13 +196,13 @@ VOID ShowUpdateInstallDialog(
196196
config.pfCallback = FinalTaskDialogCallbackProc;
197197
config.lpCallbackData = (LONG_PTR)Context;
198198
config.pButtons = TaskDialogButtonArray;
199-
config.cButtons = ARRAYSIZE(TaskDialogButtonArray);
199+
config.cButtons = RTL_NUMBER_OF(TaskDialogButtonArray);
200200

201201
config.pszWindowTitle = L"Process Hacker - Updater";
202202
config.pszMainInstruction = L"Ready to install update?";
203203
config.pszContent = L"The update has been successfully downloaded and verified.\r\n\r\nClick Install to continue.";
204204

205-
SendMessage(Context->DialogHandle, TDM_NAVIGATE_PAGE, 0, (LPARAM)&config);
205+
TaskDialogNavigatePage(Context->DialogHandle, &config);
206206
}
207207

208208
VOID ShowLatestVersionDialog(
@@ -226,7 +226,7 @@ VOID ShowLatestVersionDialog(
226226

227227
// HACK
228228
imageDosHeader = (PIMAGE_DOS_HEADER)NtCurrentPeb()->ImageBaseAddress;
229-
imageNtHeader = (PIMAGE_NT_HEADERS)PTR_ADD_OFFSET(imageDosHeader, (ULONG)imageDosHeader->e_lfanew);
229+
imageNtHeader = (PIMAGE_NT_HEADERS)PTR_ADD_OFFSET(imageDosHeader, imageDosHeader->e_lfanew);
230230
RtlSecondsSince1970ToTime(imageNtHeader->FileHeader.TimeDateStamp, &time);
231231
PhLargeIntegerToLocalSystemTime(&systemTime, &time);
232232

@@ -238,7 +238,7 @@ VOID ShowLatestVersionDialog(
238238
PhaFormatDateTime(&systemTime)->Buffer
239239
)->Buffer;
240240

241-
SendMessage(Context->DialogHandle, TDM_NAVIGATE_PAGE, 0, (LPARAM)&config);
241+
TaskDialogNavigatePage(Context->DialogHandle, &config);
242242
}
243243

244244
VOID ShowNewerVersionDialog(
@@ -263,7 +263,7 @@ VOID ShowNewerVersionDialog(
263263
PhGetStringOrEmpty(Context->CurrentVersionString)
264264
)->Buffer;
265265

266-
SendMessage(Context->DialogHandle, TDM_NAVIGATE_PAGE, 0, (LPARAM)&config);
266+
TaskDialogNavigatePage(Context->DialogHandle, &config);
267267
}
268268

269269
VOID ShowUpdateFailedDialog(
@@ -318,5 +318,5 @@ VOID ShowUpdateFailedDialog(
318318
config.pfCallback = FinalTaskDialogCallbackProc;
319319
config.lpCallbackData = (LONG_PTR)Context;
320320

321-
SendMessage(Context->DialogHandle, TDM_NAVIGATE_PAGE, 0, (LPARAM)&config);
321+
TaskDialogNavigatePage(Context->DialogHandle, &config);
322322
}

plugins/Updater/updater.c

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ NTSTATUS UpdateCheckThread(
452452

453453
if (!context->HaveData)
454454
{
455-
ShowUpdateFailedDialog(context, FALSE, FALSE);
455+
PostMessage(context->DialogHandle, PH_SHOWERROR, FALSE, FALSE);
456456

457457
PhDereferenceObject(context);
458458
PhDeleteAutoPool(&autoPool);
@@ -462,17 +462,17 @@ NTSTATUS UpdateCheckThread(
462462
if (context->CurrentVersion == context->LatestVersion)
463463
{
464464
// User is running the latest version
465-
ShowLatestVersionDialog(context);
465+
PostMessage(context->DialogHandle, PH_SHOWLATEST, 0, 0);
466466
}
467467
else if (context->CurrentVersion > context->LatestVersion)
468468
{
469469
// User is running a newer version
470-
ShowNewerVersionDialog(context);
470+
PostMessage(context->DialogHandle, PH_SHOWNEWEST, 0, 0);
471471
}
472472
else
473473
{
474474
// User is running an older version
475-
ShowAvailableDialog(context);
475+
PostMessage(context->DialogHandle, PH_SHOWUPDATE, 0, 0);
476476
}
477477

478478
PhDereferenceObject(context);
@@ -734,20 +734,20 @@ NTSTATUS UpdateDownloadThread(
734734
{
735735
if (downloadSuccess && hashSuccess && signatureSuccess)
736736
{
737-
ShowUpdateInstallDialog(context);
737+
PostMessage(context->DialogHandle, PH_SHOWINSTALL, 0, 0);
738738
}
739739
else if (downloadSuccess)
740740
{
741741
if (signatureSuccess)
742-
ShowUpdateFailedDialog(context, TRUE, FALSE);
742+
PostMessage(context->DialogHandle, PH_SHOWERROR, TRUE, FALSE);
743743
else if (hashSuccess)
744-
ShowUpdateFailedDialog(context, FALSE, TRUE);
744+
PostMessage(context->DialogHandle, PH_SHOWERROR, FALSE, TRUE);
745745
else
746-
ShowUpdateFailedDialog(context, FALSE, FALSE);
746+
PostMessage(context->DialogHandle, PH_SHOWERROR, FALSE, FALSE);
747747
}
748748
else
749749
{
750-
ShowUpdateFailedDialog(context, FALSE, FALSE);
750+
PostMessage(context->DialogHandle, PH_SHOWERROR, FALSE, FALSE);
751751
}
752752
}
753753

@@ -790,6 +790,31 @@ LRESULT CALLBACK TaskDialogSubclassProc(
790790
SetForegroundWindow(hwndDlg);
791791
}
792792
break;
793+
case PH_SHOWLATEST:
794+
{
795+
ShowLatestVersionDialog(context);
796+
}
797+
break;
798+
case PH_SHOWNEWEST:
799+
{
800+
ShowNewerVersionDialog(context);
801+
}
802+
break;
803+
case PH_SHOWUPDATE:
804+
{
805+
ShowAvailableDialog(context);
806+
}
807+
break;
808+
case PH_SHOWINSTALL:
809+
{
810+
ShowUpdateInstallDialog(context);
811+
}
812+
break;
813+
case PH_SHOWERROR:
814+
{
815+
ShowUpdateFailedDialog(context, (BOOLEAN)wParam, (BOOLEAN)lParam);
816+
}
817+
break;
793818
//case WM_PARENTNOTIFY:
794819
// {
795820
// if (wParam == WM_CREATE)

plugins/Updater/updater.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Process Hacker Plugins -
33
* Update Checker Plugin
44
*
5-
* Copyright (C) 2011-2017 dmex
5+
* Copyright (C) 2011-2019 dmex
66
*
77
* This file is part of Process Hacker.
88
*
@@ -37,8 +37,13 @@
3737

3838
#include "resource.h"
3939

40-
#define UPDATE_MENUITEM 1001
41-
#define PH_SHOWDIALOG (WM_APP + 501)
40+
#define UPDATE_MENUITEM 1001
41+
#define PH_SHOWDIALOG (WM_APP + 501)
42+
#define PH_SHOWLATEST (WM_APP + 502)
43+
#define PH_SHOWNEWEST (WM_APP + 503)
44+
#define PH_SHOWUPDATE (WM_APP + 504)
45+
#define PH_SHOWINSTALL (WM_APP + 505)
46+
#define PH_SHOWERROR (WM_APP + 506)
4247

4348
#define PLUGIN_NAME L"ProcessHacker.UpdateChecker"
4449
#define SETTING_NAME_AUTO_CHECK (PLUGIN_NAME L".PromptStart")
@@ -100,6 +105,12 @@ typedef struct _PH_UPDATER_CONTEXT
100105
PPH_STRING BuildMessage;
101106
} PH_UPDATER_CONTEXT, *PPH_UPDATER_CONTEXT;
102107

108+
// TDM_NAVIGATE_PAGE can not be called from other threads without comctl32.dll throwing access violations
109+
// after navigating to the page and you press keys such as ctrl, alt, home and insert. (dmex)
110+
#define TaskDialogNavigatePage(WindowHandle, Config) \
111+
assert(HandleToUlong(NtCurrentThreadId()) == GetWindowThreadProcessId(WindowHandle, NULL)); \
112+
SendMessage(WindowHandle, TDM_NAVIGATE_PAGE, 0, (LPARAM)Config);
113+
103114
VOID TaskDialogLinkClicked(
104115
_In_ PPH_UPDATER_CONTEXT Context
105116
);
@@ -230,4 +241,4 @@ VOID ShowLinkDialog(
230241
_In_ PPH_UPDATER_CONTEXT Context
231242
);
232243

233-
#endif
244+
#endif

plugins/Updater/verify.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Process Hacker Plugins -
33
* Update Checker Plugin
44
*
5-
* Copyright (C) 2016 dmex
5+
* Copyright (C) 2016-2019 dmex
66
*
77
* This file is part of Process Hacker.
88
*
@@ -52,7 +52,6 @@ PUPDATER_HASH_CONTEXT UpdaterInitializeHash(
5252
VOID
5353
)
5454
{
55-
BOOLEAN success = FALSE;
5655
ULONG querySize;
5756
PUPDATER_HASH_CONTEXT hashContext;
5857

@@ -255,4 +254,4 @@ VOID UpdaterDestroyHash(
255254
PhFree(Context->Hash);
256255

257256
PhFree(Context);
258-
}
257+
}

0 commit comments

Comments
 (0)