Skip to content

Commit 8da145e

Browse files
committed
Load default plugins before non-default plugins
1 parent 532163d commit 8da145e

File tree

1 file changed

+46
-66
lines changed

1 file changed

+46
-66
lines changed

ProcessHacker/plugin.c

Lines changed: 46 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* plugin support
44
*
55
* Copyright (C) 2010-2015 wj32
6-
* Copyright (C) 2017-2021 dmex
6+
* Copyright (C) 2017-2022 dmex
77
*
88
* This file is part of Process Hacker.
99
*
@@ -61,6 +61,20 @@ VOID PhpExecuteCallbackForAllPlugins(
6161
PH_AVL_TREE PhPluginsByName = PH_AVL_TREE_INIT(PhpPluginsCompareFunction);
6262
static PH_CALLBACK GeneralCallbacks[GeneralCallbackMaximum];
6363
static ULONG NextPluginId = IDPLUGINS + 1;
64+
static PH_STRINGREF PhpDefaultPluginName[] =
65+
{
66+
PH_STRINGREF_INIT(L"DotNetTools.dll"),
67+
PH_STRINGREF_INIT(L"ExtendedNotifications.dll"),
68+
PH_STRINGREF_INIT(L"ExtendedServices.dll"),
69+
PH_STRINGREF_INIT(L"ExtendedTools.dll"),
70+
PH_STRINGREF_INIT(L"HardwareDevices.dll"),
71+
PH_STRINGREF_INIT(L"NetworkTools.dll"),
72+
PH_STRINGREF_INIT(L"OnlineChecks.dll"),
73+
PH_STRINGREF_INIT(L"ToolStatus.dll"),
74+
PH_STRINGREF_INIT(L"Updater.dll"),
75+
PH_STRINGREF_INIT(L"UserNotes.dll"),
76+
PH_STRINGREF_INIT(L"WindowExplorer.dll"),
77+
};
6478

6579
INT NTAPI PhpPluginsCompareFunction(
6680
_In_ PPH_AVL_LINKS Links1,
@@ -322,6 +336,12 @@ static BOOLEAN EnumPluginsDirectoryCallback(
322336
if (!PhEndsWithStringRef(&baseName, &PhpPluginExtension, FALSE))
323337
return TRUE;
324338

339+
for (ULONG i = 0; i < RTL_NUMBER_OF(PhpDefaultPluginName); i++)
340+
{
341+
if (PhEqualStringRef(&baseName, &PhpDefaultPluginName[i], TRUE))
342+
return TRUE;
343+
}
344+
325345
if (!(directoryName = PhpGetPluginDirectoryPath()))
326346
return TRUE;
327347

@@ -439,7 +459,8 @@ VOID PhLoadPlugins(
439459
VOID
440460
)
441461
{
442-
ULONG i;
462+
NTSTATUS status;
463+
PPH_STRING fileName;
443464
PPH_STRING pluginsDirectory;
444465
PPH_LIST pluginLoadErrors;
445466

@@ -448,58 +469,34 @@ VOID PhLoadPlugins(
448469

449470
pluginLoadErrors = PhCreateList(1);
450471

451-
if (PhGetIntegerSetting(L"EnableSafeDefaultPlugins"))
472+
for (ULONG i = 0; i < RTL_NUMBER_OF(PhpDefaultPluginName); i++)
452473
{
453-
static PH_STRINGREF PhpDefaultPluginName[] =
474+
if (fileName = PhConcatStringRef2(&pluginsDirectory->sr, &PhpDefaultPluginName[i]))
454475
{
455-
PH_STRINGREF_INIT(L"DotNetTools.dll"),
456-
PH_STRINGREF_INIT(L"ExtendedNotifications.dll"),
457-
PH_STRINGREF_INIT(L"ExtendedServices.dll"),
458-
PH_STRINGREF_INIT(L"ExtendedTools.dll"),
459-
PH_STRINGREF_INIT(L"HardwareDevices.dll"),
460-
PH_STRINGREF_INIT(L"NetworkTools.dll"),
461-
PH_STRINGREF_INIT(L"OnlineChecks.dll"),
462-
PH_STRINGREF_INIT(L"ToolStatus.dll"),
463-
PH_STRINGREF_INIT(L"Updater.dll"),
464-
PH_STRINGREF_INIT(L"UserNotes.dll"),
465-
PH_STRINGREF_INIT(L"WindowExplorer.dll"),
466-
};
467-
PPH_STRING fileName;
468-
NTSTATUS status;
476+
status = PhLoadPlugin(fileName);
469477

470-
for (i = 0; i < RTL_NUMBER_OF(PhpDefaultPluginName); i++)
471-
{
472-
if (fileName = PhConcatStringRef2(&pluginsDirectory->sr, &PhpDefaultPluginName[i]))
478+
if (!NT_SUCCESS(status))
473479
{
474-
status = PhLoadPlugin(fileName);
475-
476-
if (!NT_SUCCESS(status))
477-
{
478-
PPHP_PLUGIN_LOAD_ERROR loadError;
479-
PPH_STRING errorMessage;
480+
PPHP_PLUGIN_LOAD_ERROR loadError;
481+
PPH_STRING errorMessage;
480482

481-
loadError = PhAllocateZero(sizeof(PHP_PLUGIN_LOAD_ERROR));
482-
PhSetReference(&loadError->FileName, fileName);
483+
loadError = PhAllocateZero(sizeof(PHP_PLUGIN_LOAD_ERROR));
484+
PhSetReference(&loadError->FileName, fileName);
483485

484-
if (errorMessage = PhGetNtMessage(status))
485-
{
486-
PhSetReference(&loadError->ErrorMessage, errorMessage);
487-
PhDereferenceObject(errorMessage);
488-
}
489-
490-
PhAddItemList(pluginLoadErrors, loadError);
486+
if (errorMessage = PhGetNtMessage(status))
487+
{
488+
PhSetReference(&loadError->ErrorMessage, errorMessage);
489+
PhDereferenceObject(errorMessage);
491490
}
492491

493-
PhDereferenceObject(fileName);
492+
PhAddItemList(pluginLoadErrors, loadError);
494493
}
495-
}
496494

497-
if (pluginLoadErrors->Count != 0 && !PhStartupParameters.PhSvc)
498-
{
499-
PhpShowPluginErrorMessage(pluginLoadErrors);
495+
PhDereferenceObject(fileName);
500496
}
501497
}
502-
else
498+
499+
if (!PhGetIntegerSetting(L"EnableSafeDefaultPlugins"))
503500
{
504501
HANDLE pluginsDirectoryHandle;
505502

@@ -539,13 +536,13 @@ VOID PhLoadPlugins(
539536

540537
NtClose(pluginsDirectoryHandle);
541538
}
539+
}
542540

543-
// Handle load errors.
544-
// In certain startup modes we want to ignore all plugin load errors.
545-
if (PhGetIntegerSetting(L"ShowPluginLoadErrors") && pluginLoadErrors->Count != 0 && !PhStartupParameters.PhSvc)
546-
{
547-
PhpShowPluginErrorMessage(pluginLoadErrors);
548-
}
541+
// Handle load errors.
542+
// In certain startup modes we want to ignore all plugin load errors.
543+
if (PhGetIntegerSetting(L"ShowPluginLoadErrors") && pluginLoadErrors->Count != 0 && !PhStartupParameters.PhSvc)
544+
{
545+
PhpShowPluginErrorMessage(pluginLoadErrors);
549546
}
550547

551548
// When we loaded settings before, we didn't know about plugin settings, so they
@@ -557,7 +554,7 @@ VOID PhLoadPlugins(
557554

558555
PhpExecuteCallbackForAllPlugins(PluginCallbackLoad, TRUE);
559556

560-
for (i = 0; i < pluginLoadErrors->Count; i++)
557+
for (ULONG i = 0; i < pluginLoadErrors->Count; i++)
561558
{
562559
PPHP_PLUGIN_LOAD_ERROR loadError;
563560

@@ -594,23 +591,6 @@ NTSTATUS PhLoadPlugin(
594591
_In_ PPH_STRING FileName
595592
)
596593
{
597-
//NTSTATUS status;
598-
//PPH_STRING fileName;
599-
//
600-
//status = PhGetFullPathEx(
601-
// FileName->Buffer,
602-
// NULL,
603-
// &fileName
604-
// );
605-
//
606-
//if (NT_SUCCESS(status))
607-
//{
608-
// status = PhLoadPluginImage(fileName, NULL);
609-
//
610-
// PhDereferenceObject(fileName);
611-
//}
612-
//
613-
//return status;
614594
return PhLoadPluginImage(FileName, NULL);
615595
}
616596

0 commit comments

Comments
 (0)