Process Hacker
ph.h
Go to the documentation of this file.
1 #ifndef _PH_PH_H
2 #define _PH_PH_H
3 
4 #pragma once
5 
6 #include <phbase.h>
7 #include <stdarg.h>
8 #include <phnatinl.h>
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 // native
15 
17 #define SYSTEM_IDLE_PROCESS_ID ((HANDLE)0)
18 
19 #define SYSTEM_PROCESS_ID ((HANDLE)4)
20 
21 #define SYSTEM_IDLE_PROCESS_NAME (L"System Idle Process")
22 
23 // General object-related function types
24 
25 typedef NTSTATUS (NTAPI *PPH_OPEN_OBJECT)(
26  _Out_ PHANDLE Handle,
27  _In_ ACCESS_MASK DesiredAccess,
28  _In_opt_ PVOID Context
29  );
30 
31 typedef NTSTATUS (NTAPI *PPH_GET_OBJECT_SECURITY)(
32  _Out_ PSECURITY_DESCRIPTOR *SecurityDescriptor,
33  _In_ SECURITY_INFORMATION SecurityInformation,
34  _In_opt_ PVOID Context
35  );
36 
37 typedef NTSTATUS (NTAPI *PPH_SET_OBJECT_SECURITY)(
38  _In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
39  _In_ SECURITY_INFORMATION SecurityInformation,
40  _In_opt_ PVOID Context
41  );
42 
44 NTSTATUS
45 NTAPI
47  _Out_ PHANDLE ProcessHandle,
48  _In_ ACCESS_MASK DesiredAccess,
49  _In_ HANDLE ProcessId
50  );
51 
53 NTSTATUS
54 NTAPI
56  _Out_ PHANDLE ThreadHandle,
57  _In_ ACCESS_MASK DesiredAccess,
58  _In_ HANDLE ThreadId
59  );
60 
62 NTSTATUS
63 NTAPI
65  _Out_ PHANDLE ProcessHandle,
66  _In_ ACCESS_MASK DesiredAccess,
67  _In_ HANDLE ThreadHandle
68  );
69 
71 NTSTATUS
72 NTAPI
74  _Out_ PHANDLE TokenHandle,
75  _In_ ACCESS_MASK DesiredAccess,
76  _In_ HANDLE ProcessHandle
77  );
78 
80 NTSTATUS
81 NTAPI
83  _Out_ PHANDLE TokenHandle,
84  _In_ ACCESS_MASK DesiredAccess,
85  _In_ HANDLE ThreadHandle,
86  _In_ BOOLEAN OpenAsSelf
87  );
88 
90 NTSTATUS
91 NTAPI
93  _In_ HANDLE Handle,
94  _In_ SECURITY_INFORMATION SecurityInformation,
95  _Out_ PSECURITY_DESCRIPTOR *SecurityDescriptor
96  );
97 
99 NTSTATUS
100 NTAPI
102  _In_ HANDLE Handle,
103  _In_ SECURITY_INFORMATION SecurityInformation,
104  _In_ PSECURITY_DESCRIPTOR SecurityDescriptor
105  );
106 
107 PHLIBAPI
108 NTSTATUS
109 NTAPI
111  _In_ HANDLE ProcessHandle,
112  _In_ NTSTATUS ExitStatus
113  );
114 
115 PHLIBAPI
116 NTSTATUS
117 NTAPI
119  _In_ HANDLE ProcessHandle
120  );
121 
122 PHLIBAPI
123 NTSTATUS
124 NTAPI
126  _In_ HANDLE ProcessHandle
127  );
128 
129 PHLIBAPI
130 NTSTATUS
131 NTAPI
133  _In_ HANDLE ThreadHandle,
134  _In_ NTSTATUS ExitStatus
135  );
136 
137 PHLIBAPI
138 NTSTATUS
139 NTAPI
141  _In_ HANDLE ThreadHandle,
142  _Out_opt_ PULONG PreviousSuspendCount
143  );
144 
145 PHLIBAPI
146 NTSTATUS
147 NTAPI
149  _In_ HANDLE ThreadHandle,
150  _Out_opt_ PULONG PreviousSuspendCount
151  );
152 
153 PHLIBAPI
154 NTSTATUS
155 NTAPI
157  _In_ HANDLE ThreadHandle,
158  _Inout_ PCONTEXT Context
159  );
160 
161 PHLIBAPI
162 NTSTATUS
163 NTAPI
165  _In_ HANDLE ThreadHandle,
166  _In_ PCONTEXT Context
167  );
168 
169 PHLIBAPI
170 NTSTATUS
171 NTAPI
173  _In_ HANDLE ProcessHandle,
174  _In_ PVOID BaseAddress,
175  _Out_writes_bytes_(BufferSize) PVOID Buffer,
176  _In_ SIZE_T BufferSize,
177  _Out_opt_ PSIZE_T NumberOfBytesRead
178  );
179 
180 PHLIBAPI
181 NTSTATUS
182 NTAPI
184  _In_ HANDLE ProcessHandle,
185  _In_ PVOID BaseAddress,
186  _In_reads_bytes_(BufferSize) PVOID Buffer,
187  _In_ SIZE_T BufferSize,
188  _Out_opt_ PSIZE_T NumberOfBytesWritten
189  );
190 
191 PHLIBAPI
192 NTSTATUS
193 NTAPI
195  _In_ HANDLE ProcessHandle,
196  _Out_ PPH_STRING *FileName
197  );
198 
199 PHLIBAPI
200 NTSTATUS
201 NTAPI
203  _In_ HANDLE ProcessHandle,
204  _Out_ PPH_STRING *FileName
205  );
206 
208 typedef enum _PH_PEB_OFFSET
209 {
218  PhpoTypeMask = 0xffff,
219 
220  PhpoWow64 = 0x10000
221 } PH_PEB_OFFSET;
222 
223 PHLIBAPI
224 NTSTATUS
225 NTAPI
227  _In_ HANDLE ProcessHandle,
228  _In_ PH_PEB_OFFSET Offset,
229  _Out_ PPH_STRING *String
230  );
231 
232 PHLIBAPI
233 NTSTATUS
234 NTAPI
236  _In_ HANDLE ProcessHandle,
237  _Out_ PPH_STRING *CommandLine
238  );
239 
240 PHLIBAPI
241 NTSTATUS
242 NTAPI
244  _In_ HANDLE ProcessHandle,
245  _Out_ PULONG WindowFlags,
246  _Out_ PPH_STRING *WindowTitle
247  );
248 
249 PHLIBAPI
250 NTSTATUS
251 NTAPI
253  _In_ HANDLE ProcessHandle,
254  _Out_ PBOOLEAN IsPosix
255  );
256 
257 PHLIBAPI
258 NTSTATUS
259 NTAPI
261  _In_ HANDLE ProcessHandle,
262  _Out_ PULONG ExecuteFlags
263  );
264 
265 #define PH_PROCESS_DEP_ENABLED 0x1
266 #define PH_PROCESS_DEP_ATL_THUNK_EMULATION_DISABLED 0x2
267 #define PH_PROCESS_DEP_PERMANENT 0x4
268 
269 PHLIBAPI
270 NTSTATUS
271 NTAPI
273  _In_ HANDLE ProcessHandle,
274  _Out_ PULONG DepStatus
275  );
276 
277 PHLIBAPI
278 NTSTATUS
279 NTAPI
281  _In_ HANDLE ProcessHandle,
282  _Out_ PPH_STRING *CommandLine
283  );
284 
285 #define PH_GET_PROCESS_ENVIRONMENT_WOW64 0x1 // retrieve the WOW64 environment
286 
287 PHLIBAPI
288 NTSTATUS
289 NTAPI
291  _In_ HANDLE ProcessHandle,
292  _In_ ULONG Flags,
293  _Out_ PVOID *Environment,
294  _Out_ PULONG EnvironmentLength
295  );
296 
298 {
302 
303 PHLIBAPI
304 BOOLEAN
305 NTAPI
307  _In_ PVOID Environment,
308  _In_ ULONG EnvironmentLength,
309  _Inout_ PULONG EnumerationKey,
310  _Out_ PPH_ENVIRONMENT_VARIABLE Variable
311  );
312 
313 PHLIBAPI
314 NTSTATUS
315 NTAPI
317  _In_ HANDLE ProcessHandle,
318  _In_ PVOID BaseAddress,
319  _Out_ PPH_STRING *FileName
320  );
321 
322 PHLIBAPI
323 NTSTATUS
324 NTAPI
326  _In_ HANDLE ProcessHandle,
327  _Out_ PMEMORY_WORKING_SET_INFORMATION *WorkingSetInformation
328  );
329 
331 {
337 
338 PHLIBAPI
339 NTSTATUS
340 NTAPI
342  _In_ HANDLE ProcessHandle,
343  _Out_ PPH_PROCESS_WS_COUNTERS WsCounters
344  );
345 
346 PHLIBAPI
347 NTSTATUS
348 NTAPI
350  _In_ HANDLE ProcessHandle,
351  _In_ ULONG IoPriority
352  );
353 
354 PHLIBAPI
355 NTSTATUS
356 NTAPI
358  _In_ HANDLE ProcessHandle,
359  _In_ ULONG ExecuteFlags
360  );
361 
362 PHLIBAPI
363 NTSTATUS
364 NTAPI
366  _In_ HANDLE ProcessHandle,
367  _In_ ULONG DepStatus
368  );
369 
370 PHLIBAPI
371 NTSTATUS
372 NTAPI
374  _In_ HANDLE ProcessHandle,
375  _In_ ULONG DepStatus,
376  _In_opt_ PLARGE_INTEGER Timeout
377  );
378 
379 PHLIBAPI
380 NTSTATUS
381 NTAPI
383  _In_ HANDLE ProcessHandle,
384  _In_ PWSTR FileName,
385  _In_opt_ PLARGE_INTEGER Timeout
386  );
387 
388 PHLIBAPI
389 NTSTATUS
390 NTAPI
392  _In_ HANDLE ProcessHandle,
393  _In_ PVOID BaseAddress,
394  _In_opt_ PLARGE_INTEGER Timeout
395  );
396 
397 PHLIBAPI
398 NTSTATUS
399 NTAPI
401  _In_ HANDLE ThreadHandle,
402  _In_ ULONG IoPriority
403  );
404 
405 PHLIBAPI
406 NTSTATUS
407 NTAPI
409  _In_ HANDLE JobHandle,
410  _Out_ PJOBOBJECT_BASIC_PROCESS_ID_LIST *ProcessIdList
411  );
412 
413 NTSTATUS
414 NTAPI
416  _In_ HANDLE TokenHandle,
417  _In_ TOKEN_INFORMATION_CLASS TokenInformationClass,
418  _Out_ PVOID *Buffer
419  );
420 
421 PHLIBAPI
422 NTSTATUS
423 NTAPI
425  _In_ HANDLE TokenHandle,
426  _Out_ PTOKEN_USER *User
427  );
428 
429 PHLIBAPI
430 NTSTATUS
431 NTAPI
433  _In_ HANDLE TokenHandle,
434  _Out_ PTOKEN_OWNER *Owner
435  );
436 
437 PHLIBAPI
438 NTSTATUS
439 NTAPI
441  _In_ HANDLE TokenHandle,
442  _Out_ PTOKEN_PRIMARY_GROUP *PrimaryGroup
443  );
444 
445 PHLIBAPI
446 NTSTATUS
447 NTAPI
449  _In_ HANDLE TokenHandle,
450  _Out_ PTOKEN_GROUPS *Groups
451  );
452 
453 PHLIBAPI
454 NTSTATUS
455 NTAPI
457  _In_ HANDLE TokenHandle,
458  _Out_ PTOKEN_PRIVILEGES *Privileges
459  );
460 
461 PHLIBAPI
462 NTSTATUS
463 NTAPI
465  _In_ HANDLE TokenHandle,
466  _In_ ULONG SessionId
467  );
468 
469 PHLIBAPI
470 BOOLEAN
471 NTAPI
473  _In_ HANDLE TokenHandle,
474  _In_opt_ PWSTR PrivilegeName,
475  _In_opt_ PLUID PrivilegeLuid,
476  _In_ ULONG Attributes
477  );
478 
479 PHLIBAPI
480 BOOLEAN
481 NTAPI
483  _In_ HANDLE TokenHandle,
484  _In_ LONG Privilege,
485  _In_ ULONG Attributes
486  );
487 
488 PHLIBAPI
489 NTSTATUS
490 NTAPI
492  _In_ HANDLE TokenHandle,
493  _In_ BOOLEAN IsVirtualizationEnabled
494  );
495 
496 PHLIBAPI
497 NTSTATUS
498 NTAPI
500  _In_ HANDLE TokenHandle,
501  _Out_opt_ PMANDATORY_LEVEL IntegrityLevel,
502  _Out_opt_ PWSTR *IntegrityString
503  );
504 
505 PHLIBAPI
506 NTSTATUS
507 NTAPI
509  _In_ HANDLE FileHandle,
510  _Out_ PLARGE_INTEGER Size
511  );
512 
513 PHLIBAPI
514 NTSTATUS
515 NTAPI
517  _In_ HANDLE FileHandle,
518  _In_ PLARGE_INTEGER Size
519  );
520 
521 PHLIBAPI
522 NTSTATUS
523 NTAPI
525  _In_ HANDLE TransactionManagerHandle,
526  _Out_ PTRANSACTIONMANAGER_BASIC_INFORMATION BasicInformation
527  );
528 
529 PHLIBAPI
530 NTSTATUS
531 NTAPI
533  _In_ HANDLE TransactionManagerHandle,
534  _Out_ PPH_STRING *LogFileName
535  );
536 
537 PHLIBAPI
538 NTSTATUS
539 NTAPI
541  _In_ HANDLE TransactionHandle,
542  _Out_ PTRANSACTION_BASIC_INFORMATION BasicInformation
543  );
544 
545 PHLIBAPI
546 NTSTATUS
547 NTAPI
549  _In_ HANDLE TransactionHandle,
550  _Out_opt_ PLARGE_INTEGER Timeout,
551  _Out_opt_ TRANSACTION_OUTCOME *Outcome,
552  _Out_opt_ PPH_STRING *Description
553  );
554 
555 PHLIBAPI
556 NTSTATUS
557 NTAPI
559  _In_ HANDLE ResourceManagerHandle,
560  _Out_opt_ PGUID Guid,
561  _Out_opt_ PPH_STRING *Description
562  );
563 
564 PHLIBAPI
565 NTSTATUS
566 NTAPI
568  _In_ HANDLE EnlistmentHandle,
569  _Out_ PENLISTMENT_BASIC_INFORMATION BasicInformation
570  );
571 
572 NTSTATUS
573 NTAPI
575  _Out_ PHANDLE DriverHandle,
576  _In_ PVOID BaseAddress
577  );
578 
579 NTSTATUS
580 NTAPI
582  _In_ HANDLE DriverHandle,
583  _Out_ PPH_STRING *Name
584  );
585 
586 NTSTATUS
587 NTAPI
589  _In_ HANDLE DriverHandle,
590  _Out_ PPH_STRING *ServiceKeyName
591  );
592 
593 PHLIBAPI
594 NTSTATUS
595 NTAPI
597  _In_opt_ PVOID BaseAddress,
598  _In_opt_ PWSTR Name
599  );
600 
601 PHLIBAPI
602 NTSTATUS
603 NTAPI
605  _In_ HANDLE SourceProcessHandle,
606  _In_ HANDLE SourceHandle,
607  _In_opt_ HANDLE TargetProcessHandle,
608  _Out_opt_ PHANDLE TargetHandle,
609  _In_ ACCESS_MASK DesiredAccess,
610  _In_ ULONG HandleAttributes,
611  _In_ ULONG Options
612  );
613 
614 #define PH_ENUM_PROCESS_MODULES_LIMIT 0x800
615 
628 typedef BOOLEAN (NTAPI *PPH_ENUM_PROCESS_MODULES_CALLBACK)(
629  _In_ PLDR_DATA_TABLE_ENTRY Module,
630  _In_opt_ PVOID Context
631  );
632 
633 #define PH_ENUM_PROCESS_MODULES_DONT_RESOLVE_WOW64_FS 0x1
634 #define PH_ENUM_PROCESS_MODULES_TRY_MAPPED_FILE_NAME 0x2
635 
637 {
639  PVOID Context;
640  ULONG Flags;
642 
643 PHLIBAPI
644 NTSTATUS
645 NTAPI
647  _In_ HANDLE ProcessHandle,
648  _In_ PPH_ENUM_PROCESS_MODULES_CALLBACK Callback,
649  _In_opt_ PVOID Context
650  );
651 
652 PHLIBAPI
653 NTSTATUS
654 NTAPI
656  _In_ HANDLE ProcessHandle,
657  _In_ PPH_ENUM_PROCESS_MODULES_PARAMETERS Parameters
658  );
659 
660 PHLIBAPI
661 NTSTATUS
662 NTAPI
664  _In_ HANDLE ProcessHandle,
665  _In_ PVOID BaseAddress,
666  _In_ ULONG LoadCount
667  );
668 
669 PHLIBAPI
670 NTSTATUS
671 NTAPI
673  _In_ HANDLE ProcessHandle,
674  _In_ PPH_ENUM_PROCESS_MODULES_CALLBACK Callback,
675  _In_opt_ PVOID Context
676  );
677 
678 PHLIBAPI
679 NTSTATUS
680 NTAPI
682  _In_ HANDLE ProcessHandle,
683  _In_ PPH_ENUM_PROCESS_MODULES_PARAMETERS Parameters
684  );
685 
686 PHLIBAPI
687 NTSTATUS
688 NTAPI
690  _In_ HANDLE ProcessHandle,
691  _In_ PVOID BaseAddress,
692  _In_ ULONG LoadCount
693  );
694 
695 PHLIBAPI
696 NTSTATUS
697 NTAPI
699  _In_ HANDLE ProcessHandle,
700  _In_ PWSTR FileName,
701  _In_opt_ PSTR ProcedureName,
702  _In_opt_ ULONG ProcedureNumber,
703  _Out_ PVOID *ProcedureAddress,
704  _Out_opt_ PVOID *DllBase
705  );
706 
707 PHLIBAPI
708 NTSTATUS
709 NTAPI
711  _Out_ PRTL_PROCESS_MODULES *Modules
712  );
713 
714 NTSTATUS
715 NTAPI
718  );
719 
720 PHLIBAPI
722 NTAPI
724  VOID
725  );
726 
734 #define PH_FIRST_PROCESS(Processes) ((PSYSTEM_PROCESS_INFORMATION)(Processes))
735 
746 #define PH_NEXT_PROCESS(Process) ( \
747  ((PSYSTEM_PROCESS_INFORMATION)(Process))->NextEntryOffset ? \
748  (PSYSTEM_PROCESS_INFORMATION)((PCHAR)(Process) + \
749  ((PSYSTEM_PROCESS_INFORMATION)(Process))->NextEntryOffset) : \
750  NULL \
751  )
752 
753 PHLIBAPI
754 NTSTATUS
755 NTAPI
757  _Out_ PVOID *Processes
758  );
759 
760 PHLIBAPI
761 NTSTATUS
762 NTAPI
764  _Out_ PVOID *Processes,
765  _In_ SYSTEM_INFORMATION_CLASS SystemInformationClass
766  );
767 
768 PHLIBAPI
769 NTSTATUS
770 NTAPI
772  _Out_ PVOID *Processes,
773  _In_ ULONG SessionId
774  );
775 
776 PHLIBAPI
778 NTAPI
780  _In_ PVOID Processes,
781  _In_ HANDLE ProcessId
782  );
783 
784 PHLIBAPI
786 NTAPI
788  _In_ PVOID Processes,
789  _In_ PPH_STRINGREF ImageName
790  );
791 
792 PHLIBAPI
793 NTSTATUS
794 NTAPI
796  _Out_ PSYSTEM_HANDLE_INFORMATION *Handles
797  );
798 
799 PHLIBAPI
800 NTSTATUS
801 NTAPI
803  _Out_ PSYSTEM_HANDLE_INFORMATION_EX *Handles
804  );
805 
806 #define PH_FIRST_PAGEFILE(Pagefiles) ( \
807  /* The size of a pagefile can never be 0. A TotalSize of 0
808  * is used to indicate that there are no pagefiles.
809  */ ((PSYSTEM_PAGEFILE_INFORMATION)(Pagefiles))->TotalSize ? \
810  (PSYSTEM_PAGEFILE_INFORMATION)(Pagefiles) : \
811  NULL \
812  )
813 #define PH_NEXT_PAGEFILE(Pagefile) ( \
814  ((PSYSTEM_PAGEFILE_INFORMATION)(Pagefile))->NextEntryOffset ? \
815  (PSYSTEM_PAGEFILE_INFORMATION)((PCHAR)(Pagefile) + \
816  ((PSYSTEM_PAGEFILE_INFORMATION)(Pagefile))->NextEntryOffset) : \
817  NULL \
818  )
819 
820 PHLIBAPI
821 NTSTATUS
822 NTAPI
824  _Out_ PVOID *Pagefiles
825  );
826 
827 PHLIBAPI
828 NTSTATUS
829 NTAPI
831  _In_ HANDLE ProcessId,
832  _Out_ PPH_STRING *FileName
833  );
834 
835 PHLIBAPI
836 NTSTATUS
837 NTAPI
839  _In_ HANDLE ProcessId,
840  _Out_ PBOOLEAN IsDotNet
841  );
843 #define PH_CLR_USE_SECTION_CHECK 0x1
844 #define PH_CLR_NO_WOW64_CHECK 0x2
845 #define PH_CLR_KNOWN_IS_WOW64 0x4
847 #define PH_CLR_VERSION_1_0 0x1
848 #define PH_CLR_VERSION_1_1 0x2
849 #define PH_CLR_VERSION_2_0 0x4
850 #define PH_CLR_VERSION_4_ABOVE 0x8
851 #define PH_CLR_VERSION_MASK 0xf
852 #define PH_CLR_MSCORLIB_PRESENT 0x10000
853 #define PH_CLR_PROCESS_IS_WOW64 0x100000
854 
855 PHLIBAPI
856 NTSTATUS
857 NTAPI
859  _In_ HANDLE ProcessId,
860  _In_opt_ HANDLE ProcessHandle,
861  _In_ ULONG InFlags,
862  _Out_opt_ PBOOLEAN IsDotNet,
863  _Out_opt_ PULONG Flags
864  );
865 
878 typedef BOOLEAN (NTAPI *PPH_ENUM_DIRECTORY_OBJECTS)(
879  _In_ PPH_STRINGREF Name,
880  _In_ PPH_STRINGREF TypeName,
881  _In_opt_ PVOID Context
882  );
883 
884 PHLIBAPI
885 NTSTATUS
886 NTAPI
888  _In_ HANDLE DirectoryHandle,
889  _In_ PPH_ENUM_DIRECTORY_OBJECTS Callback,
890  _In_opt_ PVOID Context
891  );
892 
893 typedef BOOLEAN (NTAPI *PPH_ENUM_DIRECTORY_FILE)(
894  _In_ PFILE_DIRECTORY_INFORMATION Information,
895  _In_opt_ PVOID Context
896  );
897 
898 PHLIBAPI
899 NTSTATUS
900 NTAPI
902  _In_ HANDLE FileHandle,
903  _In_opt_ PUNICODE_STRING SearchPattern,
904  _In_ PPH_ENUM_DIRECTORY_FILE Callback,
905  _In_opt_ PVOID Context
906  );
908 #define PH_FIRST_STREAM(Streams) ((PFILE_STREAM_INFORMATION)(Streams))
909 #define PH_NEXT_STREAM(Stream) ( \
910  ((PFILE_STREAM_INFORMATION)(Stream))->NextEntryOffset ? \
911  (PFILE_STREAM_INFORMATION)((PCHAR)(Stream) + \
912  ((PFILE_STREAM_INFORMATION)(Stream))->NextEntryOffset) : \
913  NULL \
914  )
915 
916 PHLIBAPI
917 NTSTATUS
918 NTAPI
920  _In_ HANDLE FileHandle,
921  _Out_ PVOID *Streams
922  );
923 
924 VOID
925 NTAPI
927  VOID
928  );
929 
930 PHLIBAPI
931 VOID
932 NTAPI
934  VOID
935  );
936 
937 PHLIBAPI
938 VOID
939 NTAPI
941  VOID
942  );
943 
944 PHLIBAPI
946 NTAPI
948  _In_ PPH_STRING Name
949  );
950 
951 PHLIBAPI
953 NTAPI
955  _In_ PPH_STRING FileName
956  );
958 #define PH_MODULE_TYPE_MODULE 1
959 #define PH_MODULE_TYPE_MAPPED_FILE 2
960 #define PH_MODULE_TYPE_WOW64_MODULE 3
961 #define PH_MODULE_TYPE_KERNEL_MODULE 4
962 #define PH_MODULE_TYPE_MAPPED_IMAGE 5
963 
964 typedef struct _PH_MODULE_INFO
965 {
966  ULONG Type;
967  PVOID BaseAddress;
968  ULONG Size;
969  PVOID EntryPoint;
970  ULONG Flags;
974  USHORT LoadOrderIndex; // -1 if N/A
975  USHORT LoadCount; // -1 if N/A
976  USHORT LoadReason; // -1 if N/A
977  USHORT Reserved;
978  LARGE_INTEGER LoadTime; // 0 if N/A
980 
993 typedef BOOLEAN (NTAPI *PPH_ENUM_GENERIC_MODULES_CALLBACK)(
994  _In_ PPH_MODULE_INFO Module,
995  _In_opt_ PVOID Context
996  );
998 #define PH_ENUM_GENERIC_MAPPED_FILES 0x1
999 #define PH_ENUM_GENERIC_MAPPED_IMAGES 0x2
1000 
1001 PHLIBAPI
1002 NTSTATUS
1003 NTAPI
1005  _In_ HANDLE ProcessId,
1006  _In_opt_ HANDLE ProcessHandle,
1007  _In_ ULONG Flags,
1008  _In_ PPH_ENUM_GENERIC_MODULES_CALLBACK Callback,
1009  _In_opt_ PVOID Context
1010  );
1012 #define PH_KEY_PREDEFINE(Number) ((HANDLE)(LONG_PTR)(-3 - (Number) * 2))
1013 #define PH_KEY_IS_PREDEFINED(Predefine) (((LONG_PTR)(Predefine) < 0) && ((LONG_PTR)(Predefine) & 0x1))
1014 #define PH_KEY_PREDEFINE_TO_NUMBER(Predefine) (ULONG)(((-(LONG_PTR)(Predefine) - 3) >> 1))
1016 #define PH_KEY_LOCAL_MACHINE PH_KEY_PREDEFINE(0) // \Registry\Machine
1017 #define PH_KEY_USERS PH_KEY_PREDEFINE(1) // \Registry\User
1018 #define PH_KEY_CLASSES_ROOT PH_KEY_PREDEFINE(2) // \Registry\Machine\Software\Classes
1019 #define PH_KEY_CURRENT_USER PH_KEY_PREDEFINE(3) // \Registry\User\<SID>
1020 #define PH_KEY_CURRENT_USER_NUMBER 3
1021 #define PH_KEY_MAXIMUM_PREDEFINE 4
1022 
1023 PHLIBAPI
1024 NTSTATUS
1025 NTAPI
1026 PhCreateKey(
1027  _Out_ PHANDLE KeyHandle,
1028  _In_ ACCESS_MASK DesiredAccess,
1029  _In_opt_ HANDLE RootDirectory,
1030  _In_ PPH_STRINGREF ObjectName,
1031  _In_ ULONG Attributes,
1032  _In_ ULONG CreateOptions,
1033  _Out_opt_ PULONG Disposition
1034  );
1035 
1036 PHLIBAPI
1037 NTSTATUS
1038 NTAPI
1039 PhOpenKey(
1040  _Out_ PHANDLE KeyHandle,
1041  _In_ ACCESS_MASK DesiredAccess,
1042  _In_opt_ HANDLE RootDirectory,
1043  _In_ PPH_STRINGREF ObjectName,
1044  _In_ ULONG Attributes
1045  );
1046 
1047 // lsa
1048 
1049 PHLIBAPI
1050 NTSTATUS
1051 NTAPI
1053  _Out_ PLSA_HANDLE PolicyHandle,
1054  _In_ ACCESS_MASK DesiredAccess,
1055  _In_opt_ PUNICODE_STRING SystemName
1056  );
1057 
1058 LSA_HANDLE
1059 NTAPI
1061  VOID
1062  );
1063 
1064 PHLIBAPI
1065 BOOLEAN
1066 NTAPI
1068  _In_ PLUID PrivilegeValue,
1069  _Out_ PPH_STRING *PrivilegeName
1070  );
1071 
1072 PHLIBAPI
1073 BOOLEAN
1074 NTAPI
1076  _In_ PPH_STRINGREF PrivilegeName,
1077  _Out_ PPH_STRING *PrivilegeDisplayName
1078  );
1079 
1080 PHLIBAPI
1081 BOOLEAN
1082 NTAPI
1084  _In_ PPH_STRINGREF PrivilegeName,
1085  _Out_ PLUID PrivilegeValue
1086  );
1087 
1088 PHLIBAPI
1089 NTSTATUS
1090 NTAPI
1091 PhLookupSid(
1092  _In_ PSID Sid,
1093  _Out_opt_ PPH_STRING *Name,
1094  _Out_opt_ PPH_STRING *DomainName,
1095  _Out_opt_ PSID_NAME_USE NameUse
1096  );
1097 
1098 PHLIBAPI
1099 NTSTATUS
1100 NTAPI
1101 PhLookupName(
1102  _In_ PPH_STRINGREF Name,
1103  _Out_opt_ PSID *Sid,
1104  _Out_opt_ PPH_STRING *DomainName,
1105  _Out_opt_ PSID_NAME_USE NameUse
1106  );
1107 
1108 PHLIBAPI
1109 PPH_STRING
1110 NTAPI
1112  _In_ PSID Sid,
1113  _In_ BOOLEAN IncludeDomain,
1114  _Out_opt_ PSID_NAME_USE NameUse
1115  );
1116 
1117 PHLIBAPI
1118 PPH_STRING
1119 NTAPI
1121  _In_ PSID Sid
1122  );
1123 
1124 // hndlinfo
1125 
1126 #define MAX_OBJECT_TYPE_NUMBER 257
1127 
1128 typedef PPH_STRING (NTAPI *PPH_GET_CLIENT_ID_NAME)(
1129  _In_ PCLIENT_ID ClientId
1130  );
1131 
1133 NTAPI
1135  _In_ PPH_GET_CLIENT_ID_NAME GetClientIdName
1136  );
1137 
1138 PHLIBAPI
1139 PPH_STRING
1140 NTAPI
1142  _In_ PPH_STRING Name
1143  );
1144 
1145 NTSTATUS
1146 NTAPI
1148  _In_ HANDLE SectionHandle,
1149  _Out_ PPH_STRING *FileName
1150  );
1151 
1152 PHLIBAPI
1154 NTAPI
1156  _In_ PCLIENT_ID ClientId
1157  );
1158 
1159 PHLIBAPI
1160 NTSTATUS
1161 NTAPI
1163  _In_ HANDLE ProcessHandle,
1164  _In_ HANDLE Handle,
1165  _In_ ULONG ObjectTypeNumber,
1166  _Out_opt_ POBJECT_BASIC_INFORMATION BasicInformation,
1167  _Out_opt_ PPH_STRING *TypeName,
1168  _Out_opt_ PPH_STRING *ObjectName,
1169  _Out_opt_ PPH_STRING *BestObjectName
1170  );
1171 
1172 PHLIBAPI
1173 NTSTATUS
1174 NTAPI
1176  _In_ HANDLE ProcessHandle,
1177  _In_ HANDLE Handle,
1178  _In_ ULONG ObjectTypeNumber,
1179  _Reserved_ ULONG Flags,
1180  _Out_opt_ PNTSTATUS SubStatus,
1181  _Out_opt_ POBJECT_BASIC_INFORMATION BasicInformation,
1182  _Out_opt_ PPH_STRING *TypeName,
1183  _Out_opt_ PPH_STRING *ObjectName,
1184  _Out_opt_ PPH_STRING *BestObjectName,
1185  _Reserved_ PVOID *ExtraInformation
1186  );
1187 
1188 #define PH_FIRST_OBJECT_TYPE(ObjectTypes) \
1189  (POBJECT_TYPE_INFORMATION)((PCHAR)(ObjectTypes) + ALIGN_UP(sizeof(OBJECT_TYPES_INFORMATION), ULONG_PTR))
1190 
1191 #define PH_NEXT_OBJECT_TYPE(ObjectType) \
1192  (POBJECT_TYPE_INFORMATION)((PCHAR)(ObjectType) + sizeof(OBJECT_TYPE_INFORMATION) + \
1193  ALIGN_UP(ObjectType->TypeName.MaximumLength, ULONG_PTR))
1194 
1195 PHLIBAPI
1196 NTSTATUS
1197 NTAPI
1199  _Out_ POBJECT_TYPES_INFORMATION *ObjectTypes
1200  );
1201 
1202 ULONG
1203 NTAPI
1205  _In_ PUNICODE_STRING TypeName
1206  );
1207 
1208 NTSTATUS
1209 NTAPI
1211  _In_ PUSER_THREAD_START_ROUTINE Routine,
1212  _In_opt_ PVOID Context,
1213  _In_opt_ PLARGE_INTEGER AcquireTimeout,
1214  _In_ PLARGE_INTEGER CallTimeout
1215  );
1216 
1217 NTSTATUS
1218 NTAPI
1220  _In_ HANDLE Handle,
1221  _In_ OBJECT_INFORMATION_CLASS ObjectInformationClass,
1222  _Out_writes_bytes_opt_(ObjectInformationLength) PVOID ObjectInformation,
1223  _In_ ULONG ObjectInformationLength,
1224  _Out_opt_ PULONG ReturnLength
1225  );
1226 
1227 NTSTATUS
1228 NTAPI
1230  _In_ HANDLE Handle,
1231  _In_ SECURITY_INFORMATION SecurityInformation,
1232  _Out_writes_bytes_opt_(Length) PSECURITY_DESCRIPTOR SecurityDescriptor,
1233  _In_ ULONG Length,
1234  _Out_ PULONG LengthNeeded
1235  );
1236 
1237 NTSTATUS
1238 NTAPI
1240  _In_ HANDLE Handle,
1241  _In_ SECURITY_INFORMATION SecurityInformation,
1242  _In_ PSECURITY_DESCRIPTOR SecurityDescriptor
1243  );
1244 
1245 NTSTATUS
1246 NTAPI
1248  _In_ HANDLE SourceProcessHandle,
1249  _In_ HANDLE SourceHandle,
1250  _In_opt_ HANDLE TargetProcessHandle,
1251  _Out_opt_ PHANDLE TargetHandle,
1252  _In_ ACCESS_MASK DesiredAccess,
1253  _In_ ULONG HandleAttributes,
1254  _In_ ULONG Options
1255  );
1256 
1257 // mapimg
1258 
1259 typedef struct _PH_MAPPED_IMAGE
1261  PVOID ViewBase;
1262  SIZE_T Size;
1264  PIMAGE_NT_HEADERS NtHeaders;
1266  PIMAGE_SECTION_HEADER Sections;
1267  USHORT Magic;
1269 
1270 PHLIBAPI
1271 NTSTATUS
1272 NTAPI
1274  _Out_ PPH_MAPPED_IMAGE MappedImage,
1275  _In_ PVOID ViewBase,
1276  _In_ SIZE_T Size
1277  );
1278 
1279 PHLIBAPI
1280 NTSTATUS
1281 NTAPI
1283  _In_opt_ PWSTR FileName,
1284  _In_opt_ HANDLE FileHandle,
1285  _In_ BOOLEAN ReadOnly,
1286  _Out_ PPH_MAPPED_IMAGE MappedImage
1287  );
1288 
1289 PHLIBAPI
1290 NTSTATUS
1291 NTAPI
1293  _Inout_ PPH_MAPPED_IMAGE MappedImage
1294  );
1295 
1296 PHLIBAPI
1297 NTSTATUS
1298 NTAPI
1300  _In_opt_ PWSTR FileName,
1301  _In_opt_ HANDLE FileHandle,
1302  _In_ BOOLEAN ReadOnly,
1303  _Out_ PVOID *ViewBase,
1304  _Out_ PSIZE_T Size
1305  );
1306 
1307 PHLIBAPI
1308 PIMAGE_SECTION_HEADER
1309 NTAPI
1311  _In_ PPH_MAPPED_IMAGE MappedImage,
1312  _In_ ULONG Rva
1313  );
1314 
1315 PHLIBAPI
1316 PVOID
1317 NTAPI
1319  _In_ PPH_MAPPED_IMAGE MappedImage,
1320  _In_ ULONG Rva,
1321  _Out_opt_ PIMAGE_SECTION_HEADER *Section
1322  );
1323 
1324 PHLIBAPI
1325 BOOLEAN
1326 NTAPI
1328  _In_ PIMAGE_SECTION_HEADER Section,
1329  _Out_writes_opt_z_(Count) PSTR Buffer,
1330  _In_ ULONG Count,
1331  _Out_opt_ PULONG ReturnCount
1332  );
1333 
1334 PHLIBAPI
1335 NTSTATUS
1336 NTAPI
1338  _In_ PPH_MAPPED_IMAGE MappedImage,
1339  _In_ ULONG Index,
1340  _Out_ PIMAGE_DATA_DIRECTORY *Entry
1341  );
1342 
1343 PHLIBAPI
1344 NTSTATUS
1345 NTAPI
1347  _In_ PPH_MAPPED_IMAGE MappedImage,
1348  _Out_ PIMAGE_LOAD_CONFIG_DIRECTORY32 *LoadConfig
1349  );
1350 
1351 PHLIBAPI
1352 NTSTATUS
1353 NTAPI
1355  _In_ PPH_MAPPED_IMAGE MappedImage,
1356  _Out_ PIMAGE_LOAD_CONFIG_DIRECTORY64 *LoadConfig
1357  );
1358 
1360 {
1361  PVOID ViewBase;
1363  PIMAGE_NT_HEADERS NtHeaders;
1365  PIMAGE_SECTION_HEADER Sections;
1366  USHORT Magic;
1368 
1369 NTSTATUS
1370 NTAPI
1372  _In_ HANDLE ProcessHandle,
1373  _In_ PVOID ViewBase,
1374  _Out_ PPH_REMOTE_MAPPED_IMAGE RemoteMappedImage
1375  );
1376 
1377 NTSTATUS
1378 NTAPI
1380  _Inout_ PPH_REMOTE_MAPPED_IMAGE RemoteMappedImage
1381  );
1382 
1385  PPH_MAPPED_IMAGE MappedImage;
1388  PIMAGE_DATA_DIRECTORY DataDirectory;
1389  PIMAGE_EXPORT_DIRECTORY ExportDirectory;
1391  PULONG NamePointerTable;
1392  PUSHORT OrdinalTable;
1394 
1397  USHORT Ordinal;
1398  PSTR Name;
1400 
1403  PVOID Function;
1404  PSTR ForwardedName;
1406 
1407 PHLIBAPI
1408 NTSTATUS
1409 NTAPI
1411  _Out_ PPH_MAPPED_IMAGE_EXPORTS Exports,
1412  _In_ PPH_MAPPED_IMAGE MappedImage
1413  );
1414 
1415 PHLIBAPI
1416 NTSTATUS
1417 NTAPI
1419  _In_ PPH_MAPPED_IMAGE_EXPORTS Exports,
1420  _In_ ULONG Index,
1421  _Out_ PPH_MAPPED_IMAGE_EXPORT_ENTRY Entry
1422  );
1423 
1424 PHLIBAPI
1425 NTSTATUS
1426 NTAPI
1428  _In_ PPH_MAPPED_IMAGE_EXPORTS Exports,
1429  _In_opt_ PSTR Name,
1430  _In_opt_ USHORT Ordinal,
1431  _Out_ PPH_MAPPED_IMAGE_EXPORT_FUNCTION Function
1432  );
1433 
1434 PHLIBAPI
1435 NTSTATUS
1436 NTAPI
1438  _In_ PPH_MAPPED_IMAGE_EXPORTS Exports,
1439  _In_opt_ PSTR Name,
1440  _In_opt_ USHORT Ordinal,
1441  _In_ PVOID RemoteBase,
1442  _Out_ PVOID *Function
1443  );
1444 
1445 #define PH_MAPPED_IMAGE_DELAY_IMPORTS 0x1
1446 
1449  PPH_MAPPED_IMAGE MappedImage;
1450  ULONG Flags;
1451  ULONG NumberOfDlls;
1452 
1453  union
1454  {
1455  PIMAGE_IMPORT_DESCRIPTOR DescriptorTable;
1456  PVOID DelayDescriptorTable;
1457  };
1459 
1462  PPH_MAPPED_IMAGE MappedImage;
1463  ULONG Flags;
1464  PSTR Name;
1465  ULONG NumberOfEntries;
1466 
1467  union
1468  {
1469  PIMAGE_IMPORT_DESCRIPTOR Descriptor;
1471  };
1472  PVOID *LookupTable;
1474 
1476 {
1477  PSTR Name;
1478  union
1479  {
1480  USHORT Ordinal;
1481  USHORT NameHint;
1482  };
1484 
1485 PHLIBAPI
1486 NTSTATUS
1487 NTAPI
1489  _Out_ PPH_MAPPED_IMAGE_IMPORTS Imports,
1490  _In_ PPH_MAPPED_IMAGE MappedImage
1491  );
1492 
1493 PHLIBAPI
1494 NTSTATUS
1495 NTAPI
1497  _In_ PPH_MAPPED_IMAGE_IMPORTS Imports,
1498  _In_ ULONG Index,
1499  _Out_ PPH_MAPPED_IMAGE_IMPORT_DLL ImportDll
1500  );
1501 
1502 PHLIBAPI
1503 NTSTATUS
1504 NTAPI
1506  _In_ PPH_MAPPED_IMAGE_IMPORT_DLL ImportDll,
1507  _In_ ULONG Index,
1508  _Out_ PPH_MAPPED_IMAGE_IMPORT_ENTRY Entry
1509  );
1510 
1511 PHLIBAPI
1512 NTSTATUS
1513 NTAPI
1515  _Out_ PPH_MAPPED_IMAGE_IMPORTS Imports,
1516  _In_ PPH_MAPPED_IMAGE MappedImage
1517  );
1518 
1519 USHORT
1520 NTAPI
1521 PhCheckSum(
1522  _In_ ULONG Sum,
1523  _In_reads_(Count) PUSHORT Buffer,
1524  _In_ ULONG Count
1525  );
1526 
1527 PHLIBAPI
1528 ULONG
1529 NTAPI
1531  _In_ PPH_MAPPED_IMAGE MappedImage
1532  );
1533 
1534 // maplib
1536 struct _PH_MAPPED_ARCHIVE;
1538 
1545 
1548  PPH_MAPPED_ARCHIVE MappedArchive;
1550  PSTR Name;
1551  ULONG Size;
1552  PVOID Data;
1554  PIMAGE_ARCHIVE_MEMBER_HEADER Header;
1555  CHAR NameBuffer[20];
1557 
1558 typedef struct _PH_MAPPED_ARCHIVE
1560  PVOID ViewBase;
1561  SIZE_T Size;
1568  PPH_MAPPED_ARCHIVE_MEMBER FirstStandardMember;
1569  PPH_MAPPED_ARCHIVE_MEMBER LastStandardMember;
1571 
1574  PSTR Name;
1575  PSTR DllName;
1576  union
1577  {
1578  USHORT Ordinal;
1579  USHORT NameHint;
1580  };
1581  BYTE Type;
1582  BYTE NameType;
1583  USHORT Machine;
1585 
1586 PHLIBAPI
1587 NTSTATUS
1588 NTAPI
1590  _Out_ PPH_MAPPED_ARCHIVE MappedArchive,
1591  _In_ PVOID ViewBase,
1592  _In_ SIZE_T Size
1593  );
1594 
1595 PHLIBAPI
1596 NTSTATUS
1597 NTAPI
1599  _In_opt_ PWSTR FileName,
1600  _In_opt_ HANDLE FileHandle,
1601  _In_ BOOLEAN ReadOnly,
1602  _Out_ PPH_MAPPED_ARCHIVE MappedArchive
1603  );
1604 
1605 PHLIBAPI
1606 NTSTATUS
1607 NTAPI
1609  _Inout_ PPH_MAPPED_ARCHIVE MappedArchive
1610  );
1611 
1612 PHLIBAPI
1613 NTSTATUS
1614 NTAPI
1616  _In_ PPH_MAPPED_ARCHIVE_MEMBER Member,
1617  _Out_ PPH_MAPPED_ARCHIVE_MEMBER NextMember
1618  );
1619 
1620 PHLIBAPI
1621 BOOLEAN
1622 NTAPI
1624  _In_ PPH_MAPPED_ARCHIVE_MEMBER Member
1625  );
1626 
1627 PHLIBAPI
1628 NTSTATUS
1629 NTAPI
1631  _In_ PPH_MAPPED_ARCHIVE_MEMBER Member,
1632  _Out_ PPH_MAPPED_ARCHIVE_IMPORT_ENTRY Entry
1633  );
1634 
1635 // iosup
1636 
1638 
1639 BOOLEAN
1640 NTAPI
1642  VOID
1643  );
1644 
1645 PHLIBAPI
1646 NTSTATUS
1647 NTAPI
1649  _Out_ PHANDLE FileHandle,
1650  _In_ PWSTR FileName,
1651  _In_ ACCESS_MASK DesiredAccess,
1652  _In_opt_ ULONG FileAttributes,
1653  _In_ ULONG ShareAccess,
1654  _In_ ULONG CreateDisposition,
1655  _In_ ULONG CreateOptions
1656  );
1657 
1658 PHLIBAPI
1659 NTSTATUS
1660 NTAPI
1662  _Out_ PHANDLE FileHandle,
1663  _In_ PWSTR FileName,
1664  _In_ ACCESS_MASK DesiredAccess,
1665  _In_opt_ ULONG FileAttributes,
1666  _In_ ULONG ShareAccess,
1667  _In_ ULONG CreateDisposition,
1668  _In_ ULONG CreateOptions,
1669  _Out_opt_ PULONG CreateStatus
1670  );
1671 
1672 PHLIBAPI
1673 NTSTATUS
1674 NTAPI
1676  _In_ PWSTR FileName,
1677  _Out_ PFILE_NETWORK_OPEN_INFORMATION FileInformation
1678  );
1679 
1680 PHLIBAPI
1681 NTSTATUS
1682 NTAPI
1684  _In_ PWSTR FileName
1685  );
1686 
1687 PHLIBAPI
1688 NTSTATUS
1689 NTAPI
1691  _In_ HANDLE FileHandle,
1692  _In_opt_ HANDLE Event,
1693  _In_opt_ PIO_APC_ROUTINE ApcRoutine,
1694  _In_opt_ PVOID ApcContext,
1695  _Out_ PIO_STATUS_BLOCK IoStatusBlock
1696  );
1697 
1698 PHLIBAPI
1699 NTSTATUS
1700 NTAPI
1702  _In_ HANDLE FileHandle
1703  );
1704 
1705 PHLIBAPI
1706 NTSTATUS
1707 NTAPI
1709  _In_ HANDLE FileHandle,
1710  _Out_writes_bytes_opt_(Length) PVOID Buffer,
1711  _In_ ULONG Length,
1712  _Out_opt_ PULONG NumberOfBytesRead,
1713  _Out_opt_ PULONG NumberOfBytesAvailable,
1714  _Out_opt_ PULONG NumberOfBytesLeftInMessage
1715  );
1716 
1717 PHLIBAPI
1718 NTSTATUS
1719 NTAPI
1721  _In_ HANDLE FileHandle,
1722  _In_opt_ HANDLE Event,
1723  _In_opt_ PIO_APC_ROUTINE ApcRoutine,
1724  _In_opt_ PVOID ApcContext,
1725  _Out_ PIO_STATUS_BLOCK IoStatusBlock,
1726  _In_reads_bytes_(InputBufferLength) PVOID InputBuffer,
1727  _In_ ULONG InputBufferLength,
1728  _Out_writes_bytes_(OutputBufferLength) PVOID OutputBuffer,
1729  _In_ ULONG OutputBufferLength
1730  );
1731 
1732 PHLIBAPI
1733 NTSTATUS
1734 NTAPI
1736  _In_opt_ PUNICODE_STRING FileSystemName,
1737  _In_ PUNICODE_STRING Name,
1738  _In_opt_ PLARGE_INTEGER Timeout,
1739  _In_ BOOLEAN UseDefaultTimeout
1740  );
1741 
1742 PHLIBAPI
1743 NTSTATUS
1744 NTAPI
1746  _In_ HANDLE FileHandle
1747  );
1748 
1749 // Core flags (PhCreateFileStream2)
1752 #define PH_FILE_STREAM_HANDLE_UNOWNED 0x1
1755 #define PH_FILE_STREAM_UNBUFFERED 0x2
1756 
1759 #define PH_FILE_STREAM_ASYNCHRONOUS 0x4
1762 #define PH_FILE_STREAM_OWN_POSITION 0x8
1764 // Higher-level flags (PhCreateFileStream)
1765 #define PH_FILE_STREAM_APPEND 0x00010000
1766 
1767 // Internal flags
1769 #define PH_FILE_STREAM_WRITTEN 0x80000000
1771 // Seek
1772 typedef enum _PH_SEEK_ORIGIN
1775  SeekCurrent,
1776  SeekEnd
1778 
1779 typedef struct _PH_FILE_STREAM
1781  HANDLE FileHandle;
1782  ULONG Flags;
1783  LARGE_INTEGER Position; // file object position, *not* the actual position
1785  PVOID Buffer;
1788  ULONG ReadPosition; // read position in buffer
1789  ULONG ReadLength; // how much available to read from buffer
1790  ULONG WritePosition; // write position in buffer
1792 
1793 PHLIBAPI
1794 NTSTATUS
1795 NTAPI
1797  _Out_ PPH_FILE_STREAM *FileStream,
1798  _In_ PWSTR FileName,
1799  _In_ ACCESS_MASK DesiredAccess,
1800  _In_ ULONG ShareMode,
1801  _In_ ULONG CreateDisposition,
1802  _In_ ULONG Flags
1803  );
1804 
1805 PHLIBAPI
1806 NTSTATUS
1807 NTAPI
1809  _Out_ PPH_FILE_STREAM *FileStream,
1810  _In_ HANDLE FileHandle,
1811  _In_ ULONG Flags,
1812  _In_ ULONG BufferLength
1813  );
1814 
1815 PHLIBAPI
1816 VOID
1817 NTAPI
1819  _In_ PPH_FILE_STREAM FileStream
1820  );
1821 
1822 PHLIBAPI
1823 NTSTATUS
1824 NTAPI
1826  _Inout_ PPH_FILE_STREAM FileStream,
1827  _Out_writes_bytes_(Length) PVOID Buffer,
1828  _In_ ULONG Length,
1829  _Out_opt_ PULONG ReadLength
1830  );
1831 
1832 PHLIBAPI
1833 NTSTATUS
1834 NTAPI
1836  _Inout_ PPH_FILE_STREAM FileStream,
1837  _In_reads_bytes_(Length) PVOID Buffer,
1838  _In_ ULONG Length
1839  );
1840 
1841 PHLIBAPI
1842 NTSTATUS
1843 NTAPI
1845  _Inout_ PPH_FILE_STREAM FileStream,
1846  _In_ BOOLEAN Full
1847  );
1848 
1849 PHLIBAPI
1850 VOID
1851 NTAPI
1853  _In_ PPH_FILE_STREAM FileStream,
1854  _Out_ PLARGE_INTEGER Position
1855  );
1856 
1857 PHLIBAPI
1858 NTSTATUS
1859 NTAPI
1861  _Inout_ PPH_FILE_STREAM FileStream,
1862  _In_ PLARGE_INTEGER Offset,
1863  _In_ PH_SEEK_ORIGIN Origin
1864  );
1865 
1866 PHLIBAPI
1867 NTSTATUS
1868 NTAPI
1870  _Inout_ PPH_FILE_STREAM FileStream,
1871  _In_ PLARGE_INTEGER Position,
1872  _In_ PLARGE_INTEGER Length,
1873  _In_ BOOLEAN Wait,
1874  _In_ BOOLEAN Shared
1875  );
1876 
1877 PHLIBAPI
1878 NTSTATUS
1879 NTAPI
1881  _Inout_ PPH_FILE_STREAM FileStream,
1882  _In_ PLARGE_INTEGER Position,
1883  _In_ PLARGE_INTEGER Length
1884  );
1885 
1886 PHLIBAPI
1887 NTSTATUS
1888 NTAPI
1890  _Inout_ PPH_FILE_STREAM FileStream,
1891  _In_ PPH_STRINGREF String
1892  );
1893 
1894 PHLIBAPI
1895 NTSTATUS
1896 NTAPI
1898  _Inout_ PPH_FILE_STREAM FileStream,
1899  _In_ PWSTR String
1900  );
1901 
1902 PHLIBAPI
1903 NTSTATUS
1904 NTAPI
1906  _Inout_ PPH_FILE_STREAM FileStream,
1907  _In_ PWSTR Buffer,
1908  _In_ SIZE_T Length
1909  );
1910 
1911 PHLIBAPI
1912 NTSTATUS
1913 NTAPI
1915  _Inout_ PPH_FILE_STREAM FileStream,
1916  _In_ _Printf_format_string_ PWSTR Format,
1917  _In_ va_list ArgPtr
1918  );
1919 
1920 PHLIBAPI
1921 NTSTATUS
1922 NTAPI
1924  _Inout_ PPH_FILE_STREAM FileStream,
1925  _In_ _Printf_format_string_ PWSTR Format,
1926  ...
1927  );
1928 
1929 // provider
1930 
1931 #if defined(DEBUG)
1932 extern PPH_LIST PhDbgProviderList;
1933 extern PH_QUEUED_LOCK PhDbgProviderListLock;
1934 #endif
1935 
1942 
1943 typedef VOID (NTAPI *PPH_PROVIDER_FUNCTION)(
1944  _In_ PVOID Object
1945  );
1947 struct _PH_PROVIDER_THREAD;
1949 
1952  LIST_ENTRY ListEntry;
1953  PPH_PROVIDER_THREAD ProviderThread;
1955  PVOID Object;
1956  ULONG RunId;
1957  BOOLEAN Enabled;
1958  BOOLEAN Unregistering;
1959  BOOLEAN Boosting;
1961 
1962 typedef struct _PH_PROVIDER_THREAD
1965  HANDLE TimerHandle;
1966  ULONG Interval;
1970  LIST_ENTRY ListHead;
1971  ULONG BoostCount;
1973 
1974 PHLIBAPI
1975 VOID
1976 NTAPI
1978  _Out_ PPH_PROVIDER_THREAD ProviderThread,
1979  _In_ ULONG Interval
1980  );
1981 
1982 PHLIBAPI
1983 VOID
1984 NTAPI
1986  _Inout_ PPH_PROVIDER_THREAD ProviderThread
1987  );
1988 
1989 PHLIBAPI
1990 VOID
1991 NTAPI
1993  _Inout_ PPH_PROVIDER_THREAD ProviderThread
1994  );
1995 
1996 PHLIBAPI
1997 VOID
1998 NTAPI
2000  _Inout_ PPH_PROVIDER_THREAD ProviderThread
2001  );
2002 
2003 PHLIBAPI
2004 VOID
2005 NTAPI
2007  _Inout_ PPH_PROVIDER_THREAD ProviderThread,
2008  _In_ ULONG Interval
2009  );
2010 
2011 PHLIBAPI
2012 VOID
2013 NTAPI
2015  _Inout_ PPH_PROVIDER_THREAD ProviderThread,
2016  _In_ PPH_PROVIDER_FUNCTION Function,
2017  _In_opt_ PVOID Object,
2018  _Out_ PPH_PROVIDER_REGISTRATION Registration
2019  );
2020 
2021 PHLIBAPI
2022 VOID
2023 NTAPI
2025  _Inout_ PPH_PROVIDER_REGISTRATION Registration
2026  );
2027 
2028 PHLIBAPI
2029 BOOLEAN
2030 NTAPI
2032  _Inout_ PPH_PROVIDER_REGISTRATION Registration,
2033  _Out_opt_ PULONG FutureRunId
2034  );
2035 
2036 PHLIBAPI
2037 ULONG
2038 NTAPI
2040  _In_ PPH_PROVIDER_REGISTRATION Registration
2041  );
2042 
2043 PHLIBAPI
2044 BOOLEAN
2045 NTAPI
2047  _In_ PPH_PROVIDER_REGISTRATION Registration
2048  );
2049 
2050 PHLIBAPI
2051 VOID
2052 NTAPI
2054  _Inout_ PPH_PROVIDER_REGISTRATION Registration,
2055  _In_ BOOLEAN Enabled
2056  );
2057 
2058 // svcsup
2059 
2060 extern WCHAR *PhServiceTypeStrings[6];
2061 extern WCHAR *PhServiceStartTypeStrings[5];
2062 extern WCHAR *PhServiceErrorControlStrings[4];
2063 
2064 PHLIBAPI
2065 PVOID
2066 NTAPI
2068  _In_ SC_HANDLE ScManagerHandle,
2069  _In_opt_ ULONG Type,
2070  _In_opt_ ULONG State,
2071  _Out_ PULONG Count
2072  );
2073 
2074 PHLIBAPI
2075 SC_HANDLE
2076 NTAPI
2078  _In_ PWSTR ServiceName,
2079  _In_ ACCESS_MASK DesiredAccess
2080  );
2081 
2082 PHLIBAPI
2083 PVOID
2084 NTAPI
2086  _In_ SC_HANDLE ServiceHandle
2087  );
2088 
2089 PHLIBAPI
2090 PVOID
2091 NTAPI
2093  _In_ SC_HANDLE ServiceHandle,
2094  _In_ ULONG InfoLevel
2095  );
2096 
2097 PHLIBAPI
2098 PPH_STRING
2099 NTAPI
2101  _In_ SC_HANDLE ServiceHandle
2102  );
2103 
2104 PHLIBAPI
2105 BOOLEAN
2106 NTAPI
2108  _In_ SC_HANDLE ServiceHandle,
2109  _Out_ PBOOLEAN DelayedAutoStart
2110  );
2111 
2112 PHLIBAPI
2113 BOOLEAN
2114 NTAPI
2116  _In_ SC_HANDLE ServiceHandle,
2117  _In_ BOOLEAN DelayedAutoStart
2118  );
2119 
2120 PHLIBAPI
2121 PWSTR
2122 NTAPI
2124  _In_ ULONG ServiceState
2125  );
2126 
2127 PHLIBAPI
2128 PWSTR
2129 NTAPI
2131  _In_ ULONG ServiceType
2132  );
2133 
2134 PHLIBAPI
2135 ULONG
2136 NTAPI
2138  _In_ PWSTR ServiceType
2139  );
2140 
2141 PHLIBAPI
2142 PWSTR
2143 NTAPI
2145  _In_ ULONG ServiceStartType
2146  );
2147 
2148 PHLIBAPI
2149 ULONG
2150 NTAPI
2152  _In_ PWSTR ServiceStartType
2153  );
2154 
2155 PHLIBAPI
2156 PWSTR
2157 NTAPI
2159  _In_ ULONG ServiceErrorControl
2160  );
2161 
2162 PHLIBAPI
2163 ULONG
2164 NTAPI
2166  _In_ PWSTR ServiceErrorControl
2167  );
2168 
2169 PHLIBAPI
2170 PPH_STRING
2171 NTAPI
2173  _In_ HANDLE ProcessId,
2174  _In_ PVOID ServiceTag
2175  );
2176 
2177 PHLIBAPI
2178 NTSTATUS
2179 NTAPI
2181  _In_ HANDLE ThreadHandle,
2182  _In_opt_ HANDLE ProcessHandle,
2183  _Out_ PVOID *ServiceTag
2184  );
2185 
2186 NTSTATUS
2187 NTAPI
2190  _Out_ PPH_STRING *ServiceDll
2191  );
2192 
2193 // support
2194 
2195 extern WCHAR *PhSizeUnitNames[7];
2196 extern ULONG PhMaxSizeUnit;
2197 
2198 typedef struct _PH_INTEGER_PAIR
2200  LONG X;
2201  LONG Y;
2203 
2204 typedef struct _PH_RECTANGLE
2205 {
2206  union
2207  {
2209  struct
2210  {
2211  LONG Left;
2212  LONG Top;
2213  };
2214  };
2215  union
2216  {
2218  struct
2219  {
2220  LONG Width;
2221  LONG Height;
2222  };
2223  };
2225 
2226 FORCEINLINE
2229  _In_ RECT Rect
2230  )
2231 {
2232  PH_RECTANGLE rectangle;
2233 
2234  rectangle.Left = Rect.left;
2235  rectangle.Top = Rect.top;
2236  rectangle.Width = Rect.right - Rect.left;
2237  rectangle.Height = Rect.bottom - Rect.top;
2238 
2239  return rectangle;
2240 }
2241 
2242 FORCEINLINE
2243 RECT
2245  _In_ PH_RECTANGLE Rectangle
2246  )
2247 {
2248  RECT rect;
2249 
2250  rect.left = Rectangle.Left;
2251  rect.top = Rectangle.Top;
2252  rect.right = Rectangle.Left + Rectangle.Width;
2253  rect.bottom = Rectangle.Top + Rectangle.Height;
2254 
2255  return rect;
2256 }
2257 
2258 FORCEINLINE
2259 VOID
2261  _Inout_ PRECT Rect,
2262  _In_ PRECT ParentRect
2263  )
2264 {
2265  Rect->right = ParentRect->right - ParentRect->left - Rect->right;
2266  Rect->bottom = ParentRect->bottom - ParentRect->top - Rect->bottom;
2267 }
2268 
2269 FORCEINLINE
2270 RECT
2271 PhMapRect(
2272  _In_ RECT InnerRect,
2273  _In_ RECT OuterRect
2274  )
2275 {
2276  RECT rect;
2277 
2278  rect.left = InnerRect.left - OuterRect.left;
2279  rect.top = InnerRect.top - OuterRect.top;
2280  rect.right = InnerRect.right - OuterRect.left;
2281  rect.bottom = InnerRect.bottom - OuterRect.top;
2282 
2283  return rect;
2284 }
2285 
2286 PHLIBAPI
2287 VOID
2288 NTAPI
2290  _Inout_ PPH_RECTANGLE Rectangle,
2291  _In_ PPH_RECTANGLE Bounds
2292  );
2293 
2294 PHLIBAPI
2295 VOID
2296 NTAPI
2298  _Inout_ PPH_RECTANGLE Rectangle,
2299  _In_ PPH_RECTANGLE Bounds
2300  );
2301 
2302 PHLIBAPI
2303 VOID
2304 NTAPI
2306  _In_ HWND hWnd,
2307  _Inout_ PPH_RECTANGLE Rectangle
2308  );
2309 
2310 PHLIBAPI
2311 VOID
2312 NTAPI
2314  _In_ HWND WindowHandle,
2315  _In_opt_ HWND ParentWindowHandle
2316  );
2317 
2318 FORCEINLINE
2319 VOID
2321  _Out_ PSYSTEMTIME SystemTime,
2322  _In_ PLARGE_INTEGER LargeInteger
2323  )
2324 {
2325  FILETIME fileTime;
2326 
2327  fileTime.dwLowDateTime = LargeInteger->LowPart;
2328  fileTime.dwHighDateTime = LargeInteger->HighPart;
2329  FileTimeToSystemTime(&fileTime, SystemTime);
2330 }
2331 
2332 FORCEINLINE
2333 VOID
2335  _Out_ PSYSTEMTIME SystemTime,
2336  _In_ PLARGE_INTEGER LargeInteger
2337  )
2338 {
2339  FILETIME fileTime;
2340  FILETIME newFileTime;
2341 
2342  fileTime.dwLowDateTime = LargeInteger->LowPart;
2343  fileTime.dwHighDateTime = LargeInteger->HighPart;
2344  FileTimeToLocalFileTime(&fileTime, &newFileTime);
2345  FileTimeToSystemTime(&newFileTime, SystemTime);
2346 }
2347 
2348 PHLIBAPI
2349 VOID
2350 NTAPI
2352  _In_reads_(NumberOfObjects) PVOID *Objects,
2353  _In_ ULONG NumberOfObjects
2354  );
2355 
2356 PHLIBAPI
2357 VOID
2358 NTAPI
2360  _In_reads_(NumberOfObjects) PVOID *Objects,
2361  _In_ ULONG NumberOfObjects
2362  );
2363 
2364 PHLIBAPI
2365 PPH_STRING
2366 NTAPI
2367 PhGetMessage(
2368  _In_ PVOID DllHandle,
2369  _In_ ULONG MessageTableId,
2370  _In_ ULONG MessageLanguageId,
2371  _In_ ULONG MessageId
2372  );
2373 
2374 PHLIBAPI
2375 PPH_STRING
2376 NTAPI
2378  _In_ NTSTATUS Status
2379  );
2380 
2381 PHLIBAPI
2382 PPH_STRING
2383 NTAPI
2385  _In_ ULONG Result
2386  );
2387 
2388 #define PH_MAX_MESSAGE_SIZE 800
2389 
2390 PHLIBAPI
2391 INT
2392 NTAPI
2394  _In_ HWND hWnd,
2395  _In_ ULONG Type,
2396  _In_ PWSTR Format,
2397  ...
2398  );
2399 
2400 PHLIBAPI
2401 INT
2402 NTAPI
2404  _In_ HWND hWnd,
2405  _In_ ULONG Type,
2406  _In_ PWSTR Format,
2407  _In_ va_list ArgPtr
2408  );
2410 #define PhShowError(hWnd, Format, ...) PhShowMessage(hWnd, MB_OK | MB_ICONERROR, Format, __VA_ARGS__)
2411 #define PhShowWarning(hWnd, Format, ...) PhShowMessage(hWnd, MB_OK | MB_ICONWARNING, Format, __VA_ARGS__)
2412 #define PhShowInformation(hWnd, Format, ...) PhShowMessage(hWnd, MB_OK | MB_ICONINFORMATION, Format, __VA_ARGS__)
2413 
2414 PPH_STRING
2415 NTAPI
2417  _In_ NTSTATUS Status,
2418  _In_opt_ ULONG Win32Result
2419  );
2420 
2421 PHLIBAPI
2422 VOID
2423 NTAPI
2424 PhShowStatus(
2425  _In_ HWND hWnd,
2426  _In_opt_ PWSTR Message,
2427  _In_ NTSTATUS Status,
2428  _In_opt_ ULONG Win32Result
2429  );
2430 
2431 PHLIBAPI
2432 BOOLEAN
2433 NTAPI
2435  _In_ HWND hWnd,
2436  _In_opt_ PWSTR Message,
2437  _In_ NTSTATUS Status,
2438  _In_opt_ ULONG Win32Result
2439  );
2440 
2441 PHLIBAPI
2442 BOOLEAN
2443 NTAPI
2445  _In_ HWND hWnd,
2446  _In_ PWSTR Verb,
2447  _In_ PWSTR Object,
2448  _In_opt_ PWSTR Message,
2449  _In_ BOOLEAN Warning
2450  );
2451 
2452 PHLIBAPI
2453 BOOLEAN
2454 NTAPI
2456  _In_ PPH_KEY_VALUE_PAIR KeyValuePairs,
2457  _In_ ULONG SizeOfKeyValuePairs,
2458  _In_ PWSTR String,
2459  _Out_ PULONG Integer
2460  );
2461 
2462 PHLIBAPI
2463 BOOLEAN
2464 NTAPI
2466  _In_ PPH_KEY_VALUE_PAIR KeyValuePairs,
2467  _In_ ULONG SizeOfKeyValuePairs,
2468  _In_ ULONG Integer,
2469  _Out_ PWSTR *String
2470  );
2472 #define GUID_VERSION_MAC 1
2473 #define GUID_VERSION_DCE 2
2474 #define GUID_VERSION_MD5 3
2475 #define GUID_VERSION_RANDOM 4
2476 #define GUID_VERSION_SHA1 5
2478 #define GUID_VARIANT_NCS_MASK 0x80
2479 #define GUID_VARIANT_NCS 0x00
2480 #define GUID_VARIANT_STANDARD_MASK 0xc0
2481 #define GUID_VARIANT_STANDARD 0x80
2482 #define GUID_VARIANT_MICROSOFT_MASK 0xe0
2483 #define GUID_VARIANT_MICROSOFT 0xc0
2484 #define GUID_VARIANT_RESERVED_MASK 0xe0
2485 #define GUID_VARIANT_RESERVED 0xe0
2486 
2487 typedef union _GUID_EX
2489  GUID Guid;
2490  UCHAR Data[16];
2491  struct
2492  {
2494  USHORT TimeMidPart;
2497  UCHAR ClockSequenceLow;
2498  UCHAR Node[6];
2499  } s;
2500  struct
2501  {
2502  ULONG Part0;
2503  USHORT Part32;
2504  UCHAR Part48;
2505  UCHAR Part56 : 4;
2506  UCHAR Version : 4;
2507  UCHAR Variant;
2508  UCHAR Part72;
2509  USHORT Part80;
2510  ULONG Part96;
2511  } s2;
2512 } GUID_EX, *PGUID_EX;
2513 
2514 PHLIBAPI
2515 VOID
2516 NTAPI
2518  _Out_ PGUID Guid
2519  );
2520 
2521 PHLIBAPI
2522 VOID
2523 NTAPI
2525  _Out_ PGUID Guid,
2526  _In_ PGUID Namespace,
2527  _In_ PCHAR Name,
2528  _In_ ULONG NameLength,
2529  _In_ UCHAR Version
2530  );
2531 
2532 PHLIBAPI
2533 VOID
2534 NTAPI
2536  _Out_writes_z_(Count) PWSTR Buffer,
2537  _In_ ULONG Count
2538  );
2539 
2540 PHLIBAPI
2541 PPH_STRING
2542 NTAPI
2544  _In_ PPH_STRING String,
2545  _In_ ULONG DesiredCount
2546  );
2547 
2548 PHLIBAPI
2549 PPH_STRING
2550 NTAPI
2552  _In_ PPH_STRING String,
2553  _In_ ULONG DesiredCount
2554  );
2555 
2556 PHLIBAPI
2557 BOOLEAN
2558 NTAPI
2560  _In_ PWSTR Pattern,
2561  _In_ PWSTR String,
2562  _In_ BOOLEAN IgnoreCase
2563  );
2564 
2565 PHLIBAPI
2566 PPH_STRING
2567 NTAPI
2569  _In_ PPH_STRINGREF String
2570  );
2571 
2572 PHLIBAPI
2573 LONG
2574 NTAPI
2576  _In_ PWSTR A,
2577  _In_ PWSTR B,
2578  _In_ BOOLEAN IgnoreCase,
2579  _In_ BOOLEAN MatchIfPrefix
2580  );
2581 
2582 PHLIBAPI
2583 PPH_STRING
2584 NTAPI
2585 PhFormatDate(
2586  _In_opt_ PSYSTEMTIME Date,
2587  _In_opt_ PWSTR Format
2588  );
2589 
2590 PHLIBAPI
2591 PPH_STRING
2592 NTAPI
2593 PhFormatTime(
2594  _In_opt_ PSYSTEMTIME Time,
2595  _In_opt_ PWSTR Format
2596  );
2597 
2598 PHLIBAPI
2599 PPH_STRING
2600 NTAPI
2602  _In_opt_ PSYSTEMTIME DateTime
2603  );
2604 
2605 #define PhaFormatDateTime(DateTime) \
2606  ((PPH_STRING)PhAutoDereferenceObject(PhFormatDateTime(DateTime)))
2607 
2608 PHLIBAPI
2609 PPH_STRING
2610 NTAPI
2612  _In_ ULONG64 TimeSpan
2613  );
2614 
2615 PHLIBAPI
2616 PPH_STRING
2617 NTAPI
2619  _In_ ULONG64 Value,
2620  _In_ BOOLEAN GroupDigits
2621  );
2622 
2623 #define PhaFormatUInt64(Value, GroupDigits) \
2624  ((PPH_STRING)PhAutoDereferenceObject(PhFormatUInt64((Value), (GroupDigits))))
2625 
2626 PHLIBAPI
2627 PPH_STRING
2628 NTAPI
2630  _In_ PWSTR Value,
2631  _In_ ULONG FractionalDigits,
2632  _In_ BOOLEAN GroupDigits
2633  );
2634 
2635 #define PhaFormatDecimal(Value, FractionalDigits, GroupDigits) \
2636  ((PPH_STRING)PhAutoDereferenceObject(PhFormatDecimal((Value), (FractionalDigits), (GroupDigits))))
2637 
2638 PHLIBAPI
2639 PPH_STRING
2640 NTAPI
2641 PhFormatSize(
2642  _In_ ULONG64 Size,
2643  _In_ ULONG MaxSizeUnit
2644  );
2645 
2646 #define PhaFormatSize(Size, MaxSizeUnit) \
2647  ((PPH_STRING)PhAutoDereferenceObject(PhFormatSize((Size), (MaxSizeUnit))))
2648 
2649 PHLIBAPI
2650 PPH_STRING
2651 NTAPI
2652 PhFormatGuid(
2653  _In_ PGUID Guid
2654  );
2655 
2656 PHLIBAPI
2657 PVOID
2658 NTAPI
2660  _In_ PWSTR FileName
2661  );
2662 
2663 PHLIBAPI
2664 ULONG
2665 NTAPI
2667  _In_ PVOID VersionInfo
2668  );
2669 
2670 PHLIBAPI
2671 PPH_STRING
2672 NTAPI
2674  _In_ PVOID VersionInfo,
2675  _In_ PWSTR SubBlock
2676  );
2677 
2678 PHLIBAPI
2679 PPH_STRING
2680 NTAPI
2682  _In_ PVOID VersionInfo,
2683  _In_ ULONG LangCodePage,
2684  _In_ PWSTR StringName
2685  );
2686 
2694 
2695 PHLIBAPI
2696 BOOLEAN
2697 NTAPI
2699  _Out_ PPH_IMAGE_VERSION_INFO ImageVersionInfo,
2700  _In_ PWSTR FileName
2701  );
2702 
2703 PHLIBAPI
2704 VOID
2705 NTAPI
2707  _Inout_ PPH_IMAGE_VERSION_INFO ImageVersionInfo
2708  );
2709 
2710 PHLIBAPI
2711 PPH_STRING
2712 NTAPI
2714  _In_opt_ PPH_STRING FileName,
2715  _In_ PPH_IMAGE_VERSION_INFO ImageVersionInfo,
2716  _In_opt_ PPH_STRINGREF Indent,
2717  _In_opt_ ULONG LineLimit
2718  );
2719 
2720 PHLIBAPI
2721 PPH_STRING
2722 NTAPI
2724  _In_ PWSTR FileName,
2725  _Out_opt_ PULONG IndexOfFileName
2726  );
2727 
2728 PHLIBAPI
2729 PPH_STRING
2730 NTAPI
2732  _In_ PPH_STRINGREF String
2733  );
2734 
2735 PHLIBAPI
2736 PPH_STRING
2737 NTAPI
2739  _In_ PPH_STRING FileName
2740  );
2741 
2742 PHLIBAPI
2743 PPH_STRING
2744 NTAPI
2746  VOID
2747  );
2748 
2749 PHLIBAPI
2750 VOID
2751 NTAPI
2753  _Out_ PPH_STRINGREF SystemRoot
2754  );
2755 
2756 PHLIBAPI
2757 PLDR_DATA_TABLE_ENTRY
2758 NTAPI
2760  _In_opt_ PVOID DllBase,
2761  _In_opt_ PPH_STRINGREF FullDllName,
2762  _In_opt_ PPH_STRINGREF BaseDllName
2763  );
2764 
2765 PHLIBAPI
2766 PPH_STRING
2767 NTAPI
2769  _In_ PVOID DllHandle,
2770  _Out_opt_ PULONG IndexOfFileName
2771  );
2772 
2773 PHLIBAPI
2774 PPH_STRING
2775 NTAPI
2777  VOID
2778  );
2779 
2780 PHLIBAPI
2781 PPH_STRING
2782 NTAPI
2784  VOID
2785  );
2786 
2787 PHLIBAPI
2788 PPH_STRING
2789 NTAPI
2791  _In_ ULONG Folder,
2792  _In_opt_ PWSTR AppendPath
2793  );
2794 
2795 PHLIBAPI
2796 NTSTATUS
2797 NTAPI
2799  _In_opt_ HWND hWnd,
2800  _In_ ULONG NumberOfHandles,
2801  _In_ PHANDLE Handles,
2802  _In_ ULONG Timeout
2803  );
2804 
2814 #define PH_CREATE_PROCESS_INHERIT_HANDLES 0x1
2815 #define PH_CREATE_PROCESS_UNICODE_ENVIRONMENT 0x2
2816 #define PH_CREATE_PROCESS_SUSPENDED 0x4
2817 #define PH_CREATE_PROCESS_BREAKAWAY_FROM_JOB 0x8
2818 #define PH_CREATE_PROCESS_NEW_CONSOLE 0x10
2819 
2820 PHLIBAPI
2821 NTSTATUS
2822 NTAPI
2824  _In_ PWSTR FileName,
2825  _In_opt_ PPH_STRINGREF CommandLine,
2826  _In_opt_ PVOID Environment,
2827  _In_opt_ PPH_STRINGREF CurrentDirectory,
2828  _In_opt_ PPH_CREATE_PROCESS_INFO Information,
2829  _In_ ULONG Flags,
2830  _In_opt_ HANDLE ParentProcessHandle,
2831  _Out_opt_ PCLIENT_ID ClientId,
2832  _Out_opt_ PHANDLE ProcessHandle,
2833  _Out_opt_ PHANDLE ThreadHandle
2834  );
2835 
2836 PHLIBAPI
2837 NTSTATUS
2838 NTAPI
2840  _In_opt_ PWSTR FileName,
2841  _In_opt_ PWSTR CommandLine,
2842  _In_opt_ PVOID Environment,
2843  _In_opt_ PWSTR CurrentDirectory,
2844  _In_ ULONG Flags,
2845  _In_opt_ HANDLE TokenHandle,
2846  _Out_opt_ PHANDLE ProcessHandle,
2847  _Out_opt_ PHANDLE ThreadHandle
2848  );
2849 
2850 PHLIBAPI
2851 NTSTATUS
2852 NTAPI
2854  _In_opt_ PWSTR FileName,
2855  _In_opt_ PWSTR CommandLine,
2856  _In_opt_ PVOID Environment,
2857  _In_opt_ PWSTR CurrentDirectory,
2858  _In_opt_ STARTUPINFO *StartupInfo,
2859  _In_ ULONG Flags,
2860  _In_opt_ HANDLE TokenHandle,
2861  _Out_opt_ PCLIENT_ID ClientId,
2862  _Out_opt_ PHANDLE ProcessHandle,
2863  _Out_opt_ PHANDLE ThreadHandle
2864  );
2865 
2868  _In_opt_ PWSTR ApplicationName;
2869  _In_opt_ PWSTR CommandLine;
2870  _In_opt_ PWSTR CurrentDirectory;
2871  _In_opt_ PVOID Environment;
2872  _In_opt_ PWSTR DesktopName;
2873  _In_opt_ ULONG SessionId; // use PH_CREATE_PROCESS_SET_SESSION_ID
2874  union
2875  {
2876  struct
2877  {
2878  _In_ PWSTR DomainName;
2879  _In_ PWSTR UserName;
2880  _In_ PWSTR Password;
2881  _In_opt_ ULONG LogonType;
2882  };
2883  _In_ HANDLE ProcessIdWithToken; // use PH_CREATE_PROCESS_USE_PROCESS_TOKEN
2884  _In_ ULONG SessionIdWithToken; // use PH_CREATE_PROCESS_USE_SESSION_TOKEN
2885  };
2888 #define PH_CREATE_PROCESS_USE_PROCESS_TOKEN 0x1000
2889 #define PH_CREATE_PROCESS_USE_SESSION_TOKEN 0x2000
2890 #define PH_CREATE_PROCESS_USE_LINKED_TOKEN 0x10000
2891 #define PH_CREATE_PROCESS_SET_SESSION_ID 0x20000
2892 #define PH_CREATE_PROCESS_WITH_PROFILE 0x40000
2893 
2894 PHLIBAPI
2895 NTSTATUS
2896 NTAPI
2898  _In_ PPH_CREATE_PROCESS_AS_USER_INFO Information,
2899  _In_ ULONG Flags,
2900  _Out_opt_ PCLIENT_ID ClientId,
2901  _Out_opt_ PHANDLE ProcessHandle,
2902  _Out_opt_ PHANDLE ThreadHandle
2903  );
2904 
2905 NTSTATUS
2906 NTAPI
2908  _In_ HANDLE TokenHandle,
2909  _Out_ PHANDLE NewTokenHandle
2910  );
2911 
2912 PHLIBAPI
2913 VOID
2914 NTAPI
2916  _In_ HWND hWnd,
2917  _In_ PWSTR FileName,
2918  _In_opt_ PWSTR Parameters
2919  );
2921 #define PH_SHELL_EXECUTE_ADMIN 0x1
2922 #define PH_SHELL_EXECUTE_PUMP_MESSAGES 0x2
2923 
2924 PHLIBAPI
2925 BOOLEAN
2926 NTAPI
2928  _In_opt_ HWND hWnd,
2929  _In_ PWSTR FileName,
2930  _In_opt_ PWSTR Parameters,
2931  _In_ ULONG ShowWindowType,
2932  _In_ ULONG Flags,
2933  _In_opt_ ULONG Timeout,
2934  _Out_opt_ PHANDLE ProcessHandle
2935  );
2936 
2937 PHLIBAPI
2938 VOID
2939 NTAPI
2941  _In_ HWND hWnd,
2942  _In_ PWSTR FileName
2943  );
2944 
2945 PHLIBAPI
2946 VOID
2947 NTAPI
2949  _In_ HWND hWnd,
2950  _In_ PWSTR FileName
2951  );
2952 
2953 PPH_STRING
2954 NTAPI
2956  _In_ PPH_STRING KeyName,
2957  _In_ BOOLEAN Computer
2958  );
2959 
2960 PHLIBAPI
2961 VOID
2962 NTAPI
2964  _In_ HWND hWnd,
2965  _In_ PPH_STRING KeyName
2966  );
2967 
2969 NTAPI
2971  _In_ HANDLE KeyHandle,
2972  _In_opt_ PWSTR ValueName
2973  );
2974 
2975 PHLIBAPI
2976 PPH_STRING
2977 NTAPI
2979  _In_ HANDLE KeyHandle,
2980  _In_opt_ PWSTR ValueName
2981  );
2982 
2983 typedef struct _PH_FLAG_MAPPING
2985  ULONG Flag1;
2986  ULONG Flag2;
2988 
2989 PHLIBAPI
2990 VOID
2991 NTAPI
2992 PhMapFlags1(
2993  _Inout_ PULONG Value2,
2994  _In_ ULONG Value1,
2995  _In_ const PH_FLAG_MAPPING *Mappings,
2996  _In_ ULONG NumberOfMappings
2997  );
2998 
2999 PHLIBAPI
3000 VOID
3001 NTAPI
3002 PhMapFlags2(
3003  _Inout_ PULONG Value1,
3004  _In_ ULONG Value2,
3005  _In_ const PH_FLAG_MAPPING *Mappings,
3006  _In_ ULONG NumberOfMappings
3007  );
3008 
3009 PHLIBAPI
3010 PVOID
3011 NTAPI
3013  VOID
3014  );
3015 
3016 PHLIBAPI
3017 PVOID
3018 NTAPI
3020  VOID
3021  );
3022 
3023 PHLIBAPI
3024 VOID
3025 NTAPI
3027  _In_ PVOID FileDialog
3028  );
3029 
3030 PHLIBAPI
3031 BOOLEAN
3032 NTAPI
3034  _In_ HWND hWnd,
3035  _In_ PVOID FileDialog
3036  );
3038 #define PH_FILEDIALOG_CREATEPROMPT 0x1
3039 #define PH_FILEDIALOG_PATHMUSTEXIST 0x2 // default both
3040 #define PH_FILEDIALOG_FILEMUSTEXIST 0x4 // default open
3041 #define PH_FILEDIALOG_SHOWHIDDEN 0x8
3042 #define PH_FILEDIALOG_NODEREFERENCELINKS 0x10
3043 #define PH_FILEDIALOG_OVERWRITEPROMPT 0x20 // default save
3044 #define PH_FILEDIALOG_DEFAULTEXPANDED 0x40
3045 #define PH_FILEDIALOG_STRICTFILETYPES 0x80
3046 #define PH_FILEDIALOG_PICKFOLDERS 0x100
3047 
3048 PHLIBAPI
3049 ULONG
3050 NTAPI
3052  _In_ PVOID FileDialog
3053  );
3054 
3055 PHLIBAPI
3056 VOID
3057 NTAPI
3059  _In_ PVOID FileDialog,
3060  _In_ ULONG Options
3061  );
3062 
3063 PHLIBAPI
3064 ULONG
3065 NTAPI
3067  _In_ PVOID FileDialog
3068  );
3069 
3070 typedef struct _PH_FILETYPE_FILTER
3072  PWSTR Name;
3073  PWSTR Filter;
3075 
3076 PHLIBAPI
3077 VOID
3078 NTAPI
3080  _In_ PVOID FileDialog,
3081  _In_ PPH_FILETYPE_FILTER Filters,
3082  _In_ ULONG NumberOfFilters
3083  );
3084 
3085 PHLIBAPI
3086 PPH_STRING
3087 NTAPI
3089  _In_ PVOID FileDialog
3090  );
3091 
3092 PHLIBAPI
3093 VOID
3094 NTAPI
3096  _In_ PVOID FileDialog,
3097  _In_ PWSTR FileName
3098  );
3099 
3100 PHLIBAPI
3101 NTSTATUS
3102 NTAPI
3104  _In_ PWSTR FileName,
3105  _Out_ PBOOLEAN IsPacked,
3106  _Out_opt_ PULONG NumberOfModules,
3107  _Out_opt_ PULONG NumberOfFunctions
3108  );
3109 
3110 ULONG
3111 NTAPI
3112 PhCrc32(
3113  _In_ ULONG Crc,
3114  _In_reads_(Length) PCHAR Buffer,
3115  _In_ SIZE_T Length
3116  );
3117 
3124 
3125 typedef struct _PH_HASH_CONTEXT
3128  ULONG Context[64];
3130 
3131 PHLIBAPI
3132 VOID
3133 NTAPI
3135  _Out_ PPH_HASH_CONTEXT Context,
3136  _In_ PH_HASH_ALGORITHM Algorithm
3137  );
3138 
3139 PHLIBAPI
3140 VOID
3141 NTAPI
3142 PhUpdateHash(
3143  _Inout_ PPH_HASH_CONTEXT Context,
3144  _In_reads_bytes_(Length) PVOID Buffer,
3145  _In_ ULONG Length
3146  );
3147 
3148 PHLIBAPI
3149 BOOLEAN
3150 NTAPI
3151 PhFinalHash(
3152  _Inout_ PPH_HASH_CONTEXT Context,
3153  _Out_writes_bytes_(HashLength) PVOID Hash,
3154  _In_ ULONG HashLength,
3155  _Out_opt_ PULONG ReturnLength
3156  );
3157 
3164 
3167  ULONG Id;
3168  PWSTR Name;
3171 
3172 typedef BOOLEAN (NTAPI *PPH_COMMAND_LINE_CALLBACK)(
3173  _In_opt_ PPH_COMMAND_LINE_OPTION Option,
3174  _In_opt_ PPH_STRING Value,
3175  _In_opt_ PVOID Context
3176  );
3178 #define PH_COMMAND_LINE_IGNORE_UNKNOWN_OPTIONS 0x1
3179 #define PH_COMMAND_LINE_IGNORE_FIRST_PART 0x2
3180 
3181 PHLIBAPI
3182 PPH_STRING
3183 NTAPI
3185  _In_ PPH_STRINGREF CommandLine,
3186  _Inout_ PULONG_PTR Index
3187  );
3188 
3189 PHLIBAPI
3190 BOOLEAN
3191 NTAPI
3193  _In_ PPH_STRINGREF CommandLine,
3194  _In_opt_ PPH_COMMAND_LINE_OPTION Options,
3195  _In_ ULONG NumberOfOptions,
3196  _In_ ULONG Flags,
3197  _In_ PPH_COMMAND_LINE_CALLBACK Callback,
3198  _In_opt_ PVOID Context
3199  );
3200 
3201 PHLIBAPI
3202 PPH_STRING
3203 NTAPI
3205  _In_ PPH_STRINGREF String
3206  );
3207 
3208 PHLIBAPI
3209 BOOLEAN
3210 NTAPI
3212  _In_ PPH_STRINGREF CommandLine,
3213  _Out_ PPH_STRINGREF FileName,
3214  _Out_ PPH_STRINGREF Arguments,
3215  _Out_opt_ PPH_STRING *FullFileName
3216  );
3217 
3218 #ifdef __cplusplus
3219 }
3220 #endif
3221 
3222 #endif