-
Notifications
You must be signed in to change notification settings - Fork 1
/
ntnative.h
2034 lines (1786 loc) · 80.8 KB
/
ntnative.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
///////////////////////////////////////////////////////////////////////////////
//
// Type and function declarations for the NT native API.
//
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2016-2018, 2021, 2023 Oliver Schneider (assarbad.net)
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// [Boost Software License - Version 1.0 - August 17th, 2003]
//
// SPDX-License-Identifier: BSL-1.0
//
///////////////////////////////////////////////////////////////////////////////
// http://terminus.rewolf.pl/terminus/
// http://undocumented.ntinternals.net
// https://github.com/ntdiff/headers + https://ntdiff.github.io
// https://www.vergiliusproject.com/
// https://ntdoc.m417z.com/symbols
///////////////////////////////////////////////////////////////////////////////
#ifndef __NTNATIVE_H_VER__
#define __NTNATIVE_H_VER__ 2023111723
#if (defined(_MSC_VER) && (_MSC_VER >= 1020)) || defined(__MCPP)
# pragma once
#endif // Check for "#pragma once" support
#if defined(NT_INCLUDED) || defined(_WINNT_) || defined(_WINDOWS_) || defined(_INC_WINDOWS)
# error This header should be included before those pesky Windows headers (it also includes some of them but needs to cheat on some particulars)
#else
# define WIN32_LEAN_AND_MEAN // this can be worked around by explicitly including the rarely used stuff
# pragma push_macro("NtCurrentTeb")
# define NtCurrentTeb NtCurrentTeb_Mock // comes transiently from winnt.h
# include <Windows.h>
# undef NtCurrentTeb
# pragma pop_macro("NtCurrentTeb")
#endif
#pragma push_macro("STATIC_INLINE")
#ifdef STATIC_INLINE
# undef STATIC_INLINE
#endif // STATIC_INLINE
#ifdef _MSC_VER
# define STATIC_INLINE static __forceinline
#else
# define STATIC_INLINE static inline
#endif // _MSC_VER
// Fake the SAL1 annotations where they don't exist.
#if !defined(__in_bcount) && !defined(_In_reads_bytes_)
# define __success(x)
# define __field_range(x, y)
# define __field_nullterminated
# define __in
# define __in_z
# define __in_bcount(x)
# define __in_opt
# define __inout
# define __inout_opt
# define __out
# define __out_bcount(x)
# define __out_opt
# define __out_bcount_opt(x)
# define __reserved
#endif
// Fake the SAL2 annotations where they don't exist.
#if defined(__in_bcount) && !defined(_In_reads_bytes_)
# define _Success_(x) __success(x)
# define _Field_range_(x, y) __field_range(x, y)
# define _Field_z_ __field_nullterminated
# define _In_ __in
# define _In_z_ __in_z
# define _In_reads_bytes_(x) __in_bcount(x)
# define _In_opt_ __in_opt
# define _Inout_ __inout
# define _Inout_opt_ __inout_opt
# define _Out_ __out
# define _Out_writes_bytes_(x) __out_bcount(x)
# define _Out_opt_ __out_opt
# define _Out_writes_bytes_opt_(x) __out_bcount_opt(x)
# define _Reserved_ __reserved
#endif
#ifndef _Must_inspect_result_
# define _Must_inspect_result_
#endif
#ifndef _Ret_maybenull_
# define _Ret_maybenull_
#endif
#ifndef _Ret_writes_bytes_maybenull_
# define _Ret_writes_bytes_maybenull_(Size)
#endif
#ifndef _Post_writable_byte_size_
# define _Post_writable_byte_size_(Size)
#endif
#ifndef _Post_invalid_
# define _Post_invalid_
#endif
#ifndef _Post_ptr_invalid_
# define _Post_ptr_invalid_
#endif
#ifndef _Notnull_
# define _Notnull_
#endif
#ifndef _Pre_
# define _Pre_
#endif
#ifndef _When_
# define _When_(x, y)
#endif
#ifndef _In_range_
# define _In_range_(x, y)
#endif
#ifndef _Out_range_
# define _Out_range_(x, y)
#endif
#ifndef _Frees_ptr_opt_
# define _Frees_ptr_opt_
#endif
#ifndef _Frees_ptr_
# define _Frees_ptr_
#endif
#ifndef _Inout_updates_opt_
# define _Inout_updates_opt_(x)
#endif
#ifndef _Inout_updates_
# define _Inout_updates_(x)
#endif
#ifndef _Out_writes_bytes_to_opt_
# define _Out_writes_bytes_to_opt_(x, y)
#endif
#ifndef _In_reads_opt_
# define _In_reads_opt_(x)
#endif
#ifndef _Strict_type_match_
# define _Strict_type_match_
#endif
#ifndef _Outptr_
# define _Outptr_
#endif
#ifndef _Outptr_result_maybenull_
# define _Outptr_result_maybenull_
#endif
#ifndef _Writable_elements_
# define _Writable_elements_(x)
#endif
#ifndef _In_opt_z_
# define _In_opt_z_
#endif
#ifndef _Printf_format_string_
# define _Printf_format_string_
#endif
#if defined(DDKBUILD)
# pragma push_macro("NtCurrentTeb")
# define NtCurrentTeb NtCurrentTeb_Mock // comes transiently from winnt.h
# include <WinDef.h>
# undef NtCurrentTeb
# pragma pop_macro("NtCurrentTeb")
#else
# pragma push_macro("NTSYSCALLAPI")
# pragma push_macro("NtCurrentTeb")
# ifdef NTSYSCALLAPI
# undef NTSYSCALLAPI
# define NTSYSCALLAPI
# endif
# pragma warning(push)
# pragma warning(disable : 4201)
# define OBJECT_INFORMATION_CLASS OBJECT_INFORMATION_CLASS_MOCK
# define _OBJECT_INFORMATION_CLASS _OBJECT_INFORMATION_CLASS_MOCK
# define _TEB _TEB_MOCK
# define TEB TEB_MOCK
# define PTEB PTEB_MOCK
# define ObjectBasicInformation ObjectBasicInformation_Mock
# define ObjectTypeInformation ObjectTypeInformation_Mock
# define NtQueryObject NtQueryObject_Mock
# define NtCurrentTeb NtCurrentTeb_Mock // comes transiently from winnt.h (via windef.h)
# include <winternl.h>
# undef OBJECT_INFORMATION_CLASS
# undef _OBJECT_INFORMATION_CLASS
# undef _TEB
# undef TEB
# undef PTEB
# undef ObjectBasicInformation
# undef ObjectTypeInformation
# undef NtQueryObject
# undef NtCurrentTeb
# pragma warning(pop)
# pragma pop_macro("NtCurrentTeb")
# pragma pop_macro("NTSYSCALLAPI")
#endif // DDKBUILD
#pragma warning(push)
#pragma warning(disable : 4005)
#include <ntstatus.h>
#pragma warning(pop)
#if defined(DDKBUILD)
# if defined(__cplusplus)
extern "C"
{
# endif
typedef struct _UNICODE_STRING
{
USHORT Length;
USHORT MaximumLength;
PWSTR Buffer;
} UNICODE_STRING;
typedef UNICODE_STRING* PUNICODE_STRING;
typedef const UNICODE_STRING* PCUNICODE_STRING;
typedef struct _OBJECT_ATTRIBUTES
{
ULONG Length;
HANDLE RootDirectory;
PUNICODE_STRING ObjectName;
ULONG Attributes;
PVOID SecurityDescriptor;
PVOID SecurityQualityOfService;
} OBJECT_ATTRIBUTES;
typedef OBJECT_ATTRIBUTES* POBJECT_ATTRIBUTES;
# ifndef _NTDEF_
typedef _Success_(return >= 0) LONG NTSTATUS;
typedef NTSTATUS* PNTSTATUS;
# if defined(DDKBUILD)
typedef struct _STRING
{
USHORT Length;
USHORT MaximumLength;
# ifdef MIDL_PASS
[ size_is(MaximumLength), length_is(Length) ]
# endif // MIDL_PASS
PCHAR Buffer;
} STRING;
typedef STRING* PSTRING;
typedef STRING ANSI_STRING;
typedef PSTRING PANSI_STRING;
typedef STRING OEM_STRING;
typedef PSTRING POEM_STRING;
typedef int PROCESSINFOCLASS;
typedef int THREADINFOCLASS;
typedef int SYSTEM_INFORMATION_CLASS;
typedef CONST char* PCSZ;
typedef PSTRING PCANSI_STRING;
# endif
# endif
typedef struct _IO_STATUS_BLOCK
{
union
{
NTSTATUS Status;
PVOID Pointer;
} DUMMYUNIONNAME;
ULONG_PTR Information;
} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
# ifndef RtlMoveMemory
# define RtlMoveMemory(Destination, Source, Length) memmove((Destination), (Source), (Length)) // use __movsb?
# endif
# ifndef RtlFillMemory
# define RtlFillMemory(Destination, Length, Fill) memset((Destination), (Fill), (Length)) // use __stosb?
# endif
# ifndef RtlZeroMemory
# define RtlZeroMemory(Destination, Length) memset((Destination), 0, (Length))
# endif
# ifndef OBJ_INHERIT
# define OBJ_INHERIT 0x00000002L
# endif
NTSTATUS
NTAPI
NtClose(_In_ _Post_ptr_invalid_ HANDLE Handle);
VOID NTAPI RtlInitUnicodeString(_Out_ PUNICODE_STRING DestinationString, _In_opt_z_ PCWSTR SourceString);
# if defined(__cplusplus)
}
# endif
#endif // DDKBUILD
#ifndef InitializeObjectAttributes
# define InitializeObjectAttributes(p, n, a, r, s) \
{ \
(p)->Length = sizeof(OBJECT_ATTRIBUTES); \
(p)->RootDirectory = r; \
(p)->Attributes = a; \
(p)->ObjectName = n; \
(p)->SecurityDescriptor = s; \
(p)->SecurityQualityOfService = NULL; \
}
#endif
typedef enum _OBJECT_INFORMATION_CLASS
{
ObjectBasicInformation,
ObjectNameInformation,
ObjectTypeInformation,
ObjectAllInformation,
ObjectDataInformation
} OBJECT_INFORMATION_CLASS;
#ifndef RTL_CONSTANT_STRING
# if defined(__cplusplus)
extern "C++"
{
char _RTL_CONSTANT_STRING_type_check(const char* s);
char _RTL_CONSTANT_STRING_type_check(const WCHAR* s);
// __typeof would be desirable here instead of sizeof.
template <size_t N> class _RTL_CONSTANT_STRING_remove_const_template_class;
template <> class _RTL_CONSTANT_STRING_remove_const_template_class<sizeof(char)>
{
public:
typedef char T;
};
template <> class _RTL_CONSTANT_STRING_remove_const_template_class<sizeof(WCHAR)>
{
public:
typedef WCHAR T;
};
# define _RTL_CONSTANT_STRING_remove_const_macro(s) (const_cast<_RTL_CONSTANT_STRING_remove_const_template_class<sizeof((s)[0])>::T*>(s))
}
# else
char _RTL_CONSTANT_STRING_type_check(const void* s);
# define _RTL_CONSTANT_STRING_remove_const_macro(s) (s)
# endif // __cplusplus
# define RTL_CONSTANT_STRING(s) \
{ \
sizeof(s) - sizeof((s)[0]), sizeof(s) / (sizeof(_RTL_CONSTANT_STRING_type_check(s))), _RTL_CONSTANT_STRING_remove_const_macro(s) \
}
#endif // RTL_CONSTANT_STRING
#if defined(__cplusplus)
extern "C"
{
#endif
#ifndef OBJECT_TYPE_CREATE
# define OBJECT_TYPE_CREATE (0x0001)
#endif // OBJECT_TYPE_CREATE
#ifndef OBJECT_TYPE_ALL_ACCESS
# define OBJECT_TYPE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
#endif // OBJECT_TYPE_ALL_ACCESS
#ifndef DIRECTORY_QUERY
# define DIRECTORY_QUERY (0x0001)
#endif // DIRECTORY_QUERY
#ifndef DIRECTORY_TRAVERSE
# define DIRECTORY_TRAVERSE (0x0002)
#endif // DIRECTORY_TRAVERSE
#ifndef DIRECTORY_CREATE_OBJECT
# define DIRECTORY_CREATE_OBJECT (0x0004)
#endif // DIRECTORY_CREATE_OBJECT
#ifndef DIRECTORY_CREATE_SUBDIRECTORY
# define DIRECTORY_CREATE_SUBDIRECTORY (0x0008)
#endif // DIRECTORY_CREATE_SUBDIRECTORY
#ifndef DIRECTORY_ALL_ACCESS
# define DIRECTORY_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0xF)
#endif // DIRECTORY_ALL_ACCESS
#ifndef SYMBOLIC_LINK_QUERY
# define SYMBOLIC_LINK_QUERY (0x0001)
#endif // SYMBOLIC_LINK_QUERY
#ifndef SYMBOLIC_LINK_ALL_ACCESS
# define SYMBOLIC_LINK_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
#endif // SYMBOLIC_LINK_ALL_ACCESS
#if !defined(_NTDEF_) && !defined(_NTSTATUS_)
typedef _Success_(return >= 0) LONG NTSTATUS;
typedef NTSTATUS* PNTSTATUS;
# define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)
# define NT_INFORMATION(Status) ((((ULONG)(Status)) >> 30) == 1)
# define NT_WARNING(Status) ((((ULONG)(Status)) >> 30) == 2)
# define NT_ERROR(Status) ((((ULONG)(Status)) >> 30) == 3)
#endif
typedef enum _SECTION_INHERIT
{
ViewShare = 1,
ViewUnmap = 2
} SECTION_INHERIT;
//
// Section Access Rights.
//
#ifndef SECTION_QUERY
# define SECTION_QUERY 0x0001
#endif // SECTION_QUERY
#ifndef SECTION_MAP_WRITE
# define SECTION_MAP_WRITE 0x0002
#endif // SECTION_MAP_WRITE
#ifndef SECTION_MAP_READ
# define SECTION_MAP_READ 0x0004
#endif // SECTION_MAP_READ
#ifndef SECTION_MAP_EXECUTE
# define SECTION_MAP_EXECUTE 0x0008
#endif // SECTION_MAP_EXECUTE
#ifndef SECTION_EXTEND_SIZE
# define SECTION_EXTEND_SIZE 0x0010
#endif // SECTION_EXTEND_SIZE
#ifndef SECTION_MAP_EXECUTE_EXPLICIT
# define SECTION_MAP_EXECUTE_EXPLICIT 0x0020 // not included in SECTION_ALL_ACCESS
#endif // SECTION_MAP_EXECUTE_EXPLICIT
#ifndef SECTION_ALL_ACCESS
# define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_WRITE | SECTION_MAP_READ | SECTION_MAP_EXECUTE | SECTION_EXTEND_SIZE)
#endif // SECTION_ALL_ACCESS
typedef struct _OBJECT_BASIC_INFORMATION
{
ULONG Attributes;
ACCESS_MASK DesiredAccess;
ULONG HandleCount;
ULONG ReferenceCount;
ULONG PagedPoolUsage;
ULONG NonPagedPoolUsage;
ULONG Reserved[3];
ULONG NameInformationLength;
ULONG TypeInformationLength;
ULONG SecurityDescriptorLength;
LARGE_INTEGER CreationTime;
} OBJECT_BASIC_INFORMATION, *POBJECT_BASIC_INFORMATION;
typedef struct _OBJECT_TYPE_INFORMATION
{
UNICODE_STRING TypeName;
ULONG TotalNumberOfObjects;
ULONG TotalNumberOfHandles;
ULONG TotalPagedPoolUsage;
ULONG TotalNonPagedPoolUsage;
ULONG TotalNamePoolUsage;
ULONG TotalHandleTableUsage;
ULONG HighWaterNumberOfObjects;
ULONG HighWaterNumberOfHandles;
ULONG HighWaterPagedPoolUsage;
ULONG HighWaterNonPagedPoolUsage;
ULONG HighWaterNamePoolUsage;
ULONG HighWaterHandleTableUsage;
ULONG InvalidAttributes;
GENERIC_MAPPING GenericMapping;
ULONG ValidAccessMask;
BOOLEAN SecurityRequired;
BOOLEAN MaintainHandleCount;
UCHAR TypeIndex;
CHAR ReservedByte;
ULONG PoolType;
ULONG DefaultPagedPoolCharge;
ULONG DefaultNonPagedPoolCharge;
} OBJECT_TYPE_INFORMATION, *POBJECT_TYPE_INFORMATION;
typedef struct _OBJECT_TYPES_INFORMATION
{
ULONG NumberOfTypes;
OBJECT_TYPE_INFORMATION TypeInformation[ANYSIZE_ARRAY];
} OBJECT_TYPES_INFORMATION, *POBJECT_TYPES_INFORMATION;
typedef struct _OBJECT_DIRECTORY_INFORMATION
{
UNICODE_STRING Name;
UNICODE_STRING TypeName;
} OBJECT_DIRECTORY_INFORMATION, *POBJECT_DIRECTORY_INFORMATION;
typedef enum _ATOM_INFORMATION_CLASS
{
AtomBasicInformation,
AtomTableInformation,
} ATOM_INFORMATION_CLASS;
typedef enum _EVENT_INFORMATION_CLASS
{
EventBasicInformation
} EVENT_INFORMATION_CLASS;
typedef enum _IO_COMPLETION_INFORMATION_CLASS
{
IoCompletionBasicInformation
} IO_COMPLETION_INFORMATION_CLASS, *PIO_COMPLETION_INFORMATION_CLASS;
typedef enum _KEY_INFORMATION_CLASS
{
KeyBasicInformation,
KeyNodeInformation,
KeyFullInformation,
KeyNameInformation,
KeyCachedInformation,
KeyFlagsInformation,
KeyVirtualizationInformation,
KeyHandleTagsInformation,
MaxKeyInfoClass // MaxKeyInfoClass should always be the last enum
} KEY_INFORMATION_CLASS;
typedef enum _KEY_VALUE_INFORMATION_CLASS
{
KeyValueBasicInformation,
KeyValueFullInformation,
KeyValuePartialInformation,
KeyValueFullInformationAlign64,
KeyValuePartialInformationAlign64,
MaxKeyValueInfoClass // MaxKeyValueInfoClass should always be the last enum
} KEY_VALUE_INFORMATION_CLASS;
#if !defined(_WDMDDK_) && !defined(_WDM_INCLUDED_) && !defined(_DDK_DRIVER_) && !defined(WINAPI_FAMILY_PARTITION) && !defined(WINAPI_PARTITION_DESKTOP) && \
!defined(WINAPI_PARTITION_SYSTEM)
/* newer Windows Kits have this one, so we check for WINAPI_FAMILY_PARTITION and friends */
typedef enum _KEY_SET_INFORMATION_CLASS
{
KeyWriteTimeInformation,
KeyWow64FlagsInformation,
KeyControlFlagsInformation,
KeySetVirtualizationInformation,
KeySetDebugInformation,
KeySetHandleTagsInformation,
MaxKeySetInfoClass // MaxKeySetInfoClass should always be the last enum
} KEY_SET_INFORMATION_CLASS;
#endif
typedef enum _MUTANT_INFORMATION_CLASS
{
MutantBasicInformation,
MutantOwnerInformation
} MUTANT_INFORMATION_CLASS;
typedef enum _SECTION_INFORMATION_CLASS
{
SectionBasicInformation,
SectionImageInformation
} SECTION_INFORMATION_CLASS;
typedef enum _SEMAPHORE_INFORMATION_CLASS
{
SemaphoreBasicInformation
} SEMAPHORE_INFORMATION_CLASS;
typedef enum _TIMER_INFORMATION_CLASS
{
TimerBasicInformation
} TIMER_INFORMATION_CLASS;
typedef enum _EVENT_TYPE
{
NotificationEvent,
SynchronizationEvent
} EVENT_TYPE, *PEVENT_TYPE;
typedef struct _EVENT_BASIC_INFORMATION
{
EVENT_TYPE EventType;
LONG EventState;
} EVENT_BASIC_INFORMATION, *PEVENT_BASIC_INFORMATION;
typedef struct _IO_COMPLETION_BASIC_INFORMATION
{
LONG Depth;
} IO_COMPLETION_BASIC_INFORMATION, *PIO_COMPLETION_BASIC_INFORMATION;
typedef struct _KEY_BASIC_INFORMATION
{
LARGE_INTEGER LastWriteTime;
ULONG TitleIndex;
ULONG NameLength;
WCHAR Name[1]; // Variable length string
} KEY_BASIC_INFORMATION, *PKEY_BASIC_INFORMATION;
typedef struct _KEY_VALUE_BASIC_INFORMATION
{
ULONG TitleIndex;
ULONG Type;
ULONG NameLength;
WCHAR Name[1]; // Variable size
} KEY_VALUE_BASIC_INFORMATION, *PKEY_VALUE_BASIC_INFORMATION;
typedef struct _KEY_VALUE_FULL_INFORMATION
{
ULONG TitleIndex;
ULONG Type;
ULONG DataOffset;
ULONG DataLength;
ULONG NameLength;
WCHAR Name[1]; // Variable size
// Data[1]; // Variable size data not declared
} KEY_VALUE_FULL_INFORMATION, *PKEY_VALUE_FULL_INFORMATION;
typedef struct _KEY_VALUE_PARTIAL_INFORMATION
{
ULONG TitleIndex;
ULONG Type;
ULONG DataLength;
UCHAR Data[1]; // Variable size
} KEY_VALUE_PARTIAL_INFORMATION, *PKEY_VALUE_PARTIAL_INFORMATION;
typedef struct _KEY_VALUE_PARTIAL_INFORMATION_ALIGN64
{
ULONG Type;
ULONG DataLength;
UCHAR Data[1]; // Variable size
} KEY_VALUE_PARTIAL_INFORMATION_ALIGN64, *PKEY_VALUE_PARTIAL_INFORMATION_ALIGN64;
#if (_MSC_VER < 1500) || defined(DDKBUILD)
typedef struct _KEY_VALUE_ENTRY
{
PUNICODE_STRING ValueName;
ULONG DataLength;
ULONG DataOffset;
ULONG Type;
} KEY_VALUE_ENTRY, *PKEY_VALUE_ENTRY;
#endif
typedef struct _MUTANT_BASIC_INFORMATION
{
LONG CurrentCount;
BOOLEAN OwnedByCaller;
BOOLEAN AbandonedState;
} MUTANT_BASIC_INFORMATION, *PMUTANT_BASIC_INFORMATION;
typedef struct _SECTIONBASICINFO
{
PVOID BaseAddress; //-V122
ULONG AllocationAttributes;
LARGE_INTEGER MaximumSize;
} SECTION_BASIC_INFORMATION, *PSECTION_BASIC_INFORMATION;
#pragma warning(push)
#pragma warning(disable : 4201 4214)
typedef struct _SECTION_IMAGE_INFORMATION
{
PVOID TransferAddress; //-V122
ULONG ZeroBits;
ULONG MaximumStackSize;
ULONG CommittedStackSize;
ULONG SubSystemType;
union
{
struct
{
USHORT SubSystemMinorVersion;
USHORT SubSystemMajorVersion;
} minmaj;
ULONG SubSystemVersion;
};
ULONG GpValue;
USHORT ImageCharacteristics;
USHORT DllCharacteristics;
USHORT Machine;
BOOLEAN ImageContainsCode;
BOOLEAN ImageFlags;
ULONG ComPlusNativeReady : 1;
ULONG ComPlusILOnly : 1;
ULONG ImageDynamicallyRelocated : 1;
ULONG Reserved : 5;
ULONG LoaderFlags;
ULONG ImageFileSize;
ULONG CheckSum;
} SECTION_IMAGE_INFORMATION, *PSECTION_IMAGE_INFORMATION;
#pragma warning(pop)
typedef struct _SEMAPHORE_BASIC_INFORMATION
{
ULONG CurrentCount;
ULONG MaximumCount;
} SEMAPHORE_BASIC_INFORMATION, *PSEMAPHORE_BASIC_INFORMATION;
typedef struct _TIMER_BASIC_INFORMATION
{
LARGE_INTEGER RemainingTime;
BOOLEAN TimerState;
} TIMER_BASIC_INFORMATION, *PTIMER_BASIC_INFORMATION;
//
// The context structure is used when generating 8.3 names. The caller must
// always zero out the structure before starting a new generation sequence
//
typedef struct _GENERATE_NAME_CONTEXT
{
//
// The structure is divided into two strings. The Name, and extension.
// Each part contains the value that was last inserted in the name.
// The length values are in terms of wchars and not bytes. We also
// store the last index value used in the generation collision algorithm.
//
USHORT Checksum;
BOOLEAN ChecksumInserted;
_Field_range_(<=, 8) UCHAR NameLength; // not including extension
WCHAR NameBuffer[8]; // e.g., "ntoskrnl"
_Field_range_(<=, 4) ULONG ExtensionLength; // including dot
WCHAR ExtensionBuffer[4]; // e.g., ".exe"
ULONG LastIndexValue;
} GENERATE_NAME_CONTEXT;
typedef GENERATE_NAME_CONTEXT* PGENERATE_NAME_CONTEXT;
#ifndef PIO_APC_ROUTINE_DEFINED
# pragma warning(push) /* disable code analyzer warnings for ATL & WTL libraries */
# pragma warning(disable : 28301) /* warning C28301 : No annotations for first declaration of ... */
typedef VOID(NTAPI* PIO_APC_ROUTINE)(_In_ PVOID ApcContext, _In_ PIO_STATUS_BLOCK IoStatusBlock, _In_ ULONG Reserved);
# define PIO_APC_ROUTINE_DEFINED
# pragma warning(pop) /* restore code analyzer warnings*/
#endif // PIO_APC_ROUTINE_DEFINED
typedef enum _NT_FILE_INFORMATION_CLASS
{
FileInformationDirectory = 1,
FileInformationFullDirectory, // 2
FileInformationBothDirectory, // 3
FileInformationBasic, // 4
FileInformationStandard, // 5
FileInformationInternal, // 6
FileInformationEa, // 7
FileInformationAccess, // 8
FileInformationName, // 9
FileInformationRename, // 10
FileInformationLink, // 11
FileInformationNames, // 12
FileInformationDisposition, // 13
FileInformationPosition, // 14
FileInformationFullEa, // 15
FileInformationMode, // 16
FileInformationAlignment, // 17
FileInformationAll, // 18
FileInformationAllocation, // 19
FileInformationEndOfFile, // 20
FileInformationAlternateName, // 21
FileInformationStream, // 22
FileInformationPipe, // 23
FileInformationPipeLocal, // 24
FileInformationPipeRemote, // 25
FileInformationMailslotQuery, // 26
FileInformationMailslotSet, // 27
FileInformationCompression, // 28
FileInformationObjectId, // 29
FileInformationCompletion, // 30
FileInformationMoveCluster, // 31
FileInformationQuota, // 32
FileInformationReparsePoint, // 33
FileInformationNetworkOpen, // 34
FileInformationAttributeTag, // 35
FileInformationTracking, // 36
FileInformationIdBothDirectory, // 37
FileInformationIdFullDirectory, // 38
FileInformationValidDataLength, // 39
FileInformationShortName, // 40
FileInformationIoCompletionNotification, // 41
FileInformationIoStatusBlockRange, // 42
FileInformationIoPriorityHint, // 43
FileInformationSfioReserve, // 44
FileInformationSfioVolume, // 45
FileInformationHardLink, // 46
FileInformationProcessIdsUsingFile, // 47
FileInformationNormalizedName, // 48
FileInformationNetworkPhysicalName, // 49
FileInformationIdGlobalTxDirectory, // 50
FileInformationIsRemoteDevice, // 51
FileInformationAttributeCache, // 52
FileInformationMaximum,
} NT_FILE_INFORMATION_CLASS, *PNT_FILE_INFORMATION_CLASS;
typedef struct _FILE_STREAM_INFORMATION
{
ULONG NextEntryOffset;
ULONG StreamNameLength;
LARGE_INTEGER StreamSize;
LARGE_INTEGER StreamAllocationSize;
WCHAR StreamName[1];
} FILE_STREAM_INFORMATION, *PFILE_STREAM_INFORMATION;
typedef struct _FILE_DIRECTORY_INFORMATION
{
ULONG NextEntryOffset;
ULONG FileIndex;
LARGE_INTEGER CreationTime;
LARGE_INTEGER LastAccessTime;
LARGE_INTEGER LastWriteTime;
LARGE_INTEGER ChangeTime;
LARGE_INTEGER EndOfFile;
LARGE_INTEGER AllocationSize;
ULONG FileAttributes;
ULONG FileNameLength;
WCHAR FileName[1];
} FILE_DIRECTORY_INFORMATION, *PFILE_DIRECTORY_INFORMATION;
typedef struct _FILE_FULL_DIR_INFORMATION
{
ULONG NextEntryOffset;
ULONG FileIndex;
LARGE_INTEGER CreationTime;
LARGE_INTEGER LastAccessTime;
LARGE_INTEGER LastWriteTime;
LARGE_INTEGER ChangeTime;
LARGE_INTEGER EndOfFile;
LARGE_INTEGER AllocationSize;
ULONG FileAttributes;
ULONG FileNameLength;
ULONG EaSize;
WCHAR FileName[1];
} FILE_FULL_DIR_INFORMATION, *PFILE_FULL_DIR_INFORMATION;
typedef struct _FILE_ID_FULL_DIR_INFORMATION
{
ULONG NextEntryOffset;
ULONG FileIndex;
LARGE_INTEGER CreationTime;
LARGE_INTEGER LastAccessTime;
LARGE_INTEGER LastWriteTime;
LARGE_INTEGER ChangeTime;
LARGE_INTEGER EndOfFile;
LARGE_INTEGER AllocationSize;
ULONG FileAttributes;
ULONG FileNameLength;
ULONG EaSize;
LARGE_INTEGER FileId;
WCHAR FileName[1];
} FILE_ID_FULL_DIR_INFORMATION, *PFILE_ID_FULL_DIR_INFORMATION;
typedef struct _FILE_BOTH_DIR_INFORMATION
{
ULONG NextEntryOffset;
ULONG FileIndex;
LARGE_INTEGER CreationTime;
LARGE_INTEGER LastAccessTime;
LARGE_INTEGER LastWriteTime;
LARGE_INTEGER ChangeTime;
LARGE_INTEGER EndOfFile;
LARGE_INTEGER AllocationSize;
ULONG FileAttributes;
ULONG FileNameLength;
ULONG EaSize;
CCHAR ShortNameLength;
WCHAR ShortName[12];
WCHAR FileName[1];
} FILE_BOTH_DIR_INFORMATION, *PFILE_BOTH_DIR_INFORMATION;
typedef struct _FILE_ID_BOTH_DIR_INFORMATION
{
ULONG NextEntryOffset;
ULONG FileIndex;
LARGE_INTEGER CreationTime;
LARGE_INTEGER LastAccessTime;
LARGE_INTEGER LastWriteTime;
LARGE_INTEGER ChangeTime;
LARGE_INTEGER EndOfFile;
LARGE_INTEGER AllocationSize;
ULONG FileAttributes;
ULONG FileNameLength;
ULONG EaSize;
CCHAR ShortNameLength;
WCHAR ShortName[12];
LARGE_INTEGER FileId;
WCHAR FileName[1];
} FILE_ID_BOTH_DIR_INFORMATION, *PFILE_ID_BOTH_DIR_INFORMATION;
/* xref: https://googleprojectzero.blogspot.de/2016/02/the-definitive-guide-on-win32-to-nt.html */
typedef struct _RTL_RELATIVE_NAME
{
UNICODE_STRING RelativeName;
HANDLE ContainingDirectory; //-V122
void* CurDirRef; //-V122
} RTL_RELATIVE_NAME, *PRTL_RELATIVE_NAME;
typedef enum
{
RtlPathTypeUnknown,
RtlPathTypeUncAbsolute,
RtlPathTypeDriveAbsolute,
RtlPathTypeDriveRelative,
RtlPathTypeRooted,
RtlPathTypeRelative,
RtlPathTypeLocalDevice,
RtlPathTypeRootLocalDevice,
} RTL_PATH_TYPE;
//
// I/O completion port access rights
//
#ifndef IO_COMPLETION_QUERY_STATE
# define IO_COMPLETION_QUERY_STATE 0x0001
#endif // IO_COMPLETION_QUERY_STATE
#ifndef IO_COMPLETION_MODIFY_STATE
# define IO_COMPLETION_MODIFY_STATE 0x0002
#endif // IO_COMPLETION_MODIFY_STATE
#ifndef IO_COMPLETION_ALL_ACCESS
# define IO_COMPLETION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | IO_COMPLETION_QUERY_STATE | IO_COMPLETION_MODIFY_STATE)
#endif // IO_COMPLETION_ALL_ACCESS
#if !defined(DYNAMIC_NTNATIVE) || (!DYNAMIC_NTNATIVE)
// Creating object types
NTSTATUS
NTAPI
NtCreateIoCompletion(_Out_ PHANDLE IoCompletionHandle,
_In_ ACCESS_MASK DesiredAccess,
_Inout_opt_ POBJECT_ATTRIBUTES ObjectAttributes,
_In_opt_ ULONG Count);
NTSTATUS
NTAPI
NtCreateKey(_Out_ PHANDLE KeyHandle,
_In_ ACCESS_MASK DesiredAccess,
_In_ POBJECT_ATTRIBUTES ObjectAttributes,
_Reserved_ ULONG TitleIndex,
_In_opt_ PUNICODE_STRING Class,
_In_ ULONG CreateOptions,
_Out_opt_ PULONG Disposition);
NTSTATUS
NTAPI
NtCreateSection(_Out_ PHANDLE SectionHandle,
_In_ ACCESS_MASK DesiredAccess,
_In_opt_ POBJECT_ATTRIBUTES ObjectAttributes,
_In_opt_ PLARGE_INTEGER MaximumSize,
_In_ ULONG SectionPageProtection,
_In_ ULONG AllocationAttributes,
_In_opt_ HANDLE FileHandle);
// Opening object types
NTSTATUS
NTAPI
NtOpenDirectoryObject(_Out_ PHANDLE DirectoryHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes);
NTSTATUS
NTAPI
NtOpenEvent(_Out_ PHANDLE EventHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes);
NTSTATUS
NTAPI
NtOpenEventPair(_Out_ PHANDLE EventPairHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes);
# if defined(DDKBUILD)
NTSTATUS
NTAPI
NtOpenFile(_Out_ PHANDLE FileHandle,
_In_ ACCESS_MASK DesiredAccess,
_In_ POBJECT_ATTRIBUTES ObjectAttributes,
_Out_ PIO_STATUS_BLOCK IoStatusBlock,
_In_ ULONG ShareAccess,
_In_ ULONG OpenOptions);
# endif // DDKBUILD
NTSTATUS
NTAPI