Process Hacker
providers.h
Go to the documentation of this file.
1 #ifndef PH_PROVIDERS_H
2 #define PH_PROVIDERS_H
3 
4 // procprv
5 
6 #define PH_RECORD_MAX_USAGE
7 #define PH_ENABLE_VERIFY_CACHE
8 
10 
11 PHAPPAPI extern PH_CALLBACK PhProcessAddedEvent; // phapppub
13 PHAPPAPI extern PH_CALLBACK PhProcessRemovedEvent; // phapppub
15 
18 
19 extern ULONG PhStatisticsSampleCount;
20 extern BOOLEAN PhEnableProcessQueryStage2;
21 extern BOOLEAN PhEnablePurgeProcessRecords;
22 extern BOOLEAN PhEnableCycleCpuUsage;
23 
24 extern PVOID PhProcessInformation; // only can be used if running on same thread as process provider
29 extern ULONG PhTotalProcesses;
30 extern ULONG PhTotalThreads;
31 extern ULONG PhTotalHandles;
32 
33 extern ULONG64 PhCpuTotalCycleDelta;
34 extern PLARGE_INTEGER PhCpuIdleCycleTime; // cycle time for Idle
35 extern PLARGE_INTEGER PhCpuSystemCycleTime; // cycle time for DPCs and Interrupts
38 
39 extern FLOAT PhCpuKernelUsage;
40 extern FLOAT PhCpuUserUsage;
41 extern PFLOAT PhCpusKernelUsage;
42 extern PFLOAT PhCpusUserUsage;
43 
47 
51 
55 
56 extern PH_CIRCULAR_BUFFER_FLOAT PhCpuKernelHistory;
57 extern PH_CIRCULAR_BUFFER_FLOAT PhCpuUserHistory;
58 //extern PH_CIRCULAR_BUFFER_FLOAT PhCpuOtherHistory;
59 
60 extern PPH_CIRCULAR_BUFFER_FLOAT PhCpusKernelHistory;
61 extern PPH_CIRCULAR_BUFFER_FLOAT PhCpusUserHistory;
62 //extern PPH_CIRCULAR_BUFFER_FLOAT PhCpusOtherHistory;
63 
64 extern PH_CIRCULAR_BUFFER_ULONG64 PhIoReadHistory;
65 extern PH_CIRCULAR_BUFFER_ULONG64 PhIoWriteHistory;
66 extern PH_CIRCULAR_BUFFER_ULONG64 PhIoOtherHistory;
67 
68 extern PH_CIRCULAR_BUFFER_ULONG PhCommitHistory;
69 extern PH_CIRCULAR_BUFFER_ULONG PhPhysicalHistory;
70 
71 extern PH_CIRCULAR_BUFFER_ULONG PhMaxCpuHistory;
72 extern PH_CIRCULAR_BUFFER_ULONG PhMaxIoHistory;
73 #ifdef PH_RECORD_MAX_USAGE
74 extern PH_CIRCULAR_BUFFER_FLOAT PhMaxCpuUsageHistory;
75 extern PH_CIRCULAR_BUFFER_ULONG64 PhMaxIoReadOtherHistory;
76 extern PH_CIRCULAR_BUFFER_ULONG64 PhMaxIoWriteHistory;
77 #endif
78 
79 // begin_phapppub
80 #define DPCS_PROCESS_ID ((HANDLE)(LONG_PTR)-2)
81 #define INTERRUPTS_PROCESS_ID ((HANDLE)(LONG_PTR)-3)
82 
83 // DPCs, Interrupts and System Idle Process are not real.
84 // Non-"real" processes can never be opened.
85 #define PH_IS_REAL_PROCESS_ID(ProcessId) ((LONG_PTR)(ProcessId) > 0)
86 
87 // DPCs and Interrupts are fake, but System Idle Process is not.
88 #define PH_IS_FAKE_PROCESS_ID(ProcessId) ((LONG_PTR)(ProcessId) < 0)
89 
90 // The process item has been removed.
91 #define PH_PROCESS_ITEM_REMOVED 0x1
92 // end_phapppub
93 
94 #define PH_INTEGRITY_STR_LEN 10
95 #define PH_INTEGRITY_STR_LEN_1 (PH_INTEGRITY_STR_LEN + 1)
96 
97 // begin_phapppub
100 
101 typedef struct _PH_PROCESS_ITEM
102 {
104  ULONG State;
105  PPH_PROCESS_RECORD Record;
106 
107  // Basic
108 
109  HANDLE ProcessId;
112  ULONG SessionId;
113 
114  LARGE_INTEGER CreateTime;
115 
116  // Handles
117 
118  HANDLE QueryHandle;
119 
120  // Parameters
121 
124 
125  // File
126 
127  HICON SmallIcon;
128  HICON LargeIcon;
130 
131  // Security
132 
134  TOKEN_ELEVATION_TYPE ElevationType;
135  MANDATORY_LEVEL IntegrityLevel;
137 
138  // Other
139 
142 
143  // Signature, Packed
144 
149 
150  // Flags
151 
152  union
153  {
154  ULONG Flags;
155  struct
156  {
157  ULONG UpdateIsDotNet : 1;
158  ULONG IsBeingDebugged : 1;
159  ULONG IsDotNet : 1;
160  ULONG IsElevated : 1;
161  ULONG IsInJob : 1;
163  ULONG IsPacked : 1;
164  ULONG IsPosix : 1;
165  ULONG IsSuspended : 1;
166  ULONG IsWow64 : 1;
167  ULONG IsImmersive : 1;
168  ULONG IsWow64Valid : 1;
170  ULONG AddedEventSent : 1;
171  ULONG Spare : 18;
172  };
173  };
174 
175  // Misc.
176 
179 
182 
186 
187  // Dynamic
188 
191  LARGE_INTEGER KernelTime;
192  LARGE_INTEGER UserTime;
195 
196  FLOAT CpuUsage; // Below Windows 7, sum of kernel and user CPU usage; above Windows 7, cycle-based CPU usage.
199 
211 
212  VM_COUNTERS_EX VmCounters;
213  IO_COUNTERS IoCounters;
214  SIZE_T WorkingSetPrivateSize; // since VISTA
215  ULONG PeakNumberOfThreads; // since WIN7
216  ULONG HardFaultCount; // since WIN7
217 
219  PH_CIRCULAR_BUFFER_FLOAT CpuKernelHistory;
220  PH_CIRCULAR_BUFFER_FLOAT CpuUserHistory;
221  PH_CIRCULAR_BUFFER_ULONG64 IoReadHistory;
222  PH_CIRCULAR_BUFFER_ULONG64 IoWriteHistory;
223  PH_CIRCULAR_BUFFER_ULONG64 IoOtherHistory;
224  PH_CIRCULAR_BUFFER_SIZE_T PrivateBytesHistory;
225  //PH_CIRCULAR_BUFFER_SIZE_T WorkingSetHistory;
226 
227  // New fields
231 // end_phapppub
232 
233 // begin_phapppub
234 // The process itself is dead.
235 #define PH_PROCESS_RECORD_DEAD 0x1
236 // An extra reference has been added to the process record for the statistics system.
237 #define PH_PROCESS_RECORD_STAT_REF 0x2
238 
239 typedef struct _PH_PROCESS_RECORD
240 {
241  LIST_ENTRY ListEntry;
243  ULONG Flags;
244 
245  HANDLE ProcessId;
247  ULONG SessionId;
248  LARGE_INTEGER CreateTime;
249  LARGE_INTEGER ExitTime;
250 
254  /*PPH_STRING UserName;*/
256 // end_phapppub
257 
259  VOID
260  );
261 
262 // begin_phapppub
263 PHAPPAPI
265 NTAPI
267  _In_ PCLIENT_ID ClientId
268  );
269 
270 PHAPPAPI
272 NTAPI
274  _In_ PCLIENT_ID ClientId,
275  _In_opt_ PPH_STRING ProcessName
276  );
277 
278 PHAPPAPI
279 PWSTR
280 NTAPI
282  _In_ ULONG PriorityClass
283  );
284 // end_phapppub
285 
286 PPH_PROCESS_ITEM PhCreateProcessItem(
287  _In_ HANDLE ProcessId
288  );
289 
290 // begin_phapppub
291 PHAPPAPI
292 PPH_PROCESS_ITEM
293 NTAPI
295  _In_ HANDLE ProcessId
296  );
297 
298 PHAPPAPI
299 VOID
300 NTAPI
302  _Out_opt_ PPH_PROCESS_ITEM **ProcessItems,
303  _Out_ PULONG NumberOfProcessItems
304  );
305 // end_phapppub
306 
308 
310  _In_ PPH_VERIFY_FILE_INFO Information,
311  _In_opt_ PWSTR PackageFullName,
312  _Out_opt_ PPH_STRING *SignerName
313  );
314 
316  _In_ PPH_STRING FileName,
317  _In_opt_ PWSTR PackageFullName,
318  _Out_opt_ PPH_STRING *SignerName,
319  _In_ BOOLEAN CachedOnly
320  );
321 
322 // begin_phapppub
323 PHAPPAPI
324 BOOLEAN
325 NTAPI
327  _In_opt_ PPH_PROCESS_ITEM ProcessItem,
328  _In_ ULONG Index,
329  _Out_ PLARGE_INTEGER Time
330  );
331 
332 PHAPPAPI
334 NTAPI
336  _In_opt_ PPH_PROCESS_ITEM ProcessItem,
337  _In_ ULONG Index
338  );
339 // end_phapppub
340 
342  _In_ BOOLEAN SendModifiedEvent
343  );
344 
346  _In_ PVOID Object
347  );
348 
349 // begin_phapppub
350 PHAPPAPI
351 VOID
352 NTAPI
354  _In_ PPH_PROCESS_RECORD ProcessRecord
355  );
356 
357 PHAPPAPI
358 BOOLEAN
359 NTAPI
361  _In_ PPH_PROCESS_RECORD ProcessRecord
362  );
363 
364 PHAPPAPI
365 VOID
366 NTAPI
368  _In_ PPH_PROCESS_RECORD ProcessRecord
369  );
370 
371 PHAPPAPI
372 VOID
373 NTAPI
375  _In_ PPH_PROCESS_RECORD ProcessRecord
376  );
377 
378 PHAPPAPI
379 PPH_PROCESS_RECORD
380 NTAPI
382  _In_opt_ HANDLE ProcessId,
383  _In_ PLARGE_INTEGER Time
384  );
385 // end_phapppub
386 
388  VOID
389  );
390 
391 // begin_phapppub
392 PHAPPAPI
393 PPH_PROCESS_ITEM
394 NTAPI
396  _In_ HANDLE ParentProcessId,
397  _In_ HANDLE ProcessId,
398  _In_ PLARGE_INTEGER CreateTime
399  );
400 
401 PHAPPAPI
402 PPH_PROCESS_ITEM
403 NTAPI
405  _In_ PPH_PROCESS_RECORD Record
406  );
407 // end_phapppub
408 
409 // srvprv
410 
412 
413 PHAPPAPI extern PH_CALLBACK PhServiceAddedEvent; // phapppub
414 PHAPPAPI extern PH_CALLBACK PhServiceModifiedEvent; // phapppub
415 PHAPPAPI extern PH_CALLBACK PhServiceRemovedEvent; // phapppub
416 PHAPPAPI extern PH_CALLBACK PhServicesUpdatedEvent; // phapppub
417 
418 extern BOOLEAN PhEnableServiceNonPoll;
419 
420 // begin_phapppub
421 typedef struct _PH_SERVICE_ITEM
422 {
423  PH_STRINGREF Key; // points to Name
426 
427  // State
428  ULONG Type;
429  ULONG State;
431  ULONG Flags; // e.g. SERVICE_RUNS_IN_SYSTEM_PROCESS
432  HANDLE ProcessId;
433 
434  // Config
435  ULONG StartType;
437 // end_phapppub
438  BOOLEAN DelayedStart;
439  BOOLEAN HasTriggers;
440 
441  BOOLEAN PendingProcess;
443 
445 // begin_phapppub
447 // end_phapppub
448 
449 // begin_phapppub
451 {
452  PPH_SERVICE_ITEM Service;
455 
456 typedef enum _PH_SERVICE_CHANGE
457 {
463 // end_phapppub
464 
466  VOID
467  );
468 
469 PPH_SERVICE_ITEM PhCreateServiceItem(
470  _In_opt_ LPENUM_SERVICE_STATUS_PROCESS Information
471  );
472 
473 // begin_phapppub
474 PHAPPAPI
475 PPH_SERVICE_ITEM
476 NTAPI
478  _In_ PWSTR Name
479  );
480 // end_phapppub
481 
483  _In_ PPH_SERVICE_ITEM ServiceItem
484  );
485 
486 // begin_phapppub
487 PHAPPAPI
489 NTAPI
491  _In_ PPH_SERVICE_MODIFIED_DATA Data
492  );
493 // end_phapppub
494 
496  _In_ PPH_PROCESS_ITEM ProcessItem
497  );
498 
500  _In_ PVOID Object
501  );
502 
503 // netprv
504 
506 PHAPPAPI extern PH_CALLBACK PhNetworkItemAddedEvent; // phapppub
510 
511 extern BOOLEAN PhEnableNetworkProviderResolve;
512 
513 // begin_phapppub
514 #define PH_NETWORK_OWNER_INFO_SIZE 16
515 
516 typedef struct _PH_NETWORK_ITEM
517 {
521  ULONG State;
522  HANDLE ProcessId;
523 
525  HICON ProcessIcon;
528 
529  BOOLEAN JustResolved;
530 
537 
538  LARGE_INTEGER CreateTime;
541 // end_phapppub
542 
544  VOID
545  );
546 
547 PPH_NETWORK_ITEM PhCreateNetworkItem(
548  VOID
549  );
550 
551 // begin_phapppub
552 PHAPPAPI
553 PPH_NETWORK_ITEM
554 NTAPI
556  _In_ ULONG ProtocolType,
557  _In_ PPH_IP_ENDPOINT LocalEndpoint,
558  _In_ PPH_IP_ENDPOINT RemoteEndpoint,
559  _In_ HANDLE ProcessId
560  );
561 // end_phapppub
562 
564  _In_ PPH_IP_ADDRESS Address
565  );
566 
568  _In_ PVOID Object
569  );
570 
571 // begin_phapppub
572 PHAPPAPI
573 PWSTR
574 NTAPI
576  _In_ ULONG ProtocolType
577  );
578 
579 PHAPPAPI
580 PWSTR
581 NTAPI
583  _In_ ULONG State
584  );
585 // end_phapppub
586 
587 // modprv
588 
591 
592 // begin_phapppub
593 typedef struct _PH_MODULE_ITEM
594 {
595  PVOID BaseAddress;
596  ULONG Size;
597  ULONG Flags;
598  ULONG Type;
599  USHORT LoadReason;
600  USHORT LoadCount;
604 
606 
607  BOOLEAN IsFirst;
608  BOOLEAN JustProcessed;
609 
612 
616 
617  LARGE_INTEGER LoadTime;
619 
620 typedef struct _PH_MODULE_PROVIDER
621 {
628 
629  HANDLE ProcessId;
632  SLIST_HEADER QueryListHead;
633  NTSTATUS RunStatus;
635 // end_phapppub
636 
638  VOID
639  );
640 
641 PPH_MODULE_PROVIDER PhCreateModuleProvider(
642  _In_ HANDLE ProcessId
643  );
644 
645 PPH_MODULE_ITEM PhCreateModuleItem(
646  VOID
647  );
648 
649 PPH_MODULE_ITEM PhReferenceModuleItem(
650  _In_ PPH_MODULE_PROVIDER ModuleProvider,
651  _In_ PVOID BaseAddress
652  );
653 
655  _In_ PPH_MODULE_PROVIDER ModuleProvider
656  );
657 
659  _In_ PVOID Object
660  );
661 
662 // thrdprv
663 
666 
667 // begin_phapppub
668 typedef struct _PH_THREAD_ITEM
669 {
670  HANDLE ThreadId;
671 
672  LARGE_INTEGER CreateTime;
673  LARGE_INTEGER KernelTime;
674  LARGE_INTEGER UserTime;
675 
676  FLOAT CpuUsage;
679 
684  ULONG64 StartAddress;
689  KWAIT_REASON WaitReason;
692 
693  HANDLE ThreadHandle;
694 
695  BOOLEAN IsGuiThread;
696  BOOLEAN JustResolved;
697 
700 
702 
703 typedef struct _PH_THREAD_PROVIDER
704 {
712 
713  HANDLE ProcessId;
715  BOOLEAN HasServices;
717  BOOLEAN Terminating;
719 
720  SLIST_HEADER QueryListHead;
723  ULONG64 RunId;
726 // end_phapppub
727 
729  VOID
730  );
731 
732 PPH_THREAD_PROVIDER PhCreateThreadProvider(
733  _In_ HANDLE ProcessId
734  );
735 
737  _In_ PPH_THREAD_PROVIDER ThreadProvider,
738  _Out_ PPH_CALLBACK_REGISTRATION CallbackRegistration
739  );
740 
742  _In_ PPH_THREAD_PROVIDER ThreadProvider,
743  _In_ PPH_CALLBACK_REGISTRATION CallbackRegistration
744  );
745 
747  _Inout_ PPH_THREAD_PROVIDER ThreadProvider
748  );
749 
751  _In_ PPH_THREAD_PROVIDER ThreadProvider
752  );
753 
754 PPH_THREAD_ITEM PhCreateThreadItem(
755  _In_ HANDLE ThreadId
756  );
757 
758 PPH_THREAD_ITEM PhReferenceThreadItem(
759  _In_ PPH_THREAD_PROVIDER ThreadProvider,
760  _In_ HANDLE ThreadId
761  );
762 
764  _In_ PPH_THREAD_PROVIDER ThreadProvider
765  );
766 
767 // begin_phapppub
768 PHAPPAPI
770 NTAPI
772  _In_ LONG PriorityWin32
773  );
774 // end_phapppub
775 
777  _In_ PPH_THREAD_PROVIDER ThreadProvider
778  );
779 
780 // hndlprv
781 
784 
785 // begin_phapppub
786 #define PH_HANDLE_FILE_SHARED_READ 0x1
787 #define PH_HANDLE_FILE_SHARED_WRITE 0x2
788 #define PH_HANDLE_FILE_SHARED_DELETE 0x4
789 #define PH_HANDLE_FILE_SHARED_MASK 0x7
790 
791 typedef struct _PH_HANDLE_ITEM
792 {
794 
795  HANDLE Handle;
796  PVOID Object;
797  ULONG Attributes;
798  ACCESS_MASK GrantedAccess;
799  ULONG FileFlags;
800 
804 
809 
810 typedef struct _PH_HANDLE_PROVIDER
811 {
816 
821 
822  HANDLE ProcessId;
824 
826  NTSTATUS RunStatus;
828 // end_phapppub
829 
831  VOID
832  );
833 
834 PPH_HANDLE_PROVIDER PhCreateHandleProvider(
835  _In_ HANDLE ProcessId
836  );
837 
838 PPH_HANDLE_ITEM PhCreateHandleItem(
839  _In_opt_ PSYSTEM_HANDLE_TABLE_ENTRY_INFO_EX Handle
840  );
841 
842 PPH_HANDLE_ITEM PhReferenceHandleItem(
843  _In_ PPH_HANDLE_PROVIDER HandleProvider,
844  _In_ HANDLE Handle
845  );
846 
848  _In_ PPH_HANDLE_PROVIDER HandleProvider
849  );
850 
851 NTSTATUS PhEnumHandlesGeneric(
852  _In_ HANDLE ProcessId,
853  _In_ HANDLE ProcessHandle,
854  _Out_ PSYSTEM_HANDLE_INFORMATION_EX *Handles,
855  _Out_ PBOOLEAN FilterNeeded
856  );
857 
859  _In_ PVOID Object
860  );
861 
862 // memprv
863 
865 
866 // begin_phapppub
868 {
877  Teb32Region, // Not used
885 
886 typedef struct _PH_MEMORY_ITEM
887 {
888  LIST_ENTRY ListEntry;
890 
891  union
892  {
893  struct
894  {
895  PVOID BaseAddress;
898  SIZE_T RegionSize;
899  ULONG State;
900  ULONG Protect;
901  ULONG Type;
902  };
903  MEMORY_BASIC_INFORMATION BasicInfo;
904  };
905 
907 
909  SIZE_T PrivateSize;
910 
916 
918 
919  union
920  {
921  struct
922  {
925  } Custom;
926  struct
927  {
929  } MappedFile;
930  struct
931  {
932  HANDLE ThreadId;
933  } Teb;
934  struct
935  {
936  HANDLE ThreadId;
937  } Stack;
938  struct
939  {
940  ULONG Index;
941  } Heap;
942  struct
943  {
945  } HeapSegment;
946  } u;
948 
949 typedef struct _PH_MEMORY_ITEM_LIST
950 {
951  HANDLE ProcessId;
953  LIST_ENTRY ListHead;
955 // end_phapppub
956 
958  VOID
959  );
960 
962  _In_ ULONG Protection,
963  _Out_writes_(17) PWSTR String
964  );
965 
967  _In_ ULONG State
968  );
969 
971  _In_ ULONG Type
972  );
973 
974 PPH_MEMORY_ITEM PhCreateMemoryItem(
975  VOID
976  );
977 
978 // begin_phapppub
979 PHAPPAPI
980 VOID
981 NTAPI
983  _In_ PPH_MEMORY_ITEM_LIST List
984  );
985 
986 PHAPPAPI
987 PPH_MEMORY_ITEM
988 NTAPI
990  _In_ PPH_MEMORY_ITEM_LIST List,
991  _In_ PVOID Address
992  );
993 
994 #define PH_QUERY_MEMORY_IGNORE_FREE 0x1
995 #define PH_QUERY_MEMORY_REGION_TYPE 0x2
996 #define PH_QUERY_MEMORY_WS_COUNTERS 0x4
997 
998 PHAPPAPI
999 NTSTATUS
1000 NTAPI
1002  _In_ HANDLE ProcessId,
1003  _In_ ULONG Flags,
1004  _Out_ PPH_MEMORY_ITEM_LIST List
1005  );
1006 // end_phapppub
1007 
1008 #endif