@@ -297,6 +297,9 @@ BOOLEAN ProcessTreeFilterCallback(
297
297
298
298
for (i = 0 ; i < serviceList -> Count ; i ++ )
299
299
{
300
+ PPH_STRING serviceFileName = NULL ;
301
+ PPH_STRING serviceBinaryPath = NULL ;
302
+
300
303
serviceItem = serviceList -> Items [i ];
301
304
302
305
if (!PhIsNullOrEmptyString (serviceItem -> Name ))
@@ -329,6 +332,36 @@ BOOLEAN ProcessTreeFilterCallback(
329
332
break ;
330
333
}
331
334
}
335
+
336
+ if (NT_SUCCESS (QueryServiceFileName (
337
+ & serviceItem -> Name -> sr ,
338
+ & serviceFileName ,
339
+ & serviceBinaryPath
340
+ )))
341
+ {
342
+ if (serviceFileName )
343
+ {
344
+ if (WordMatchStringRef (& serviceFileName -> sr ))
345
+ {
346
+ matched = TRUE;
347
+ }
348
+
349
+ PhDereferenceObject (serviceFileName );
350
+ }
351
+
352
+ if (serviceBinaryPath )
353
+ {
354
+ if (WordMatchStringRef (& serviceBinaryPath -> sr ))
355
+ {
356
+ matched = TRUE;
357
+ }
358
+
359
+ PhDereferenceObject (serviceBinaryPath );
360
+ }
361
+
362
+ if (matched )
363
+ break ;
364
+ }
332
365
}
333
366
334
367
PhDereferenceObjects (serviceList -> Items , serviceList -> Count );
@@ -347,6 +380,8 @@ BOOLEAN ServiceTreeFilterCallback(
347
380
)
348
381
{
349
382
PPH_SERVICE_NODE serviceNode = (PPH_SERVICE_NODE )Node ;
383
+ PPH_STRING serviceFileName = NULL ;
384
+ PPH_STRING serviceBinaryPath = NULL ;
350
385
351
386
if (PhIsNullOrEmptyString (SearchboxText ))
352
387
return TRUE;
@@ -385,6 +420,38 @@ BOOLEAN ServiceTreeFilterCallback(
385
420
return TRUE;
386
421
}
387
422
423
+ if (NT_SUCCESS (QueryServiceFileName (
424
+ & serviceNode -> ServiceItem -> Name -> sr ,
425
+ & serviceFileName ,
426
+ & serviceBinaryPath
427
+ )))
428
+ {
429
+ BOOLEAN matched = FALSE;
430
+
431
+ if (serviceFileName )
432
+ {
433
+ if (WordMatchStringRef (& serviceFileName -> sr ))
434
+ {
435
+ matched = TRUE;
436
+ }
437
+
438
+ PhDereferenceObject (serviceFileName );
439
+ }
440
+
441
+ if (serviceBinaryPath )
442
+ {
443
+ if (WordMatchStringRef (& serviceBinaryPath -> sr ))
444
+ {
445
+ matched = TRUE;
446
+ }
447
+
448
+ PhDereferenceObject (serviceBinaryPath );
449
+ }
450
+
451
+ if (matched )
452
+ return TRUE;
453
+ }
454
+
388
455
return FALSE;
389
456
}
390
457
@@ -464,4 +531,114 @@ BOOLEAN NetworkTreeFilterCallback(
464
531
}
465
532
466
533
return FALSE;
467
- }
534
+ }
535
+
536
+ // NOTE: This function does not use the SCM due to major performance issues.
537
+ // For now we just query this information from the registry but it might be out-of-sync
538
+ // until the SCM flushes its cache.
539
+ NTSTATUS QueryServiceFileName (
540
+ _In_ PPH_STRINGREF ServiceName ,
541
+ _Out_ PPH_STRING * ServiceFileName ,
542
+ _Out_ PPH_STRING * ServiceBinaryPath
543
+ )
544
+ {
545
+ static PH_STRINGREF servicesKeyName = PH_STRINGREF_INIT (L"System\\CurrentControlSet\\Services\\" );
546
+ static PH_STRINGREF typeKeyName = PH_STRINGREF_INIT (L"Type" );
547
+
548
+ NTSTATUS status ;
549
+ HANDLE keyHandle ;
550
+ ULONG serviceType ;
551
+ PPH_STRING keyName ;
552
+ PPH_STRING binaryPath ;
553
+ PPH_STRING fileName ;
554
+
555
+ keyName = PhConcatStringRef2 (& servicesKeyName , ServiceName );
556
+ binaryPath = NULL ;
557
+ fileName = NULL ;
558
+
559
+ if (NT_SUCCESS (status = PhOpenKey (
560
+ & keyHandle ,
561
+ KEY_READ ,
562
+ PH_KEY_LOCAL_MACHINE ,
563
+ & keyName -> sr ,
564
+ 0
565
+ )))
566
+ {
567
+ PPH_STRING serviceImagePath ;
568
+ PKEY_VALUE_PARTIAL_INFORMATION buffer ;
569
+
570
+ if (NT_SUCCESS (status = PhQueryValueKey (
571
+ keyHandle ,
572
+ & typeKeyName ,
573
+ KeyValuePartialInformation ,
574
+ & buffer
575
+ )))
576
+ {
577
+ if (
578
+ buffer -> Type == REG_DWORD &&
579
+ buffer -> DataLength == sizeof (ULONG )
580
+ )
581
+ {
582
+ serviceType = * (PULONG )buffer -> Data ;
583
+ }
584
+
585
+ PhFree (buffer );
586
+ }
587
+
588
+ if (serviceImagePath = PhQueryRegistryString (keyHandle , L"ImagePath" ))
589
+ {
590
+ PPH_STRING expandedString ;
591
+
592
+ if (expandedString = PhExpandEnvironmentStrings (& serviceImagePath -> sr ))
593
+ {
594
+ binaryPath = expandedString ;
595
+ PhDereferenceObject (serviceImagePath );
596
+ }
597
+ else
598
+ {
599
+ binaryPath = serviceImagePath ;
600
+ }
601
+ }
602
+ else
603
+ {
604
+ status = STATUS_NOT_FOUND ;
605
+ }
606
+
607
+ NtClose (keyHandle );
608
+ }
609
+
610
+ if (NT_SUCCESS (status ))
611
+ {
612
+ PhGetServiceDllParameter (ServiceName , & fileName );
613
+
614
+ if (!fileName )
615
+ {
616
+ if (serviceType & SERVICE_WIN32 )
617
+ {
618
+ PH_STRINGREF dummyFileName ;
619
+ PH_STRINGREF dummyArguments ;
620
+
621
+ PhParseCommandLineFuzzy (& binaryPath -> sr , & dummyFileName , & dummyArguments , & fileName );
622
+
623
+ if (!fileName )
624
+ PhSwapReference (& fileName , binaryPath );
625
+ }
626
+ else
627
+ {
628
+ fileName = PhGetFileName (binaryPath );
629
+ }
630
+ }
631
+
632
+ * ServiceFileName = fileName ;
633
+ * ServiceBinaryPath = binaryPath ;
634
+ }
635
+ else
636
+ {
637
+ if (binaryPath )
638
+ PhDereferenceObject (binaryPath );
639
+ }
640
+
641
+ PhDereferenceObject (keyName );
642
+
643
+ return status ;
644
+ }
0 commit comments