Skip to content

Commit c47791f

Browse files
committed
Add tray notifications and logging for modified services
1 parent e195256 commit c47791f

File tree

7 files changed

+71
-9
lines changed

7 files changed

+71
-9
lines changed

ProcessHacker/include/mainwnd.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,9 @@ typedef struct _PH_MAIN_TAB_PAGE
215215
#define PH_NOTIFY_SERVICE_DELETE 0x8
216216
#define PH_NOTIFY_SERVICE_START 0x10
217217
#define PH_NOTIFY_SERVICE_STOP 0x20
218-
#define PH_NOTIFY_MAXIMUM 0x40
219-
#define PH_NOTIFY_VALID_MASK 0x3f
218+
#define PH_NOTIFY_SERVICE_MODIFIED 0x40
219+
#define PH_NOTIFY_MAXIMUM 0x80
220+
#define PH_NOTIFY_VALID_MASK 0x7f
220221
// end_phapppub
221222

222223
BOOLEAN PhMainWndInitialization(

ProcessHacker/include/phapp.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,10 @@ struct _PH_PLUGIN *PhFindPlugin2(
161161
#define PH_LOG_ENTRY_SERVICE_STOP 6
162162
#define PH_LOG_ENTRY_SERVICE_CONTINUE 7
163163
#define PH_LOG_ENTRY_SERVICE_PAUSE 8
164-
#define PH_LOG_ENTRY_SERVICE_LAST 8
164+
#define PH_LOG_ENTRY_SERVICE_MODIFIED 9
165+
#define PH_LOG_ENTRY_SERVICE_LAST 10
165166

166-
#define PH_LOG_ENTRY_MESSAGE 9 // phapppub
167+
#define PH_LOG_ENTRY_MESSAGE 100 // phapppub
167168

168169
typedef struct _PH_LOG_ENTRY *PPH_LOG_ENTRY; // phapppub
169170

ProcessHacker/log.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,24 @@ PPH_STRING PhFormatLogEntry(
383383
// );
384384
return PhpFormatLogEntryToBuffer(format, RTL_NUMBER_OF(format));
385385
}
386+
case PH_LOG_ENTRY_SERVICE_MODIFIED:
387+
{
388+
PH_FORMAT format[5];
389+
390+
// Service modified: %s (%s)
391+
PhInitFormatS(&format[0], L"Service modified: ");
392+
PhInitFormatSR(&format[1], Entry->Service.Name->sr);
393+
PhInitFormatS(&format[2], L" (");
394+
PhInitFormatSR(&format[3], Entry->Service.DisplayName->sr);
395+
PhInitFormatC(&format[4], L')');
396+
397+
//return PhFormatString(
398+
// L"Service modified: %s (%s)",
399+
// Entry->Service.Name->Buffer,
400+
// Entry->Service.DisplayName->Buffer
401+
// );
402+
return PhpFormatLogEntryToBuffer(format, RTL_NUMBER_OF(format));
403+
}
386404
case PH_LOG_ENTRY_MESSAGE:
387405
PhReferenceObject(Entry->Message);
388406
return Entry->Message;

ProcessHacker/mainwnd.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,7 @@ VOID PhMwpOnCommand(
765765
case ID_NOTIFICATIONS_STARTEDSERVICES:
766766
case ID_NOTIFICATIONS_STOPPEDSERVICES:
767767
case ID_NOTIFICATIONS_DELETEDSERVICES:
768+
case ID_NOTIFICATIONS_MODIFIEDSERVICES:
768769
{
769770
PhMwpExecuteNotificationMenuCommand(WindowHandle, Id);
770771
}
@@ -2637,6 +2638,7 @@ PPH_EMENU PhpCreateNotificationMenu(
26372638
PhInsertEMenuItem(menuItem, PhCreateEMenuItem(0, ID_NOTIFICATIONS_STARTEDSERVICES, L"St&arted services", NULL, NULL), ULONG_MAX);
26382639
PhInsertEMenuItem(menuItem, PhCreateEMenuItem(0, ID_NOTIFICATIONS_STOPPEDSERVICES, L"St&opped services", NULL, NULL), ULONG_MAX);
26392640
PhInsertEMenuItem(menuItem, PhCreateEMenuItem(0, ID_NOTIFICATIONS_DELETEDSERVICES, L"&Deleted services", NULL, NULL), ULONG_MAX);
2641+
PhInsertEMenuItem(menuItem, PhCreateEMenuItem(0, ID_NOTIFICATIONS_MODIFIEDSERVICES, L"&Modified services", NULL, NULL), ULONG_MAX);
26402642

26412643
for (i = PH_NOTIFY_MINIMUM; i != PH_NOTIFY_MAXIMUM; i <<= 1)
26422644
{
@@ -2662,6 +2664,9 @@ PPH_EMENU PhpCreateNotificationMenu(
26622664
case PH_NOTIFY_SERVICE_STOP:
26632665
id = ID_NOTIFICATIONS_STOPPEDSERVICES;
26642666
break;
2667+
case PH_NOTIFY_SERVICE_MODIFIED:
2668+
id = ID_NOTIFICATIONS_MODIFIEDSERVICES;
2669+
break;
26652670
}
26662671

26672672
PhSetFlagsEMenuItem(menuItem, id, PH_EMENU_CHECKED, PH_EMENU_CHECKED);
@@ -2690,6 +2695,7 @@ BOOLEAN PhMwpExecuteNotificationMenuCommand(
26902695
case ID_NOTIFICATIONS_STARTEDSERVICES:
26912696
case ID_NOTIFICATIONS_STOPPEDSERVICES:
26922697
case ID_NOTIFICATIONS_DELETEDSERVICES:
2698+
case ID_NOTIFICATIONS_MODIFIEDSERVICES:
26932699
{
26942700
ULONG bit;
26952701

@@ -2713,6 +2719,9 @@ BOOLEAN PhMwpExecuteNotificationMenuCommand(
27132719
case ID_NOTIFICATIONS_DELETEDSERVICES:
27142720
bit = PH_NOTIFY_SERVICE_DELETE;
27152721
break;
2722+
case ID_NOTIFICATIONS_MODIFIEDSERVICES:
2723+
bit = PH_NOTIFY_SERVICE_MODIFIED;
2724+
break;
27162725
}
27172726

27182727
PhMwpNotifyIconNotifyMask ^= bit;

ProcessHacker/mwpgsrv.c

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Main window: Services tab
44
*
55
* Copyright (C) 2009-2016 wj32
6-
* Copyright (C) 2017-2020 dmex
6+
* Copyright (C) 2017-2021 dmex
77
*
88
* This file is part of Process Hacker.
99
*
@@ -501,7 +501,8 @@ VOID PhMwpOnServiceAdded(
501501
}
502502

503503
VOID PhMwpOnServiceModified(
504-
_In_ PPH_SERVICE_MODIFIED_DATA ServiceModifiedData
504+
_In_ PPH_SERVICE_MODIFIED_DATA ServiceModifiedData,
505+
_In_ ULONG RunId
505506
)
506507
{
507508
PH_SERVICE_CHANGE serviceChange;
@@ -529,14 +530,15 @@ VOID PhMwpOnServiceModified(
529530
logEntryType = PH_LOG_ENTRY_SERVICE_PAUSE;
530531
break;
531532
default:
532-
logEntryType = 0;
533+
// HACK: We can't use JustProcessed here, so use the RunId instead. (dmex)
534+
logEntryType = (RunId && RunId > 2) ? PH_LOG_ENTRY_SERVICE_MODIFIED : 0;
533535
break;
534536
}
535537

536538
if (logEntryType != 0)
537539
PhLogServiceEntry(logEntryType, ServiceModifiedData->Service->Name, ServiceModifiedData->Service->DisplayName);
538540

539-
if (PhMwpNotifyIconNotifyMask & (PH_NOTIFY_SERVICE_START | PH_NOTIFY_SERVICE_STOP))
541+
if (PhMwpNotifyIconNotifyMask & (PH_NOTIFY_SERVICE_START | PH_NOTIFY_SERVICE_STOP | PH_NOTIFY_SERVICE_MODIFIED))
540542
{
541543
PPH_SERVICE_ITEM serviceItem;
542544

@@ -600,6 +602,35 @@ VOID PhMwpOnServiceModified(
600602
}
601603
}
602604
}
605+
else if (serviceChange == -1 && PhMwpNotifyIconNotifyMask & PH_NOTIFY_SERVICE_MODIFIED && (RunId && RunId > 2))
606+
{
607+
if (!PhPluginsEnabled || !PhMwpPluginNotifyEvent(PH_NOTIFY_SERVICE_MODIFIED, serviceItem))
608+
{
609+
PH_FORMAT format[5];
610+
WCHAR formatBuffer[260];
611+
612+
PhMwpClearLastNotificationDetails();
613+
PhMwpLastNotificationType = PH_NOTIFY_SERVICE_MODIFIED;
614+
PhSwapReference(&PhMwpLastNotificationDetails.ServiceName, serviceItem->Name);
615+
616+
// The service %s (%s) has been modified.
617+
PhInitFormatS(&format[0], L"The service ");
618+
PhInitFormatSR(&format[1], serviceItem->Name->sr);
619+
PhInitFormatS(&format[2], L" (");
620+
PhInitFormatSR(&format[3], serviceItem->DisplayName->sr);
621+
PhInitFormatS(&format[4], L") was modified");
622+
623+
if (PhFormatToBuffer(format, RTL_NUMBER_OF(format), formatBuffer, sizeof(formatBuffer), NULL))
624+
{
625+
PhShowIconNotification(L"Service modified", formatBuffer);
626+
}
627+
else
628+
{
629+
PhShowIconNotification(L"Service modified",
630+
PH_AUTO_T(PH_STRING, PhFormat(format, RTL_NUMBER_OF(format), 0))->Buffer);
631+
}
632+
}
633+
}
603634
}
604635
}
605636

@@ -667,7 +698,7 @@ VOID PhMwpOnServicesUpdated(
667698
PhMwpOnServiceAdded(serviceItem, events[i].RunId);
668699
break;
669700
case ProviderModifiedEvent:
670-
PhMwpOnServiceModified((PPH_SERVICE_MODIFIED_DATA)serviceItem);
701+
PhMwpOnServiceModified((PPH_SERVICE_MODIFIED_DATA)serviceItem, events[i].RunId);
671702
break;
672703
case ProviderRemovedEvent:
673704
PhMwpOnServiceRemoved(serviceItem);

ProcessHacker/resource.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@
680680
#define ID_NOTIFICATIONS_STARTEDSERVICES 40183
681681
#define ID_NOTIFICATIONS_STOPPEDSERVICES 40184
682682
#define ID_NOTIFICATIONS_DELETEDSERVICES 40185
683+
#define ID_NOTIFICATIONS_MODIFIEDSERVICES 40186
683684
#define ID_MISCELLANEOUS_GDIHANDLES 40188
684685
#define ID_MISCELLANEOUS_HEAPS 40189
685686
#define ID_ESC_EXIT 40190

plugins/ExtendedNotifications/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ VOID NTAPI NotifyEventCallback(
396396
case PH_NOTIFY_SERVICE_DELETE:
397397
case PH_NOTIFY_SERVICE_START:
398398
case PH_NOTIFY_SERVICE_STOP:
399+
case PH_NOTIFY_SERVICE_MODIFIED:
399400
serviceItem = notifyEvent->Parameter;
400401

401402
MatchFilterList(ServiceFilterList, serviceItem->Name, &filterType);

0 commit comments

Comments
 (0)