-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathntdef.h
1361 lines (1104 loc) · 38.6 KB
/
ntdef.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
#pragma once
#pragma warning( push )
#pragma warning (disable : 4201 4324)
#include <ntstatus.h>
#define CONTAINING_RECORD(address, type, field) ((type *)( \
(char*)(address) - \
(UINT64)(&((type *)0)->field)))
typedef struct _UNICODE_STRING
{
UINT16 Length;
UINT16 MaximumLength;
CHAR16* Buffer;
} UNICODE_STRING, * PUNICODE_STRING;
typedef short CSHORT;
typedef unsigned short USHORT;
typedef long LONG;
typedef unsigned long ULONG;
typedef VOID* PVOID;
typedef void* HANDLE;
typedef HANDLE* PHANDLE;
typedef CHAR8 CCHAR;
typedef CCHAR KPROCESSOR_MODE;
typedef ULONG DEVICE_TYPE, ACCESS_MASK;
typedef long NTSTATUS;
typedef PVOID PIO_TIMER, PVPB, PSECURITY_DESCRIPTOR, PDRIVER_EXTENSION, PFAST_IO_DISPATCH, PDRIVER_INITIALIZE, PDRIVER_STARTIO, PDRIVER_UNLOAD, PDRIVER_DISPATCH;
typedef unsigned char BYTE;
typedef struct _OBJECT_TYPE OBJECT_TYPE, * POBJECT_TYPE;
typedef struct _OBJECT_ATTRIBUTES {
ULONG Length;
HANDLE RootDirectory;
PUNICODE_STRING ObjectName;
ULONG Attributes;
PVOID SecurityDescriptor;
PVOID SecurityQualityOfService;
} OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES;
typedef enum _FILE_INFORMATION_CLASS {
FileDirectoryInformation = 1,
FileFullDirectoryInformation, // 2
FileBothDirectoryInformation, // 3
FileBasicInformation, // 4
FileStandardInformation, // 5
FileInternalInformation, // 6
FileEaInformation, // 7
FileAccessInformation, // 8
FileNameInformation, // 9
FileRenameInformation, // 10
FileLinkInformation, // 11
FileNamesInformation, // 12
FileDispositionInformation, // 13
FilePositionInformation, // 14
FileFullEaInformation, // 15
FileModeInformation, // 16
FileAlignmentInformation, // 17
FileAllInformation, // 18
FileAllocationInformation, // 19
FileEndOfFileInformation, // 20
FileAlternateNameInformation, // 21
FileStreamInformation, // 22
FilePipeInformation, // 23
FilePipeLocalInformation, // 24
FilePipeRemoteInformation, // 25
FileMailslotQueryInformation, // 26
FileMailslotSetInformation, // 27
FileCompressionInformation, // 28
FileObjectIdInformation, // 29
FileCompletionInformation, // 30
FileMoveClusterInformation, // 31
FileQuotaInformation, // 32
FileReparsePointInformation, // 33
FileNetworkOpenInformation, // 34
FileAttributeTagInformation, // 35
FileTrackingInformation, // 36
FileIdBothDirectoryInformation, // 37
FileIdFullDirectoryInformation, // 38
FileValidDataLengthInformation, // 39
FileShortNameInformation, // 40
FileIoCompletionNotificationInformation, // 41
FileIoStatusBlockRangeInformation, // 42
FileIoPriorityHintInformation, // 43
FileSfioReserveInformation, // 44
FileSfioVolumeInformation, // 45
FileHardLinkInformation, // 46
FileProcessIdsUsingFileInformation, // 47
FileNormalizedNameInformation, // 48
FileNetworkPhysicalNameInformation, // 49
FileIdGlobalTxDirectoryInformation, // 50
FileIsRemoteDeviceInformation, // 51
FileUnusedInformation, // 52
FileNumaNodeInformation, // 53
FileStandardLinkInformation, // 54
FileRemoteProtocolInformation, // 55
//
// These are special versions of these operations (defined earlier)
// which can be used by kernel mode drivers only to bypass security
// access checks for Rename and HardLink operations. These operations
// are only recognized by the IOManager, a file system should never
// receive these.
//
FileRenameInformationBypassAccessCheck, // 56
FileLinkInformationBypassAccessCheck, // 57
//
// End of special information classes reserved for IOManager.
//
FileVolumeNameInformation, // 58
FileIdInformation, // 59
FileIdExtdDirectoryInformation, // 60
FileReplaceCompletionInformation, // 61
FileHardLinkFullIdInformation, // 62
FileIdExtdBothDirectoryInformation, // 63
FileDispositionInformationEx, // 64
FileRenameInformationEx, // 65
FileRenameInformationExBypassAccessCheck, // 66
FileDesiredStorageClassInformation, // 67
FileStatInformation, // 68
FileMemoryPartitionInformation, // 69
FileStatLxInformation, // 70
FileCaseSensitiveInformation, // 71
FileLinkInformationEx, // 72
FileLinkInformationExBypassAccessCheck, // 73
FileStorageReserveIdInformation, // 74
FileCaseSensitiveInformationForceAccessCheck, // 75
FileKnownFolderInformation, // 76
FileMaximumInformation
} FILE_INFORMATION_CLASS, * PFILE_INFORMATION_CLASS;
typedef struct _FILE_STANDARD_INFORMATION {
UINT64 AllocationSize;
UINT64 EndOfFile;
ULONG NumberOfLinks;
BOOLEAN DeletePending;
BOOLEAN Directory;
} FILE_STANDARD_INFORMATION, * PFILE_STANDARD_INFORMATION;
typedef enum _MODE {
KernelMode,
UserMode,
MaximumMode
} MODE;
typedef enum _POOL_TYPE {
NonPagedPool,
NonPagedPoolExecute = NonPagedPool,
PagedPool,
NonPagedPoolMustSucceed = NonPagedPool + 2,
DontUseThisType,
NonPagedPoolCacheAligned = NonPagedPool + 4,
PagedPoolCacheAligned,
NonPagedPoolCacheAlignedMustS = NonPagedPool + 6,
MaxPoolType,
NonPagedPoolBase = 0,
NonPagedPoolBaseMustSucceed = NonPagedPoolBase + 2,
NonPagedPoolBaseCacheAligned = NonPagedPoolBase + 4,
NonPagedPoolBaseCacheAlignedMustS = NonPagedPoolBase + 6,
NonPagedPoolSession = 32,
PagedPoolSession = NonPagedPoolSession + 1,
NonPagedPoolMustSucceedSession = PagedPoolSession + 1,
DontUseThisTypeSession = NonPagedPoolMustSucceedSession + 1,
NonPagedPoolCacheAlignedSession = DontUseThisTypeSession + 1,
PagedPoolCacheAlignedSession = NonPagedPoolCacheAlignedSession + 1,
NonPagedPoolCacheAlignedMustSSession = PagedPoolCacheAlignedSession + 1,
NonPagedPoolNx = 512,
NonPagedPoolNxCacheAligned = NonPagedPoolNx + 4,
NonPagedPoolSessionNx = NonPagedPoolNx + 32,
} POOL_TYPE;
typedef struct _RELOC_BLOCK_HDR
{
UINT32 PageRVA;
UINT32 BlockSize;
} RELOC_BLOCK_HDR, *PRELOC_BLOCK_HDR;
typedef struct _RELOC_ENTRY
{
UINT16 Offset : 12;
UINT16 Type : 4;
} RELOC_ENTRY, * PRELOC_ENTRY;
typedef struct _RELOC_NAME_TABLE_ENTRY
{
UINT16 Hint;
CHAR8 Name[];
} RELOC_NAME_TABLE_ENTRY, PRELOC_NAME_TABLE_ENTRY;
//
// The following are masks for the predefined standard access types
//
#define DELETE (0x00010000L)
#define READ_CONTROL (0x00020000L)
#define WRITE_DAC (0x00040000L)
#define WRITE_OWNER (0x00080000L)
#define SYNCHRONIZE (0x00100000L)
#define STANDARD_RIGHTS_REQUIRED (0x000F0000L)
#define STANDARD_RIGHTS_READ (READ_CONTROL)
#define STANDARD_RIGHTS_WRITE (READ_CONTROL)
#define STANDARD_RIGHTS_EXECUTE (READ_CONTROL)
#define STANDARD_RIGHTS_ALL (0x001F0000L)
#define SPECIFIC_RIGHTS_ALL (0x0000FFFFL)
//
// AccessSystemAcl access type
//
#define ACCESS_SYSTEM_SECURITY (0x01000000L)
//
// MaximumAllowed access type
//
#define MAXIMUM_ALLOWED (0x02000000L)
//
// These are the generic rights.
//
#define GENERIC_READ (0x80000000L)
#define GENERIC_WRITE (0x40000000L)
#define GENERIC_EXECUTE (0x20000000L)
#define GENERIC_ALL (0x10000000L)
#define OBJ_INHERIT 0x00000002L
#define OBJ_PERMANENT 0x00000010L
#define OBJ_EXCLUSIVE 0x00000020L
#define OBJ_CASE_INSENSITIVE 0x00000040L
#define OBJ_OPENIF 0x00000080L
#define OBJ_OPENLINK 0x00000100L
#define OBJ_KERNEL_HANDLE 0x00000200L
#define OBJ_FORCE_ACCESS_CHECK 0x00000400L
#define OBJ_IGNORE_IMPERSONATED_DEVICEMAP 0x00000800L
#define OBJ_DONT_REPARSE 0x00001000L
#define OBJ_VALID_ATTRIBUTES 0x00001FF2L
//
// Define the create disposition values
//
#define FILE_SUPERSEDE 0x00000000
#define FILE_OPEN 0x00000001
#define FILE_CREATE 0x00000002
#define FILE_OPEN_IF 0x00000003
#define FILE_OVERWRITE 0x00000004
#define FILE_OVERWRITE_IF 0x00000005
#define FILE_MAXIMUM_DISPOSITION 0x00000005
//
// Define the create/open option flags
//
#define FILE_DIRECTORY_FILE 0x00000001
#define FILE_WRITE_THROUGH 0x00000002
#define FILE_SEQUENTIAL_ONLY 0x00000004
#define FILE_NO_INTERMEDIATE_BUFFERING 0x00000008
#define FILE_SYNCHRONOUS_IO_ALERT 0x00000010
#define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020
#define FILE_NON_DIRECTORY_FILE 0x00000040
#define FILE_CREATE_TREE_CONNECTION 0x00000080
#define FILE_COMPLETE_IF_OPLOCKED 0x00000100
#define FILE_NO_EA_KNOWLEDGE 0x00000200
#define FILE_OPEN_REMOTE_INSTANCE 0x00000400
#define FILE_RANDOM_ACCESS 0x00000800
#define FILE_DELETE_ON_CLOSE 0x00001000
#define FILE_OPEN_BY_FILE_ID 0x00002000
#define FILE_OPEN_FOR_BACKUP_INTENT 0x00004000
#define FILE_NO_COMPRESSION 0x00008000
#define FILE_OPEN_REQUIRING_OPLOCK 0x00010000
#define FILE_DISALLOW_EXCLUSIVE 0x00020000
#define FILE_SESSION_AWARE 0x00040000
//
// CreateOptions flag to pass in call to CreateFile to allow the write through xro.sys
//
#define FILE_RESERVE_OPFILTER 0x00100000
#define FILE_OPEN_REPARSE_POINT 0x00200000
#define FILE_OPEN_NO_RECALL 0x00400000
#define FILE_OPEN_FOR_FREE_SPACE_QUERY 0x00800000
#define FILE_ANY_ACCESS 0
#define FILE_SPECIAL_ACCESS (FILE_ANY_ACCESS)
#define FILE_READ_ACCESS ( 0x0001 ) // file & pipe
#define FILE_WRITE_ACCESS ( 0x0002 ) // file & pipe
typedef NTSTATUS (*p_ObReferenceObjectByName)(PUNICODE_STRING ObjectName,
ULONG Attributes,
PVOID AccessState,
ACCESS_MASK DesiredAccess,
POBJECT_TYPE ObjectType,
KPROCESSOR_MODE AccessMode,
PVOID ParseContext OPTIONAL,
PVOID* Object);
#define IRP_MJ_MAXIMUM_FUNCTION 0x1b
extern p_ObReferenceObjectByName ObReferenceObjectByName;
typedef struct _MDL {
struct _MDL* Next;
CSHORT Size;
CSHORT MdlFlags;
struct _EPROCESS* Process;
PVOID MappedSystemVa; /* see creators for field size annotations. */
PVOID StartVa; /* see creators for validity; could be address 0. */
ULONG ByteCount;
ULONG ByteOffset;
} MDL, * PMDL;
typedef struct __declspec(align(16)) _DEVICE_OBJECT {
CSHORT Type;
USHORT Size;
LONG ReferenceCount;
struct _DRIVER_OBJECT* DriverObject;
struct _DEVICE_OBJECT* NextDevice;
struct _DEVICE_OBJECT* AttachedDevice;
struct _IRP* CurrentIrp;
PIO_TIMER Timer;
ULONG Flags;
ULONG Characteristics;
volatile PVPB Vpb;
PVOID DeviceExtension;
DEVICE_TYPE DeviceType;
CCHAR StackSize;
union {
LIST_ENTRY ListEntry;
BYTE Wcb[0x48];
} Queue;
ULONG AlignmentRequirement;
ULONG pad0;
BYTE DeviceQueue[0x28];
BYTE Dpc[0x40];
ULONG ActiveThreadCount;
ULONG pad1;
PSECURITY_DESCRIPTOR SecurityDescriptor;
BYTE DeviceLock[0x18];
USHORT SectorSize;
USHORT Spare1;
struct _DEVOBJ_EXTENSION* DeviceObjectExtension;
PVOID Reserved;
} DEVICE_OBJECT, * PDEVICE_OBJECT;
typedef struct _DEVOBJ_EXTENSION {
CSHORT Type;
USHORT Size;
PDEVICE_OBJECT DeviceObject; // owning device object
//
// The remaining fields are reserved for system use.
//
ULONG PowerFlags;
struct _DEVICE_OBJECT_POWER_EXTENSION* Dope;
ULONG ExtensionFlags;
PVOID DeviceNode;
PDEVICE_OBJECT AttachedTo;
volatile LONG StartIoCount;
LONG StartIoKey;
ULONG StartIoFlags;
PVPB Vpb;
PVOID DependencyNode;
PVOID InterruptContext;
volatile LONG InterruptCount;
volatile PVOID VerifierContext;
} DEVOBJ_EXTENSION, * PDEVOBJ_EXTENSION;
typedef struct _DRIVER_OBJECT {
CSHORT Type;
CSHORT Size;
PDEVICE_OBJECT DeviceObject;
ULONG Flags;
PVOID DriverStart;
ULONG DriverSize;
PVOID DriverSection;
PDRIVER_EXTENSION DriverExtension;
UNICODE_STRING DriverName;
PUNICODE_STRING HardwareDatabase;
PFAST_IO_DISPATCH FastIoDispatch;
PDRIVER_INITIALIZE DriverInit;
PDRIVER_STARTIO DriverStartIo;
PDRIVER_UNLOAD DriverUnload;
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION + 1];
} DRIVER_OBJECT, * PDRIVER_OBJECT;
typedef struct _LOADER_PARAMETER_BLOCK
{
UINT32 OsMajorVersion;
UINT32 OsMinorVersion;
UINT32 Size;
UINT32 OsLoaderSecurityVersion;
struct _LIST_ENTRY LoadOrderListHead;
struct _LIST_ENTRY MemoryDescriptorListHead;
struct _LIST_ENTRY BootDriverListHead;
struct _LIST_ENTRY EarlyLaunchListHead;
struct _LIST_ENTRY CoreDriverListHead;
struct _LIST_ENTRY CoreExtensionsDriverListHead;
struct _LIST_ENTRY TpmCoreDriverListHead;
} LOADER_PARAMETER_BLOCK, * PLOADER_PARAMETER_BLOCK;
typedef struct _KLDR_DATA_TABLE_ENTRY
{
struct _LIST_ENTRY InLoadOrderLinks;
VOID* ExceptionTable;
UINT32 ExceptionTableSize;
VOID* GpValue;
struct _NON_PAGED_DEBUG_INFO* NonPagedDebugInfo;
VOID* DllBase;
VOID* EntryPoint;
UINT32 SizeOfImage;
struct _UNICODE_STRING FullDllName;
struct _UNICODE_STRING BaseDllName;
UINT32 Flags;
UINT16 LoadCount;
union
{
UINT16 SignatureLevel : 4;
UINT16 SignatureType : 3;
UINT16 Unused : 9;
UINT16 EntireField;
} u1;
VOID* SectionPointer;
UINT32 CheckSum;
UINT32 CoverageSectionSize;
VOID* CoverageSection;
VOID* LoadedImports;
VOID* Spare;
UINT32 SizeOfImageNotRounded;
UINT32 TimeDateStamp;
} KLDR_DATA_TABLE_ENTRY, * PKLDR_DATA_TABLE_ENTRY;
typedef struct _IMAGE_FILE_HEADER
{
UINT16 Machine;
UINT16 NumberOfSections;
UINT32 TimeDateStamp;
UINT32 PointerToSymbolTable;
UINT32 NumberOfSymbols;
UINT16 SizeOfOptionalHeader;
UINT16 Characteristics;
} IMAGE_FILE_HEADER, * PIMAGE_FILE_HEADER;
typedef struct _IMAGE_DATA_DIRECTORY
{
UINT32 VirtualAddress;
UINT32 Size;
} IMAGE_DATA_DIRECTORY, * PIMAGE_DATA_DIRECTORY;
#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
typedef struct _IMAGE_OPTIONAL_HEADER64
{
UINT16 Magic;
UINT8 MajorLinkerVersion;
UINT8 MinorLinkerVersion;
UINT32 SizeOfCode;
UINT32 SizeOfInitializedData;
UINT32 SizeOfUninitializedData;
UINT32 AddressOfEntryPoint;
UINT32 BaseOfCode;
UINT64 ImageBase;
UINT32 SectionAlignment;
UINT32 FileAlignment;
UINT16 MajorOperatingSystemVersion;
UINT16 MinorOperatingSystemVersion;
UINT16 MajorImageVersion;
UINT16 MinorImageVersion;
UINT16 MajorSubsystemVersion;
UINT16 MinorSubsystemVersion;
UINT32 Win32VersionValue;
UINT32 SizeOfImage;
UINT32 SizeOfHeaders;
UINT32 CheckSum;
UINT16 Subsystem;
UINT16 DllCharacteristics;
UINT64 SizeOfStackReserve;
UINT64 SizeOfStackCommit;
UINT64 SizeOfHeapReserve;
UINT64 SizeOfHeapCommit;
UINT32 LoaderFlags;
UINT32 NumberOfRvaAndSizes;
IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
} IMAGE_OPTIONAL_HEADER64, * PIMAGE_OPTIONAL_HEADER64;
typedef struct _IMAGE_NT_HEADERS64
{
UINT32 Signature;
IMAGE_FILE_HEADER FileHeader;
IMAGE_OPTIONAL_HEADER64 OptionalHeader;
} IMAGE_NT_HEADERS64, * PIMAGE_NT_HEADERS64, IMAGE_NT_HEADERS, * PIMAGE_NT_HEADERS;
typedef struct _IMAGE_DOS_HEADER
{
UINT16 e_magic; // Magic number
UINT16 e_cblp; // Bytes on last page of file
UINT16 e_cp; // Pages in file
UINT16 e_crlc; // Relocations
UINT16 e_cparhdr; // Size of header in paragraphs
UINT16 e_minalloc; // Minimum extra paragraphs needed
UINT16 e_maxalloc; // Maximum extra paragraphs needed
UINT16 e_ss; // Initial (relative) SS value
UINT16 e_sp; // Initial SP value
UINT16 e_csum; // Checksum
UINT16 e_ip; // Initial IP value
UINT16 e_cs; // Initial (relative) CS value
UINT16 e_lfarlc; // File address of relocation table
UINT16 e_ovno; // Overlay number
UINT16 e_res[4]; // Reserved words
UINT16 e_oemid; // OEM identifier (for e_oeminfo)
UINT16 e_oeminfo; // OEM information; e_oemid specific
UINT16 e_res2[10]; // Reserved words
INT32 e_lfanew; // File address of new exe header
} IMAGE_DOS_HEADER, * PIMAGE_DOS_HEADER;
#define IMAGE_SIZEOF_SHORT_NAME 8
typedef struct _IMAGE_SECTION_HEADER
{
UINT8 Name[IMAGE_SIZEOF_SHORT_NAME];
union
{
UINT32 PhysicalAddress;
UINT32 VirtualSize;
} Misc;
UINT32 VirtualAddress;
UINT32 SizeOfRawData;
UINT32 PointerToRawData;
UINT32 PointerToRelocations;
UINT32 PointerToLinenumbers;
UINT16 NumberOfRelocations;
UINT16 NumberOfLinenumbers;
UINT32 Characteristics;
} IMAGE_SECTION_HEADER, * PIMAGE_SECTION_HEADER;
typedef struct _IMAGE_EXPORT_DIRECTORY
{
UINT32 Characteristics;
UINT32 TimeDateStamp;
UINT16 MajorVersion;
UINT16 MinorVersion;
UINT32 Name;
UINT32 Base;
UINT32 NumberOfFunctions;
UINT32 NumberOfNames;
UINT32 AddressOfFunctions;
UINT32 AddressOfNames;
UINT32 AddressOfNameOrdinals;
} IMAGE_EXPORT_DIRECTORY, * PIMAGE_EXPORT_DIRECTORY;
typedef struct _IMAGE_IMPORT_DESCRIPTOR {
UINT32 LookupTableRVA; // RVA to original unbound IAT (PIMAGE_THUNK_DATA)
UINT32 TimeDateStamp; // 0 if not bound,
// -1 if bound, and real date\time stamp
// in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT (new BIND)
// O.W. date/time stamp of DLL bound to (Old BIND)
UINT32 ForwarderChain; // -1 if no forwarders
UINT32 Name;
UINT32 ImportAddressTable; // RVA to IAT (if bound this IAT has actual addresses)
} IMAGE_IMPORT_DESCRIPTOR;
typedef IMAGE_IMPORT_DESCRIPTOR * PIMAGE_IMPORT_DESCRIPTOR;
typedef struct _IMAGE_IMPORT_BY_NAME {
UINT16 Hint;
CHAR8 Name[];
} IMAGE_IMPORT_BY_NAME, * PIMAGE_IMPORT_BY_NAME;
typedef struct _IO_STATUS_BLOCK {
union {
UINT32 Status;
VOID* Pointer;
};
UINT64 Information;
} IO_STATUS_BLOCK, * PIO_STATUS_BLOCK;
typedef struct _KDEVICE_QUEUE_ENTRY {
LIST_ENTRY DeviceListEntry;
UINT32 SortKey;
BOOLEAN Inserted;
} KDEVICE_QUEUE_ENTRY, * PKDEVICE_QUEUE_ENTRY, * PRKDEVICE_QUEUE_ENTRY;
typedef struct _KAPC {
UINT8 Type;
UINT8 AllFlags;
UINT8 Size;
UINT8 SpareByte1;
UINT32 SpareLong0;
struct _KTHREAD* Thread;
LIST_ENTRY ApcListEntry;
VOID* Reserved[3];
VOID* NormalContext;
VOID* SystemArgument1;
VOID* SystemArgument2;
CHAR8 ApcStateIndex;
CHAR8 ApcMode;
BOOLEAN Inserted;
} KAPC, * PKAPC, * PRKAPC;
// TODO: Clean this up
typedef struct _IO_STACK_LOCATION {
UINT8 MajorFunction;
UINT8 MinorFunction;
UINT8 Flags;
UINT8 Control;
//
// The following user parameters are based on the service that is being
// invoked. Drivers and file systems can determine which set to use based
// on the above major and minor function codes.
//
// Stupid me deleted all the declspec aligns and they need to be added back
union {
//
// System service parameters for: NtCreateFile
//
struct {
VOID* SecurityContext;
UINT32 Options;
UINT16 FileAttributes;
UINT16 ShareAccess;
UINT32 EaLength;
} Create;
//
// System service parameters for: NtCreateNamedPipeFile
//
// Notice that the fields in the following parameter structure must
// match those for the create structure other than the last longword.
// This is so that no distinctions need be made by the I/O system's
// parse routine other than for the last longword.
//
struct {
VOID* SecurityContext;
UINT32 Options;
UINT16 Reserved;
UINT16 ShareAccess;
VOID* Parameters;
} CreatePipe;
//
// System service parameters for: NtCreateMailslotFile
//
// Notice that the fields in the following parameter structure must
// match those for the create structure other than the last longword.
// This is so that no distinctions need be made by the I/O system's
// parse routine other than for the last longword.
//
struct {
VOID* SecurityContext;
UINT32 Options;
UINT16 Reserved;
UINT16 ShareAccess;
VOID* Parameters;
} CreateMailslot;
//
// System service parameters for: NtReadFile
//
struct {
UINT32 Length;
UINT32 Key;
#if defined(_WIN64)
UINT32 Flags;
#endif
UINT64 ByteOffset;
} Read;
//
// System service parameters for: NtWriteFile
//
struct {
UINT32 Length;
UINT32 Key;
#if defined(_WIN64)
UINT32 Flags;
#endif
UINT64 ByteOffset;
} Write;
//
// System service parameters for: NtQueryDirectoryFile
//
struct {
UINT32 Length;
PUNICODE_STRING FileName;
UINT32 FileInformationClass;
UINT32 FileIndex;
} QueryDirectory;
//
// System service parameters for: NtNotifyChangeDirectoryFile / NtNotifyChangeDirectoryFileEx
//
struct {
UINT32 Length;
UINT32 CompletionFilter;
} NotifyDirectory;
//
// System service parameters for: NtNotifyChangeDirectoryFile / NtNotifyChangeDirectoryFileEx
//
// For minor code IRP_MN_NOTIFY_CHANGE_DIRECTORY_EX
// N.B. Keep Length and CompletionFilter aligned with NotifyDirectory.
//
struct {
UINT32 Length;
UINT32 CompletionFilter;
UINT32 DirectoryNotifyInformationClass;
} NotifyDirectoryEx;
//
// System service parameters for: NtQueryInformationFile
//
struct {
UINT32 Length;
UINT32 FileInformationClass;
} QueryFile;
//
// System service parameters for: NtSetInformationFile
//
struct {
UINT32 Length;
UINT32 FileInformationClass;
VOID* FileObject;
union {
struct {
BOOLEAN ReplaceIfExists;
BOOLEAN AdvanceOnly;
};
UINT32 ClusterCount;
VOID* DeleteHandle;
};
} SetFile;
//
// System service parameters for: NtQueryEaFile
//
struct {
UINT32 Length;
VOID* EaList;
UINT32 EaListLength;
UINT32 EaIndex;
} QueryEa;
//
// System service parameters for: NtSetEaFile
//
struct {
UINT32 Length;
} SetEa;
//
// System service parameters for: NtQueryVolumeInformationFile
//
struct {
UINT32 Length;
UINT32 FsInformationClass;
} QueryVolume;
//
// System service parameters for: NtSetVolumeInformationFile
//
struct {
UINT32 Length;
UINT32 FsInformationClass;
} SetVolume;
//
// System service parameters for: NtFsControlFile
//
// Note that the user's output buffer is stored in the UserBuffer field
// and the user's input buffer is stored in the SystemBuffer field.
//
struct {
UINT32 OutputBufferLength;
UINT32 InputBufferLength;
UINT32 FsControlCode;
VOID* Type3InputBuffer;
} FileSystemControl;
//
// System service parameters for: NtLockFile/NtUnlockFile
//
struct {
UINT64* Length;
UINT32 Key;
UINT64 ByteOffset;
} LockControl;
//
// System service parameters for: NtFlushBuffersFile
//
// No extra user-supplied parameters.
//
//
// System service parameters for: NtCancelIoFile
//
// No extra user-supplied parameters.
//
//
// System service parameters for: NtDeviceIoControlFile
//
// Note that the user's output buffer is stored in the UserBuffer field
// and the user's input buffer is stored in the SystemBuffer field.
//
struct {
UINT32 OutputBufferLength;
UINT32 __declspec(align(8)) InputBufferLength;
UINT32 __declspec(align(8)) IoControlCode;
VOID* Type3InputBuffer;
} DeviceIoControl;
//
// System service parameters for: NtQuerySecurityObject
//
struct {
UINT32 SecurityInformation;
UINT32 Length;
} QuerySecurity;
//
// System service parameters for: NtSetSecurityObject
//
struct {
UINT32 SecurityInformation;
VOID* SecurityDescriptor;
} SetSecurity;
//
// Non-system service parameters.
//
// Parameters for MountVolume
//
struct {
VOID* Vpb;
VOID* DeviceObject;
} MountVolume;
//
// Parameters for VerifyVolume
//
struct {
VOID* Vpb;
VOID* DeviceObject;
} VerifyVolume;
//
// Parameters for Scsi with internal device control.
//
struct {
struct _SCSI_REQUEST_BLOCK* Srb;
} Scsi;
//
// System service parameters for: NtQueryQuotaInformationFile
//
struct {
UINT32 Length;
VOID* StartSid;
VOID* SidList;
UINT32 SidListLength;
} QueryQuota;
//
// System service parameters for: NtSetQuotaInformationFile
//
struct {
UINT32 Length;
} SetQuota;
//
// Parameters for IRP_MN_QUERY_DEVICE_RELATIONS
//
struct {
UINT32 Type;
} QueryDeviceRelations;
//
// Parameters for IRP_MN_QUERY_INTERFACE
//
struct {
CONST GUID* InterfaceType;
UINT16 Size;
UINT16 Version;
VOID* Interface;
VOID* InterfaceSpecificData;
} QueryInterface;
//
// Parameters for IRP_MN_QUERY_CAPABILITIES
//
struct {
VOID* Capabilities;
} DeviceCapabilities;
//
// Parameters for IRP_MN_FILTER_RESOURCE_REQUIREMENTS
//
struct {
VOID* IoResourceRequirementList;
} FilterResourceRequirements;
//
// Parameters for IRP_MN_READ_CONFIG and IRP_MN_WRITE_CONFIG
//
struct {
UINT32 WhichSpace;
VOID* Buffer;
UINT32 Offset;
UINT32 Length;
} ReadWriteConfig;
//
// Parameters for IRP_MN_SET_LOCK
//
struct {
BOOLEAN Lock;
} SetLock;
//