6 #ifndef PHLIB_NO_DEFAULT_LIB
7 #pragma comment(lib, "ntdll.lib")
9 #pragma comment(lib, "comctl32.lib")
10 #pragma comment(lib, "version.lib")
14 #pragma warning(disable: 4201)
16 #pragma warning(disable: 4214)
18 #pragma warning(disable: 4985)
20 #pragma warning(disable: 4996)
26 #if defined(PHLIB_EXPORT)
27 #define PHLIBAPI __declspec(dllexport)
28 #elif defined(PHLIB_IMPORT)
29 #define PHLIBAPI __declspec(dllimport)
75 #define WINDOWS_ANCIENT 0
77 #define WINDOWS_SERVER_2003 52
78 #define WINDOWS_VISTA 60
81 #define WINDOWS_8_1 63
82 #define WINDOWS_10 100
83 #define WINDOWS_NEW MAXLONG
85 #define WINDOWS_HAS_CONSOLE_HOST (WindowsVersion >= WINDOWS_7)
86 #define WINDOWS_HAS_CYCLE_TIME (WindowsVersion >= WINDOWS_VISTA)
87 #define WINDOWS_HAS_IFILEDIALOG (WindowsVersion >= WINDOWS_VISTA)
88 #define WINDOWS_HAS_IMAGE_FILE_NAME_BY_PROCESS_ID (WindowsVersion >= WINDOWS_VISTA)
89 #define WINDOWS_HAS_IMMERSIVE (WindowsVersion >= WINDOWS_8)
90 #define WINDOWS_HAS_LIMITED_ACCESS (WindowsVersion >= WINDOWS_VISTA)
91 #define WINDOWS_HAS_PSSUSPENDRESUMEPROCESS (WindowsVersion >= WINDOWS_VISTA)
92 #define WINDOWS_HAS_SERVICE_TAGS (WindowsVersion >= WINDOWS_VISTA)
93 #define WINDOWS_HAS_UAC (WindowsVersion >= WINDOWS_VISTA)
98 #define dprintf(format, ...) DbgPrint(format, __VA_ARGS__)
100 #define dprintf(format, ...)
111 #define PHLIB_INIT_MODULE_RESERVED1 0x1
112 #define PHLIB_INIT_MODULE_RESERVED2 0x2
114 #define PHLIB_INIT_MODULE_WORK_QUEUE 0x4
116 #define PHLIB_INIT_MODULE_HANDLE_TABLE 0x8
118 #define PHLIB_INIT_MODULE_IO_SUPPORT 0x10
120 #define PHLIB_INIT_MODULE_SYMBOL_PROVIDER 0x20
121 #define PHLIB_INIT_MODULE_RESERVED3 0x40
125 #define PHLIB_INIT_TOKEN_INFO 0x100000
135 _In_opt_ SIZE_T HeapReserveSize,
136 _In_opt_ SIZE_T HeapCommitSize
171 typedef struct _PHP_BASE_THREAD_DBG
174 LIST_ENTRY ListEntry;
178 PPH_AUTO_POOL CurrentAutoPool;
179 } PHP_BASE_THREAD_DBG, *PPHP_BASE_THREAD_DBG;
181 extern ULONG PhDbgThreadDbgTlsIndex;
182 extern LIST_ENTRY PhDbgThreadListHead;
190 _In_opt_ SIZE_T StackSize,
192 _In_opt_ PVOID Parameter
208 if (
NT_SUCCESS(LdrGetDllHandle(NULL, NULL, &dllName, &dllHandle)))
217 _In_ PVOID DllHandle,
218 _In_opt_ PSTR ProcedureName,
219 _In_opt_ ULONG ProcedureNumber
224 PVOID procedureAddress;
229 status = LdrGetProcedureAddress(
238 status = LdrGetProcedureAddress(
249 return procedureAddress;
258 _Out_ PLARGE_INTEGER SystemTime
265 _Out_ PLARGE_INTEGER TimeZoneBias
272 _In_ PLARGE_INTEGER SystemTime,
273 _Out_ PLARGE_INTEGER LocalTime
280 _In_ PLARGE_INTEGER LocalTime,
281 _Out_ PLARGE_INTEGER SystemTime
316 _Frees_ptr_opt_ PVOID Memory
325 _Frees_ptr_opt_ PVOID Memory,
344 _Out_opt_ PSIZE_T NewSize
351 _Frees_ptr_opt_ PVOID Memory
363 copy = PhAllocate(Size);
364 memcpy(copy, Data, Size);
371 #define PH_EVENT_SET 0x1
372 #define PH_EVENT_SET_SHIFT 0
373 #define PH_EVENT_REFCOUNT_SHIFT 1
374 #define PH_EVENT_REFCOUNT_INC 0x2
375 #define PH_EVENT_REFCOUNT_MASK (((ULONG_PTR)1 << 15) - 1)
406 #define PH_EVENT_INIT { { PH_EVENT_REFCOUNT_INC }, NULL }
412 _Out_ PPH_EVENT Event
415 #define PhSetEvent PhfSetEvent
420 _Inout_ PPH_EVENT Event
427 _Inout_ PPH_EVENT Event,
428 _In_opt_ PLARGE_INTEGER Timeout
434 _Inout_ PPH_EVENT Event,
435 _In_opt_ PLARGE_INTEGER Timeout
444 #define PhResetEvent PhfResetEvent
449 _Inout_ PPH_EVENT Event
455 _Out_ PPH_EVENT Event
459 Event->EventHandle = NULL;
475 return (BOOLEAN)Event->Set;
480 #define PH_BARRIER_COUNT_SHIFT 0
481 #define PH_BARRIER_COUNT_MASK (((LONG_PTR)1 << (sizeof(ULONG_PTR) * 8 / 2 - 1)) - 1)
482 #define PH_BARRIER_COUNT_INC ((LONG_PTR)1 << PH_BARRIER_COUNT_SHIFT)
483 #define PH_BARRIER_TARGET_SHIFT (sizeof(ULONG_PTR) * 8 / 2)
484 #define PH_BARRIER_TARGET_MASK (((LONG_PTR)1 << (sizeof(ULONG_PTR) * 8 / 2 - 1)) - 1)
485 #define PH_BARRIER_TARGET_INC ((LONG_PTR)1 << PH_BARRIER_TARGET_SHIFT)
486 #define PH_BARRIER_WAKING ((LONG_PTR)1 << (sizeof(ULONG_PTR) * 8 - 1))
488 #define PH_BARRIER_MASTER 1
489 #define PH_BARRIER_SLAVE 2
490 #define PH_BARRIER_OBSERVER 3
498 #define PH_BARRIER_INIT(Target) { (ULONG_PTR)(Target) << PH_BARRIER_TARGET_SHIFT, PH_QUEUED_LOCK_INIT }
504 _Out_ PPH_BARRIER Barrier,
505 _In_ ULONG_PTR Target
508 #define PhWaitForBarrier PhfWaitForBarrier
513 _Inout_ PPH_BARRIER Barrier,
520 _Out_ PPH_BARRIER Barrier,
521 _In_ ULONG_PTR Target
530 #define PH_RUNDOWN_ACTIVE 0x1
531 #define PH_RUNDOWN_REF_SHIFT 1
532 #define PH_RUNDOWN_REF_INC 0x2
539 #define PH_RUNDOWN_PROTECT_INIT { 0 }
551 _Out_ PPH_RUNDOWN_PROTECT Protection
558 _Inout_ PPH_RUNDOWN_PROTECT Protection
565 _Inout_ PPH_RUNDOWN_PROTECT Protection
572 _Inout_ PPH_RUNDOWN_PROTECT Protection
578 _Out_ PPH_RUNDOWN_PROTECT Protection
581 Protection->Value = 0;
587 _Inout_ PPH_RUNDOWN_PROTECT Protection
595 (PVOID *)&Protection->Value,
611 _Inout_ PPH_RUNDOWN_PROTECT Protection
619 (PVOID *)&Protection->Value,
631 _Inout_ PPH_RUNDOWN_PROTECT Protection
637 (PVOID *)&Protection->Value,
648 #define PH_INITONCE_SHIFT 31
649 #define PH_INITONCE_INITIALIZING (0x1 << PH_INITONCE_SHIFT)
650 #define PH_INITONCE_INITIALIZING_SHIFT PH_INITONCE_SHIFT
659 #define PH_INITONCE_INIT { PH_EVENT_INIT }
661 #define PhInitializeInitOnce PhfInitializeInitOnce
666 _Out_ PPH_INITONCE InitOnce
673 _Inout_ PPH_INITONCE InitOnce
676 #define PhEndInitOnce PhfEndInitOnce
681 _Inout_ PPH_INITONCE InitOnce
687 _Inout_ PPH_INITONCE InitOnce
690 if (InitOnce->Event.Set)
699 _In_ PPH_INITONCE InitOnce
702 return (BOOLEAN)InitOnce->Event.Set;
739 _In_ PSTR InputBuffer,
740 _In_ SIZE_T InputCount,
741 _Out_writes_opt_z_(OutputCount) PSTR OutputBuffer,
742 _In_ SIZE_T OutputCount,
743 _Out_opt_ PSIZE_T ReturnCount
750 _In_ PWSTR InputBuffer,
751 _In_ SIZE_T InputCount,
752 _Out_writes_opt_z_(OutputCount) PWSTR OutputBuffer,
753 _In_ SIZE_T OutputCount,
754 _Out_opt_ PSIZE_T ReturnCount
761 _In_ PSTR InputBuffer,
762 _In_ SIZE_T InputCount,
763 _Out_writes_opt_z_(OutputCount) PWSTR OutputBuffer,
764 _In_ SIZE_T OutputCount,
765 _Out_opt_ PSIZE_T ReturnCount
772 _In_ PSTR InputBuffer,
773 _In_ SIZE_T InputCount,
774 _Out_writes_opt_z_(OutputCount) PWSTR OutputBuffer,
775 _In_ SIZE_T OutputCount,
776 _Out_opt_ PSIZE_T ReturnCount
785 _In_ BOOLEAN IgnoreCase
813 return (USHORT)(Char -
'0') < 10;
821 _In_ BOOLEAN IgnoreCase
825 return strcmp(String1, String2);
827 return stricmp(String1, String2);
835 _In_ BOOLEAN IgnoreCase
839 return strcmp(String1, String2) == 0;
841 return stricmp(String1, String2) == 0;
849 _In_ BOOLEAN IgnoreCase
853 return wcscmp(String1, String2);
855 return wcsicmp(String1, String2);
863 _In_ BOOLEAN IgnoreCase
868 return wcscmp(String1, String2) == 0;
876 return wcsicmp(String1, String2) == 0;
904 #define PH_STRINGREF_INIT(String) { sizeof(String) - sizeof(WCHAR), (String) }
905 #define PH_BYTESREF_INIT(String) { sizeof(String) - sizeof(CHAR), (String) }
910 _Out_ PPH_STRINGREF String,
914 String->Length = wcslen(Buffer) *
sizeof(WCHAR);
915 String->Buffer = Buffer;
921 _Out_ PPH_STRINGREF String,
926 String->Buffer = Buffer;
932 _Out_ PPH_BYTESREF Bytes,
936 Bytes->Length = strlen(Buffer) *
sizeof(CHAR);
937 Bytes->Buffer = Buffer;
943 _Out_ PPH_STRINGREF String
947 String->Buffer = NULL;
953 _In_ PPH_STRINGREF String,
957 UnicodeString->Length = (USHORT)String->Length;
958 UnicodeString->MaximumLength = (USHORT)String->Length;
959 UnicodeString->Buffer = String->Buffer;
961 return String->Length <= UNICODE_STRING_MAX_BYTES;
968 _Out_ PPH_STRINGREF String
971 String->Length = UnicodeString->Length;
972 String->Buffer = UnicodeString->Buffer;
979 _In_ PPH_STRINGREF String1,
980 _In_ PPH_STRINGREF String2,
981 _In_ BOOLEAN IgnoreCase
988 _In_ PPH_STRINGREF String1,
989 _In_ PPH_STRINGREF String2,
990 _In_ BOOLEAN IgnoreCase
997 _In_ PPH_STRINGREF String,
998 _In_ WCHAR Character,
999 _In_ BOOLEAN IgnoreCase
1006 _In_ PPH_STRINGREF String,
1007 _In_ WCHAR Character,
1008 _In_ BOOLEAN IgnoreCase
1015 _In_ PPH_STRINGREF String,
1016 _In_ PPH_STRINGREF SubString,
1017 _In_ BOOLEAN IgnoreCase
1024 _In_ PPH_STRINGREF Input,
1025 _In_ WCHAR Separator,
1026 _Out_ PPH_STRINGREF FirstPart,
1027 _Out_ PPH_STRINGREF SecondPart
1034 _In_ PPH_STRINGREF Input,
1035 _In_ WCHAR Separator,
1036 _Out_ PPH_STRINGREF FirstPart,
1037 _Out_ PPH_STRINGREF SecondPart
1044 _In_ PPH_STRINGREF Input,
1045 _In_ PPH_STRINGREF Separator,
1046 _In_ BOOLEAN IgnoreCase,
1047 _Out_ PPH_STRINGREF FirstPart,
1048 _Out_ PPH_STRINGREF SecondPart
1051 #define PH_SPLIT_AT_CHAR_SET 0x0 // default
1052 #define PH_SPLIT_AT_STRING 0x1
1053 #define PH_SPLIT_AT_RANGE 0x2
1054 #define PH_SPLIT_CASE_INSENSITIVE 0x1000
1055 #define PH_SPLIT_COMPLEMENT_CHAR_SET 0x2000
1056 #define PH_SPLIT_START_AT_END 0x4000
1057 #define PH_SPLIT_CHAR_SET_IS_UPPERCASE 0x8000
1063 _In_ PPH_STRINGREF Input,
1064 _In_ PPH_STRINGREF Separator,
1066 _Out_ PPH_STRINGREF FirstPart,
1067 _Out_ PPH_STRINGREF SecondPart,
1068 _Out_opt_ PPH_STRINGREF SeparatorPart
1071 #define PH_TRIM_START_ONLY 0x1
1072 #define PH_TRIM_END_ONLY 0x2
1078 _Inout_ PPH_STRINGREF String,
1079 _In_ PPH_STRINGREF CharSet,
1086 _In_ PPH_STRINGREF String1,
1088 _In_ BOOLEAN IgnoreCase
1101 _In_ PPH_STRINGREF String1,
1103 _In_ BOOLEAN IgnoreCase
1116 _In_ PPH_STRINGREF String,
1117 _In_ PPH_STRINGREF Prefix,
1118 _In_ BOOLEAN IgnoreCase
1123 sr.
Buffer = String->Buffer;
1124 sr.
Length = Prefix->Length;
1126 if (String->Length < sr.
Length)
1135 _In_ PPH_STRINGREF String,
1137 _In_ BOOLEAN IgnoreCase
1150 _In_ PPH_STRINGREF String,
1151 _In_ PPH_STRINGREF Suffix,
1152 _In_ BOOLEAN IgnoreCase
1157 if (Suffix->Length > String->Length)
1160 sr.
Buffer = (PWCHAR)((PCHAR)String->Buffer + String->Length - Suffix->Length);
1161 sr.
Length = Suffix->Length;
1169 _In_ PPH_STRINGREF String,
1171 _In_ BOOLEAN IgnoreCase
1184 _Inout_ PPH_STRINGREF String,
1185 _In_ LONG_PTR Length
1188 String->Buffer = (PWCH)((PCHAR)String->Buffer + Length);
1189 String->Length -= Length;
1195 _In_ PPH_STRINGREF String
1202 for (i = 0, j = String->Length /
sizeof(WCHAR) - 1; i <= j; i++, j--)
1204 t = String->Buffer[i];
1205 String->Buffer[i] = String->Buffer[j];
1206 String->Buffer[j] = t;
1260 _In_opt_ PWCHAR Buffer,
1267 _In_ PPH_STRINGREF String
1297 #define PH_CONCAT_STRINGS_LENGTH_CACHE_SIZE 16
1319 _In_ PPH_STRINGREF String1,
1320 _In_ PPH_STRINGREF String2
1326 _In_ PPH_STRINGREF String1,
1327 _In_ PPH_STRINGREF String2,
1328 _In_ PPH_STRINGREF String3
1335 _In_ _Printf_format_string_ PWSTR Format,
1343 _In_ _Printf_format_string_ PWSTR Format,
1360 _In_opt_ PPH_STRING String
1364 return String->Buffer;
1372 _In_opt_ PPH_STRING String
1398 _In_opt_ PPH_STRING String
1402 return String->Buffer;
1421 _In_opt_ PPH_STRING String,
1422 _In_ PWSTR DefaultString
1426 return String->Buffer;
1428 return DefaultString;
1439 _In_opt_ PPH_STRING String
1442 return !String || String->Length == 0;
1453 _In_ PPH_STRING String
1469 _In_ PPH_STRING String1,
1470 _In_ PPH_STRING String2,
1471 _In_ BOOLEAN IgnoreCase
1475 return wcscmp(String1->Buffer, String2->Buffer);
1490 _In_ PPH_STRING String1,
1492 _In_ BOOLEAN IgnoreCase
1497 return wcscmp(String1->Buffer, String2);
1515 _In_opt_ PPH_STRING String1,
1516 _In_opt_ PPH_STRING String2,
1517 _In_ BOOLEAN IgnoreCase
1520 if (String1 && String2)
1526 return !String2 ? 0 : -1;
1544 _In_ PPH_STRING String1,
1545 _In_ PPH_STRING String2,
1546 _In_ BOOLEAN IgnoreCase
1562 _In_ PPH_STRING String1,
1564 _In_ BOOLEAN IgnoreCase
1569 return wcscmp(String1->Buffer, String2) == 0;
1589 _In_ PPH_STRING String,
1590 _In_ PPH_STRING Prefix,
1591 _In_ BOOLEAN IgnoreCase
1609 _In_ PPH_STRING String,
1611 _In_ BOOLEAN IgnoreCase
1633 _In_ PPH_STRING String,
1634 _In_ PPH_STRING Suffix,
1635 _In_ BOOLEAN IgnoreCase
1653 _In_ PPH_STRING String,
1655 _In_ BOOLEAN IgnoreCase
1679 _In_ PPH_STRING String,
1680 _In_ SIZE_T StartIndex,
1684 if (StartIndex != 0)
1694 return r + StartIndex;
1718 _In_ PPH_STRING String,
1719 _In_ SIZE_T StartIndex,
1723 if (StartIndex != 0)
1733 return r + StartIndex;
1757 _In_ PPH_STRING String,
1758 _In_ SIZE_T StartIndex,
1759 _In_ PWSTR SubString
1766 if (StartIndex != 0)
1776 return r + StartIndex;
1796 _In_ PPH_STRING String,
1797 _In_ SIZE_T StartIndex,
1801 return PhCreateStringEx(&String->Buffer[StartIndex], Count *
sizeof(WCHAR));
1812 _Inout_ PPH_STRING String
1815 _wcslwr(String->Buffer);
1826 _Inout_ PPH_STRING String
1829 _wcsupr(String->Buffer);
1845 _Inout_ PPH_STRING String
1899 _In_opt_ PCHAR Buffer,
1906 _In_ PPH_BYTESREF Bytes
1914 #define PH_UNICODE_BYTE_ORDER_MARK 0xfeff
1915 #define PH_UNICODE_MAX_CODE_POINT 0x10ffff
1917 #define PH_UNICODE_UTF16_TO_HIGH_SURROGATE(CodePoint) ((USHORT)((CodePoint) >> 10) + 0xd7c0)
1918 #define PH_UNICODE_UTF16_TO_LOW_SURROGATE(CodePoint) ((USHORT)((CodePoint) & 0x3ff) + 0xdc00)
1919 #define PH_UNICODE_UTF16_IS_HIGH_SURROGATE(CodeUnit) ((CodeUnit) >= 0xd800 && (CodeUnit) <= 0xdbff)
1920 #define PH_UNICODE_UTF16_IS_LOW_SURROGATE(CodeUnit) ((CodeUnit) >= 0xdc00 && (CodeUnit) <= 0xdfff)
1921 #define PH_UNICODE_UTF16_TO_CODE_POINT(HighSurrogate, LowSurrogate) (((ULONG)(HighSurrogate) << 10) + (ULONG)(LowSurrogate) - 0x35fdc00)
1923 #define PH_UNICODE_UTF8 0
1924 #define PH_UNICODE_UTF16 1
1925 #define PH_UNICODE_UTF32 2
1964 _Out_ PPH_UNICODE_DECODER Decoder,
1969 Decoder->Encoding = Encoding;
1976 _Inout_ PPH_UNICODE_DECODER Decoder,
1984 _Inout_ PPH_UNICODE_DECODER Decoder,
1985 _Out_ PULONG CodePoint
1992 _In_ UCHAR Encoding,
1993 _In_ ULONG CodePoint,
1994 _Out_opt_ PVOID CodeUnits,
1995 _Out_ PULONG NumberOfCodeUnits
2004 _In_reads_bytes_(InputLength) PCH Input,
2005 _In_ SIZE_T InputLength,
2006 _Out_writes_bytes_(InputLength *
sizeof(WCHAR)) PWCH Output
2013 _In_reads_bytes_(InputLength) PCH Input,
2014 _In_ SIZE_T InputLength
2034 _In_opt_ CHAR Replacement
2041 _In_opt_ CHAR Replacement
2089 _Out_ PSIZE_T BytesInUtf16String,
2090 _In_reads_bytes_(BytesInUtf8String) PCH Utf8String,
2091 _In_ SIZE_T BytesInUtf8String
2098 _Out_writes_bytes_to_(MaxBytesInUtf16String, *BytesInUtf16String) PWCH Utf16String,
2099 _In_ SIZE_T MaxBytesInUtf16String,
2100 _Out_opt_ PSIZE_T BytesInUtf16String,
2101 _In_reads_bytes_(BytesInUtf8String) PCH Utf8String,
2102 _In_ SIZE_T BytesInUtf8String
2126 _Out_ PSIZE_T BytesInUtf8String,
2127 _In_reads_bytes_(BytesInUtf16String) PWCH Utf16String,
2128 _In_ SIZE_T BytesInUtf16String
2135 _Out_writes_bytes_to_(MaxBytesInUtf8String, *BytesInUtf8String) PCH Utf8String,
2136 _In_ SIZE_T MaxBytesInUtf8String,
2137 _Out_opt_ PSIZE_T BytesInUtf8String,
2138 _In_reads_bytes_(BytesInUtf16String) PWCH Utf16String,
2139 _In_ SIZE_T BytesInUtf16String
2180 _Out_ PPH_STRING_BUILDER StringBuilder,
2181 _In_ SIZE_T InitialCapacity
2188 _Inout_ PPH_STRING_BUILDER StringBuilder
2195 _Inout_ PPH_STRING_BUILDER StringBuilder
2202 _Inout_ PPH_STRING_BUILDER StringBuilder,
2203 _In_ PPH_STRINGREF String
2210 _Inout_ PPH_STRING_BUILDER StringBuilder,
2218 _Inout_ PPH_STRING_BUILDER StringBuilder,
2219 _In_opt_ PWCHAR String,
2227 _Inout_ PPH_STRING_BUILDER StringBuilder,
2228 _In_ WCHAR Character
2235 _Inout_ PPH_STRING_BUILDER StringBuilder,
2236 _In_ WCHAR Character,
2244 _Inout_ PPH_STRING_BUILDER StringBuilder,
2245 _In_ _Printf_format_string_ PWSTR Format,
2252 _Inout_ PPH_STRING_BUILDER StringBuilder,
2253 _In_ _Printf_format_string_ PWSTR Format,
2261 _Inout_ PPH_STRING_BUILDER StringBuilder,
2263 _In_ PPH_STRINGREF String
2270 _Inout_ PPH_STRING_BUILDER StringBuilder,
2279 _Inout_ PPH_STRING_BUILDER StringBuilder,
2281 _In_opt_ PWCHAR String,
2289 _Inout_ PPH_STRING_BUILDER StringBuilder,
2290 _In_ SIZE_T StartIndex,
2297 _Inout_ PPH_STRING_BUILDER StringBuilder,
2303 StringBuilder->String->Length /
sizeof(WCHAR) - Count,
2330 _Out_ PPH_BYTES_BUILDER BytesBuilder,
2331 _In_ SIZE_T InitialCapacity
2338 _Inout_ PPH_BYTES_BUILDER BytesBuilder
2345 _Inout_ PPH_BYTES_BUILDER BytesBuilder
2351 _In_ PPH_BYTES_BUILDER BytesBuilder,
2355 return BytesBuilder->Bytes->Buffer + Offset;
2362 _Inout_ PPH_BYTES_BUILDER BytesBuilder,
2363 _In_ PPH_BYTESREF Bytes
2370 _Inout_ PPH_BYTES_BUILDER BytesBuilder,
2378 _Inout_ PPH_BYTES_BUILDER BytesBuilder,
2379 _In_opt_ PVOID Buffer,
2381 _In_opt_ SIZE_T Alignment,
2382 _Out_opt_ PSIZE_T Offset
2408 _In_ ULONG InitialCapacity
2415 _Inout_ PPH_LIST List,
2416 _In_ ULONG NewCapacity
2423 _Inout_ PPH_LIST List,
2431 _Inout_ PPH_LIST List,
2440 _Inout_ PPH_LIST List
2456 _Inout_ PPH_LIST List,
2465 _Inout_ PPH_LIST List,
2475 _Inout_ PPH_LIST List,
2483 _Inout_ PPH_LIST List,
2484 _In_ ULONG StartIndex,
2503 _In_opt_ PVOID Context
2530 #define PH_IS_LIST_POINTER_VALID(Pointer) (!((ULONG_PTR)(Pointer) & 0x1))
2536 _In_ ULONG InitialCapacity
2543 _Inout_ PPH_POINTER_LIST PointerList,
2551 _In_ PPH_POINTER_LIST PointerList,
2552 _Inout_ PULONG EnumerationKey,
2553 _Out_ PVOID *Pointer,
2554 _Out_ PHANDLE PointerHandle
2561 _In_ PPH_POINTER_LIST PointerList,
2569 _Inout_ PPH_POINTER_LIST PointerList,
2570 _In_ HANDLE PointerHandle
2576 _In_ PPH_POINTER_LIST PointerList,
2577 _Inout_ PULONG EnumerationKey,
2578 _Out_ PVOID *Pointer
2581 while (*EnumerationKey < PointerList->NextEntry)
2583 PVOID pointer = PointerList->Items[*EnumerationKey];
2585 (*EnumerationKey)++;
2605 #define PH_HASH_SET_INIT { 0 }
2606 #define PH_HASH_SET_SIZE(Buckets) (sizeof(Buckets) / sizeof(PPH_HASH_ENTRY))
2617 _Out_ PPH_HASH_ENTRY *Buckets,
2618 _In_ ULONG NumberOfBuckets
2621 memset(Buckets, 0,
sizeof(PPH_HASH_ENTRY) * NumberOfBuckets);
2635 _In_ ULONG NumberOfBuckets
2638 PPH_HASH_ENTRY *buckets;
2640 buckets = (PPH_HASH_ENTRY *)PhAllocate(
sizeof(PPH_HASH_ENTRY) * NumberOfBuckets);
2657 _In_ PPH_HASH_ENTRY *Buckets,
2658 _In_ ULONG NumberOfBuckets
2662 PPH_HASH_ENTRY entry;
2667 for (i = 0; i < NumberOfBuckets; i++)
2669 for (entry = Buckets[i]; entry; entry = entry->
Next)
2689 _Inout_ PPH_HASH_ENTRY *NewBuckets,
2690 _In_ ULONG NumberOfNewBuckets,
2691 _In_ PPH_HASH_ENTRY *OldBuckets,
2692 _In_ ULONG NumberOfOldBuckets
2696 PPH_HASH_ENTRY entry;
2697 PPH_HASH_ENTRY nextEntry;
2700 for (i = 0; i < NumberOfOldBuckets; i++)
2702 entry = OldBuckets[i];
2706 nextEntry = entry->
Next;
2708 index = entry->
Hash & (NumberOfNewBuckets - 1);
2709 entry->
Next = NewBuckets[index];
2710 NewBuckets[index] = entry;
2730 _Inout_ PPH_HASH_ENTRY *Buckets,
2731 _In_ ULONG NumberOfBuckets,
2732 _Out_ PPH_HASH_ENTRY Entry,
2738 index = Hash & (NumberOfBuckets - 1);
2741 Entry->Next = Buckets[index];
2742 Buckets[index] = Entry;
2760 _In_ PPH_HASH_ENTRY *Buckets,
2761 _In_ ULONG NumberOfBuckets,
2765 return Buckets[Hash & (NumberOfBuckets - 1)];
2778 _Inout_ PPH_HASH_ENTRY *Buckets,
2779 _In_ ULONG NumberOfBuckets,
2780 _Inout_ PPH_HASH_ENTRY Entry
2784 PPH_HASH_ENTRY entry;
2785 PPH_HASH_ENTRY previousEntry;
2787 index = Entry->
Hash & (NumberOfBuckets - 1);
2788 previousEntry = NULL;
2790 entry = Buckets[index];
2797 Buckets[index] = entry->
Next;
2804 previousEntry = entry;
2805 entry = entry->
Next;
2824 _Inout_ PPH_HASH_ENTRY **Buckets,
2825 _Inout_ PULONG NumberOfBuckets,
2826 _In_ ULONG NewNumberOfBuckets
2829 PPH_HASH_ENTRY *newBuckets;
2835 *Buckets = newBuckets;
2836 *NumberOfBuckets = NewNumberOfBuckets;
2888 #define PH_HASHTABLE_POWER_OF_TWO_SIZE
2924 #define PH_HASHTABLE_ENTRY_SIZE(InnerSize) (FIELD_OFFSET(PH_HASHTABLE_ENTRY, Body) + (InnerSize))
2925 #define PH_HASHTABLE_GET_ENTRY(Hashtable, Index) \
2926 ((PPH_HASHTABLE_ENTRY)PTR_ADD_OFFSET((Hashtable)->Entries, \
2927 PH_HASHTABLE_ENTRY_SIZE((Hashtable)->EntrySize) * (Index)))
2928 #define PH_HASHTABLE_GET_ENTRY_INDEX(Hashtable, Entry) \
2929 ((ULONG)(PTR_ADD_OFFSET(Entry, -(Hashtable)->Entries) / \
2930 PH_HASHTABLE_ENTRY_SIZE((Hashtable)->EntrySize)))
2936 _In_ ULONG EntrySize,
2939 _In_ ULONG InitialCapacity
2946 _Inout_ PPH_HASHTABLE Hashtable,
2954 _Inout_ PPH_HASHTABLE Hashtable,
2956 _Out_opt_ PBOOLEAN Added
2963 _Inout_ PPH_HASHTABLE Hashtable
2970 _In_ PPH_HASHTABLE Hashtable,
2972 _Inout_ PULONG EnumerationKey
2979 _In_ PPH_HASHTABLE Hashtable,
2987 _Inout_ PPH_HASHTABLE Hashtable,
3003 _In_ PPH_HASHTABLE Hashtable,
3004 _Out_ PPH_HASHTABLE_ENUM_CONTEXT Context
3007 Context->Current = (ULONG_PTR)Hashtable->Entries;
3009 Context->End = Context->Current + (ULONG_PTR)Hashtable->NextEntry * Context->Step;
3015 _Inout_ PPH_HASHTABLE_ENUM_CONTEXT Context
3018 PPH_HASHTABLE_ENTRY entry;
3020 while (Context->Current != Context->End)
3023 Context->Current += Context->Step;
3026 return &entry->
Body;
3036 _In_reads_(Length) PUCHAR Bytes,
3044 _In_ PPH_STRINGREF String,
3045 _In_ BOOLEAN IgnoreCase
3055 Value ^= (Value >> 20) ^ (Value >> 12);
3056 return Value ^ (Value >> 7) ^ (Value >> 4);
3067 Value = ~Value + (Value << 18);
3068 Value ^= Value >> 31;
3070 Value ^= Value >> 11;
3071 Value += Value << 6;
3072 Value ^= Value >> 22;
3074 return (ULONG)Value;
3080 _In_ ULONG_PTR Value
3102 _In_ ULONG InitialCapacity
3109 _Inout_ PPH_HASHTABLE SimpleHashtable,
3111 _In_opt_ PVOID Value
3118 _In_ PPH_HASHTABLE SimpleHashtable,
3126 _In_ PPH_HASHTABLE SimpleHashtable,
3144 _Inout_ PPH_HASHTABLE SimpleHashtable,
3177 _Out_ PPH_FREE_LIST FreeList,
3179 _In_ ULONG MaximumCount
3186 _Inout_ PPH_FREE_LIST FreeList
3193 _Inout_ PPH_FREE_LIST FreeList
3200 _Inout_ PPH_FREE_LIST FreeList,
3215 _In_opt_ PVOID Parameter,
3216 _In_opt_ PVOID Context
3258 #define PH_CALLBACK_DECLARE(Name) PH_CALLBACK Name = { &Name.ListHead, &Name.ListHead, PH_QUEUED_LOCK_INIT, PH_QUEUED_LOCK_INIT }
3264 _Out_ PPH_CALLBACK Callback
3271 _Inout_ PPH_CALLBACK Callback
3278 _Inout_ PPH_CALLBACK Callback,
3280 _In_opt_ PVOID Context,
3281 _Out_ PPH_CALLBACK_REGISTRATION Registration
3288 _Inout_ PPH_CALLBACK Callback,
3290 _In_opt_ PVOID Context,
3292 _Out_ PPH_CALLBACK_REGISTRATION Registration
3299 _Inout_ PPH_CALLBACK Callback,
3300 _Inout_ PPH_CALLBACK_REGISTRATION Registration
3307 _In_ PPH_CALLBACK Callback,
3308 _In_opt_ PVOID Parameter
3347 _In_ PPH_STRINGREF String,
3348 _Out_writes_bytes_(String->Length /
sizeof(WCHAR) / 2) PUCHAR Buffer
3355 _In_reads_bytes_(Length) PUCHAR Buffer,
3362 _In_reads_bytes_(Length) PUCHAR Buffer,
3364 _In_ BOOLEAN UpperCase
3371 _In_ PPH_STRINGREF String,
3372 _In_opt_ ULONG Base,
3373 _Out_opt_ PLONG64 Integer
3380 _In_ LONG64 Integer,
3381 _In_opt_ ULONG Base,
3385 #define PH_TIMESPAN_STR_LEN 30
3386 #define PH_TIMESPAN_STR_LEN_1 (PH_TIMESPAN_STR_LEN + 1)
3388 #define PH_TIMESPAN_HMS 0
3389 #define PH_TIMESPAN_HMSM 1
3390 #define PH_TIMESPAN_DHMS 2
3417 _Inout_updates_(Count) PFLOAT A,
3526 #define PhInitFormatC(f, v) do { (f)->Type = CharFormatType; (f)->u.Char = (v); } while (0)
3527 #define PhInitFormatS(f, v) do { (f)->Type = StringFormatType; PhInitializeStringRef(&(f)->u.String, (v)); } while (0)
3528 #define PhInitFormatSR(f, v) do { (f)->Type = StringFormatType; (f)->u.String = (v); } while (0)
3529 #define PhInitFormatMultiByteS(f, v) do { (f)->Type = MultiByteStringFormatType; PhInitializeBytesRef(&(f)->u.MultiByteString, (v)); } while (0)
3530 #define PhInitFormatD(f, v) do { (f)->Type = Int32FormatType; (f)->u.Int32 = (v); } while (0)
3531 #define PhInitFormatU(f, v) do { (f)->Type = UInt32FormatType; (f)->u.UInt32 = (v); } while (0)
3532 #define PhInitFormatX(f, v) do { (f)->Type = UInt32FormatType | FormatUseRadix; (f)->u.UInt32 = (v); (f)->Radix = 16; } while (0)
3533 #define PhInitFormatI64D(f, v) do { (f)->Type = Int64FormatType; (f)->u.Int64 = (v); } while (0)
3534 #define PhInitFormatI64U(f, v) do { (f)->Type = UInt64FormatType; (f)->u.UInt64 = (v); } while (0)
3535 #define PhInitFormatI64X(f, v) do { (f)->Type = UInt64FormatType | FormatUseRadix; (f)->u.UInt64 = (v); (f)->Radix = 16; } while (0)
3536 #define PhInitFormatIU(f, v) do { (f)->Type = UIntPtrFormatType; (f)->u.UIntPtr = (v); } while (0)
3537 #define PhInitFormatIX(f, v) do { (f)->Type = UIntPtrFormatType | FormatUseRadix; (f)->u.UIntPtr = (v); (f)->Radix = 16; } while (0)
3538 #define PhInitFormatF(f, v, p) do { (f)->Type = DoubleFormatType | FormatUsePrecision; (f)->u.Double = (v); (f)->Precision = (p); } while (0)
3539 #define PhInitFormatE(f, v, p) do { (f)->Type = DoubleFormatType | FormatStandardForm | FormatUsePrecision; (f)->u.Double = (v); (f)->Precision = (p); } while (0)
3540 #define PhInitFormatA(f, v, p) do { (f)->Type = DoubleFormatType | FormatHexadecimalForm | FormatUsePrecision; (f)->u.Double = (v); (f)->Precision = (p); } while (0)
3541 #define PhInitFormatSize(f, v) do { (f)->Type = SizeFormatType; (f)->u.Size = (v); } while (0)
3547 _In_reads_(Count) PPH_FORMAT Format,
3549 _In_opt_ SIZE_T InitialCapacity
3556 _In_reads_(Count) PPH_FORMAT Format,
3558 _Out_writes_bytes_opt_(BufferLength) PWSTR Buffer,
3559 _In_opt_ SIZE_T BufferLength,
3560 _Out_opt_ PSIZE_T ReturnLength
3576 _In_opt_ PWSTR Buffer,
3584 _In_ PPH_STRING String
3607 _In_ _Printf_format_string_ PWSTR Format,
3615 _In_ PPH_STRING String
3622 _In_ PPH_STRING String
3629 _In_ PPH_STRING String,
3630 _In_ SIZE_T StartIndex,
3640 _In_ NTSTATUS Status
3654 _In_ NTSTATUS Status
3667 #define PhIsLeftChildElement(Links) ((Links)->Parent->Left == (Links))
3668 #define PhIsRightChildElement(Links) ((Links)->Parent->Right == (Links))
3682 typedef LONG (NTAPI *PPH_AVL_TREE_COMPARE_FUNCTION)(
3683 _In_ PPH_AVL_LINKS Links1,
3684 _In_ PPH_AVL_LINKS
Links2
3695 #define PH_AVL_TREE_INIT(CompareFunction) { { NULL, NULL, NULL, 0 }, 0, CompareFunction }
3697 #define PhRootElementAvlTree(Tree) ((Tree)->Root.Right)
3703 _Out_ PPH_AVL_TREE Tree,
3704 _In_ PPH_AVL_TREE_COMPARE_FUNCTION CompareFunction
3711 _Inout_ PPH_AVL_TREE Tree,
3712 _Out_ PPH_AVL_LINKS Element
3719 _Inout_ PPH_AVL_TREE Tree,
3720 _Inout_ PPH_AVL_LINKS Element
3727 _In_ PPH_AVL_TREE Tree,
3728 _In_ PPH_AVL_LINKS Element
3735 _In_ PPH_AVL_TREE Tree,
3736 _In_ PPH_AVL_LINKS Element,
3744 _In_ PPH_AVL_TREE Tree
3751 _In_ PPH_AVL_TREE Tree
3758 _In_ PPH_AVL_LINKS Element
3765 _In_ PPH_AVL_LINKS Element
3769 _In_ PPH_AVL_TREE Tree,
3770 _In_ PPH_AVL_LINKS Element,
3771 _In_opt_ PVOID Context
3778 _In_ PPH_AVL_TREE Tree,
3781 _In_opt_ PVOID Context
3805 ULONG_PTR Value :
sizeof(ULONG_PTR) * 8 - 2;
3816 #define PH_HANDLE_TABLE_SAFE
3817 #define PH_HANDLE_TABLE_FREE_COUNT 64
3819 #define PH_HANDLE_TABLE_STRICT_FIFO 0x1
3820 #define PH_HANDLE_TABLE_VALID_FLAGS 0x1
3836 _In_ _Post_invalid_ PPH_HANDLE_TABLE HandleTable
3842 _Inout_ PPH_HANDLE_TABLE HandleTable,
3843 _Inout_ PPH_HANDLE_TABLE_ENTRY HandleTableEntry
3849 _Inout_ PPH_HANDLE_TABLE HandleTable,
3850 _Inout_ PPH_HANDLE_TABLE_ENTRY HandleTableEntry
3856 _Inout_ PPH_HANDLE_TABLE HandleTable,
3857 _In_ PPH_HANDLE_TABLE_ENTRY HandleTableEntry
3863 _Inout_ PPH_HANDLE_TABLE HandleTable,
3865 _In_opt_ PPH_HANDLE_TABLE_ENTRY HandleTableEntry
3868 PPH_HANDLE_TABLE_ENTRY
3871 _In_ PPH_HANDLE_TABLE HandleTable,
3876 _In_ PPH_HANDLE_TABLE HandleTable,
3878 _In_ PPH_HANDLE_TABLE_ENTRY HandleTableEntry,
3879 _In_opt_ PVOID Context
3885 _In_ PPH_HANDLE_TABLE HandleTable,
3887 _In_opt_ PVOID Context
3893 _In_ PPH_HANDLE_TABLE HandleTable,
3895 _In_opt_ PVOID Context
3920 _In_ PPH_HANDLE_TABLE HandleTable,
3922 _Out_writes_bytes_opt_(BufferLength) PVOID Buffer,
3923 _In_ ULONG BufferLength,
3924 _Out_opt_ PULONG ReturnLength
3930 _Inout_ PPH_HANDLE_TABLE HandleTable,
3932 _In_reads_bytes_(BufferLength) PVOID Buffer,
3933 _In_ ULONG BufferLength
3938 #if !defined(_PH_WORKQUEUE_PRIVATE) && defined(DEBUG)
3939 extern PPH_LIST PhDbgWorkQueueList;
3984 _Out_ PPH_WORK_QUEUE WorkQueue,
3985 _In_ ULONG MinimumThreads,
3986 _In_ ULONG MaximumThreads,
3987 _In_ ULONG NoWorkTimeout
3994 _Inout_ PPH_WORK_QUEUE WorkQueue
4001 _Inout_ PPH_WORK_QUEUE WorkQueue
4008 _Inout_ PPH_WORK_QUEUE WorkQueue,
4010 _In_opt_ PVOID Context
4015 _Inout_ PPH_WORK_QUEUE WorkQueue,
4017 _In_opt_ PVOID Context,
4026 _In_opt_ PVOID Context