-
Notifications
You must be signed in to change notification settings - Fork 2
/
ntregapi.h
1410 lines (1304 loc) · 46.6 KB
/
ntregapi.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
/*
* Registry support functions
*
* This file is part of System Informer.
*/
#ifndef _NTREGAPI_H
#define _NTREGAPI_H
// Boot condition flags (NtInitializeRegistry)
#define REG_INIT_BOOT_SM 0x0000
#define REG_INIT_BOOT_SETUP 0x0001
#define REG_INIT_BOOT_ACCEPTED_BASE 0x0002
#define REG_INIT_BOOT_ACCEPTED_MAX REG_INIT_BOOT_ACCEPTED_BASE + 999
#define REG_MAX_KEY_VALUE_NAME_LENGTH 32767
#define REG_MAX_KEY_NAME_LENGTH 512
typedef enum _KEY_INFORMATION_CLASS
{
KeyBasicInformation, // KEY_BASIC_INFORMATION
KeyNodeInformation, // KEY_NODE_INFORMATION
KeyFullInformation, // KEY_FULL_INFORMATION
KeyNameInformation, // KEY_NAME_INFORMATION
KeyCachedInformation, // KEY_CACHED_INFORMATION
KeyFlagsInformation, // KEY_FLAGS_INFORMATION
KeyVirtualizationInformation, // KEY_VIRTUALIZATION_INFORMATION
KeyHandleTagsInformation, // KEY_HANDLE_TAGS_INFORMATION
KeyTrustInformation, // KEY_TRUST_INFORMATION
KeyLayerInformation, // KEY_LAYER_INFORMATION
MaxKeyInfoClass
} KEY_INFORMATION_CLASS;
typedef struct _KEY_BASIC_INFORMATION
{
LARGE_INTEGER LastWriteTime;
ULONG TitleIndex;
ULONG NameLength;
_Field_size_bytes_(NameLength) WCHAR Name[1];
} KEY_BASIC_INFORMATION, *PKEY_BASIC_INFORMATION;
typedef struct _KEY_NODE_INFORMATION
{
LARGE_INTEGER LastWriteTime;
ULONG TitleIndex;
ULONG ClassOffset;
ULONG ClassLength;
ULONG NameLength;
_Field_size_bytes_(NameLength) WCHAR Name[1];
// ...
// WCHAR Class[1];
} KEY_NODE_INFORMATION, *PKEY_NODE_INFORMATION;
typedef struct _KEY_FULL_INFORMATION
{
LARGE_INTEGER LastWriteTime;
ULONG TitleIndex;
ULONG ClassOffset;
ULONG ClassLength;
ULONG SubKeys;
ULONG MaxNameLength;
ULONG MaxClassLength;
ULONG Values;
ULONG MaxValueNameLength;
ULONG MaxValueDataLength;
WCHAR Class[1];
} KEY_FULL_INFORMATION, *PKEY_FULL_INFORMATION;
typedef struct _KEY_NAME_INFORMATION
{
ULONG NameLength;
_Field_size_bytes_(NameLength) WCHAR Name[1];
} KEY_NAME_INFORMATION, *PKEY_NAME_INFORMATION;
typedef struct _KEY_CACHED_INFORMATION
{
LARGE_INTEGER LastWriteTime;
ULONG TitleIndex;
ULONG SubKeys;
ULONG MaxNameLength;
ULONG Values;
ULONG MaxValueNameLength;
ULONG MaxValueDataLength;
ULONG NameLength;
_Field_size_bytes_(NameLength) WCHAR Name[1];
} KEY_CACHED_INFORMATION, *PKEY_CACHED_INFORMATION;
// rev
#define REG_FLAG_VOLATILE 0x0001
#define REG_FLAG_LINK 0x0002
// msdn
#define REG_KEY_DONT_VIRTUALIZE 0x0002
#define REG_KEY_DONT_SILENT_FAIL 0x0004
#define REG_KEY_RECURSE_FLAG 0x0008
// private
typedef struct _KEY_FLAGS_INFORMATION
{
ULONG Wow64Flags;
ULONG KeyFlags; // REG_FLAG_*
ULONG ControlFlags; // REG_KEY_*
} KEY_FLAGS_INFORMATION, *PKEY_FLAGS_INFORMATION;
/**
* The KEY_VIRTUALIZATION_INFORMATION structure contains information about the virtualization state of a key.
*
* The flags include:
* - VirtualizationCandidate: The key is part of the virtualization namespace scope (only HKLM\Software for now).
* - VirtualizationEnabled: Virtualization is enabled on this key. Can be 1 only if VirtualizationCandidate is 1.
* - VirtualTarget: The key is a virtual key. Can be 1 only if VirtualizationCandidate and VirtualizationEnabled are 0. Valid only on the virtual store key handles.
* - VirtualStore: The key is a part of the virtual store path. Valid only on the virtual store key handles.
* - VirtualSource: The key has ever been virtualized, can be 1 only if VirtualizationCandidate is 1.
* - Reserved: Reserved bits.
*/
typedef struct _KEY_VIRTUALIZATION_INFORMATION
{
ULONG VirtualizationCandidate : 1;
ULONG VirtualizationEnabled : 1;
ULONG VirtualTarget : 1;
ULONG VirtualStore : 1;
ULONG VirtualSource : 1;
ULONG Reserved : 27;
} KEY_VIRTUALIZATION_INFORMATION, *PKEY_VIRTUALIZATION_INFORMATION;
// private
/**
* The KEY_TRUST_INFORMATION structure contains information about the trust status of a key.
*
* The flags include:
* - TrustedKey: Indicates whether the key is trusted. When set, this flag signifies that the key is considered
* to be secure and reliable.
* - Reserved: Reserved bits.
*/
typedef struct _KEY_TRUST_INFORMATION
{
ULONG TrustedKey : 1;
ULONG Reserved : 31;
} KEY_TRUST_INFORMATION, *PKEY_TRUST_INFORMATION;
// private
/**
* The KEY_LAYER_INFORMATION structure contains information about a key layer.
*
* The flags include:
* - IsTombstone: Indicates whether the key layer is a tombstone. A tombstone is a marker that indicates
* that the key has been deleted but not yet purged from the registry. It is used to maintain the
* integrity of the registry and ensure that deleted keys are not immediately reused.
* - IsSupersedeLocal: Indicates whether the key layer supersedes the local key. When set, this flag
* indicates that the key layer should replace the local key's information, effectively overriding
* any local changes or settings.
* - IsSupersedeTree: Indicates whether the key layer supersedes the entire key tree. When set, this flag
* indicates that the key layer should replace the entire subtree of keys, overriding any changes or
* settings in the subtree.
* - ClassIsInherited: Indicates whether the key layer's class is inherited. When set, this flag indicates
* that the class information of the key layer is inherited from its parent key, rather than being
* explicitly defined.
* - Reserved: Reserved bits.
*/
typedef struct _KEY_LAYER_INFORMATION
{
ULONG IsTombstone : 1;
ULONG IsSupersedeLocal : 1;
ULONG IsSupersedeTree : 1;
ULONG ClassIsInherited : 1;
ULONG Reserved : 28;
} KEY_LAYER_INFORMATION, *PKEY_LAYER_INFORMATION;
typedef enum _KEY_SET_INFORMATION_CLASS
{
KeyWriteTimeInformation, // KEY_WRITE_TIME_INFORMATION
KeyWow64FlagsInformation, // KEY_WOW64_FLAGS_INFORMATION
KeyControlFlagsInformation, // KEY_CONTROL_FLAGS_INFORMATION
KeySetVirtualizationInformation, // KEY_SET_VIRTUALIZATION_INFORMATION
KeySetDebugInformation,
KeySetHandleTagsInformation, // KEY_HANDLE_TAGS_INFORMATION
KeySetLayerInformation, // KEY_SET_LAYER_INFORMATION
MaxKeySetInfoClass
} KEY_SET_INFORMATION_CLASS;
/**
* Structure representing the last write time of a registry key.
*
* The values include:
* - LastWriteTime: Contains the timestamp of the last write operation performed on a registry key.
*/
typedef struct _KEY_WRITE_TIME_INFORMATION
{
LARGE_INTEGER LastWriteTime;
} KEY_WRITE_TIME_INFORMATION, *PKEY_WRITE_TIME_INFORMATION;
/**
* The KEY_WOW64_FLAGS_INFORMATION structure contains information about the WOW64 flags for a key.
*
* The fields include:
* - UserFlags: A set of user-defined flags associated with the key. These flags are used to store
* additional information about the key in the context of WOW64 (Windows 32-bit on Windows 64-bit).
*/
typedef struct _KEY_WOW64_FLAGS_INFORMATION
{
ULONG UserFlags;
} KEY_WOW64_FLAGS_INFORMATION, *PKEY_WOW64_FLAGS_INFORMATION;
/**
* The KEY_HANDLE_TAGS_INFORMATION structure contains information about the handle tags for a key.
*
* The fields include:
* - HandleTags: A set of tags associated with the key handle. These tags are used to store additional
* metadata or state information about the key handle.
*/
typedef struct _KEY_HANDLE_TAGS_INFORMATION
{
ULONG HandleTags;
} KEY_HANDLE_TAGS_INFORMATION, *PKEY_HANDLE_TAGS_INFORMATION;
/**
* The KEY_SET_LAYER_INFORMATION structure contains information about a key layer.
*
* The flags include:
* - IsTombstone: Indicates whether the key layer is a tombstone. A tombstone is a marker that indicates
* that the key has been deleted but not yet purged from the registry. It is used to maintain the
* integrity of the registry and ensure that deleted keys are not immediately reused.
* - IsSupersedeLocal: Indicates whether the key layer supersedes the local key. When set, this flag
* indicates that the key layer should replace the local key's information, effectively overriding
* any local changes or settings.
* - IsSupersedeTree: Indicates whether the key layer supersedes the entire key tree. When set, this flag
* indicates that the key layer should replace the entire subtree of keys, overriding any changes or
* settings in the subtree.
* - ClassIsInherited: Indicates whether the key layer's class is inherited. When set, this flag indicates
* that the class information of the key layer is inherited from its parent key, rather than being
* explicitly defined.
* - Reserved: Reserved bits.
*/
typedef struct _KEY_SET_LAYER_INFORMATION
{
ULONG IsTombstone : 1;
ULONG IsSupersedeLocal : 1;
ULONG IsSupersedeTree : 1;
ULONG ClassIsInherited : 1;
ULONG Reserved : 28;
} KEY_SET_LAYER_INFORMATION, *PKEY_SET_LAYER_INFORMATION;
/**
* The KEY_CONTROL_FLAGS_INFORMATION structure contains control flags for a key.
*
* The fields include:
* - ControlFlags: A set of control flags associated with the key. These flags are used to store
* additional control information about the key, which can affect its behavior or state.
*/
typedef struct _KEY_CONTROL_FLAGS_INFORMATION
{
ULONG ControlFlags;
} KEY_CONTROL_FLAGS_INFORMATION, *PKEY_CONTROL_FLAGS_INFORMATION;
typedef struct _KEY_SET_VIRTUALIZATION_INFORMATION
{
ULONG VirtualTarget : 1;
ULONG VirtualStore : 1;
ULONG VirtualSource : 1; // true if key has been virtualized at least once
ULONG Reserved : 29;
} KEY_SET_VIRTUALIZATION_INFORMATION, *PKEY_SET_VIRTUALIZATION_INFORMATION;
typedef enum _KEY_VALUE_INFORMATION_CLASS
{
KeyValueBasicInformation, // KEY_VALUE_BASIC_INFORMATION
KeyValueFullInformation, // KEY_VALUE_FULL_INFORMATION
KeyValuePartialInformation, // KEY_VALUE_PARTIAL_INFORMATION
KeyValueFullInformationAlign64,
KeyValuePartialInformationAlign64, // KEY_VALUE_PARTIAL_INFORMATION_ALIGN64
KeyValueLayerInformation, // KEY_VALUE_LAYER_INFORMATION
MaxKeyValueInfoClass
} KEY_VALUE_INFORMATION_CLASS;
typedef struct _KEY_VALUE_BASIC_INFORMATION
{
ULONG TitleIndex;
ULONG Type;
ULONG NameLength;
_Field_size_bytes_(NameLength) WCHAR Name[1];
} KEY_VALUE_BASIC_INFORMATION, *PKEY_VALUE_BASIC_INFORMATION;
typedef struct _KEY_VALUE_FULL_INFORMATION
{
ULONG TitleIndex;
ULONG Type;
ULONG DataOffset;
ULONG DataLength;
ULONG NameLength;
_Field_size_bytes_(NameLength) WCHAR Name[1];
// ...
// UCHAR Data[1];
} KEY_VALUE_FULL_INFORMATION, *PKEY_VALUE_FULL_INFORMATION;
typedef struct _KEY_VALUE_PARTIAL_INFORMATION
{
ULONG TitleIndex;
ULONG Type;
ULONG DataLength;
_Field_size_bytes_(DataLength) UCHAR Data[1];
} KEY_VALUE_PARTIAL_INFORMATION, *PKEY_VALUE_PARTIAL_INFORMATION;
typedef struct _KEY_VALUE_PARTIAL_INFORMATION_ALIGN64
{
ULONG Type;
ULONG DataLength;
_Field_size_bytes_(DataLength) UCHAR Data[1];
} KEY_VALUE_PARTIAL_INFORMATION_ALIGN64, *PKEY_VALUE_PARTIAL_INFORMATION_ALIGN64;
// private
typedef struct _KEY_VALUE_LAYER_INFORMATION
{
ULONG IsTombstone : 1;
ULONG Reserved : 31;
} KEY_VALUE_LAYER_INFORMATION, *PKEY_VALUE_LAYER_INFORMATION;
// private
typedef enum _CM_EXTENDED_PARAMETER_TYPE
{
CmExtendedParameterInvalidType,
CmExtendedParameterTrustClassKey,
CmExtendedParameterEvent,
CmExtendedParameterFileAccessToken,
CmExtendedParameterMax,
} CM_EXTENDED_PARAMETER_TYPE;
#define CM_EXTENDED_PARAMETER_TYPE_BITS 8
// private
typedef struct DECLSPEC_ALIGN(8) _CM_EXTENDED_PARAMETER
{
struct
{
ULONG64 Type : CM_EXTENDED_PARAMETER_TYPE_BITS;
ULONG64 Reserved : 64 - CM_EXTENDED_PARAMETER_TYPE_BITS;
};
union
{
ULONG64 ULong64;
PVOID Pointer;
SIZE_T Size;
HANDLE Handle;
ULONG ULong;
ACCESS_MASK AccessMask;
};
} CM_EXTENDED_PARAMETER, *PCM_EXTENDED_PARAMETER;
typedef struct _KEY_VALUE_ENTRY
{
PUNICODE_STRING ValueName;
ULONG DataLength;
ULONG DataOffset;
ULONG Type;
} KEY_VALUE_ENTRY, *PKEY_VALUE_ENTRY;
typedef enum _REG_ACTION
{
KeyAdded,
KeyRemoved,
KeyModified
} REG_ACTION;
typedef struct _REG_NOTIFY_INFORMATION
{
ULONG NextEntryOffset;
REG_ACTION Action;
ULONG KeyLength;
_Field_size_bytes_(KeyLength) WCHAR Key[1];
} REG_NOTIFY_INFORMATION, *PREG_NOTIFY_INFORMATION;
typedef struct _KEY_PID_ARRAY
{
HANDLE ProcessId;
UNICODE_STRING KeyName;
} KEY_PID_ARRAY, *PKEY_PID_ARRAY;
typedef struct _KEY_OPEN_SUBKEYS_INFORMATION
{
ULONG Count;
KEY_PID_ARRAY KeyArray[1];
} KEY_OPEN_SUBKEYS_INFORMATION, *PKEY_OPEN_SUBKEYS_INFORMATION;
//
// Virtualization // since REDSTONE
//
// rev
#define VR_DEVICE_NAME L"\\Device\\VRegDriver"
// rev
#define IOCTL_VR_INITIALIZE_JOB_FOR_VREG CTL_CODE(FILE_DEVICE_UNKNOWN, 1, METHOD_BUFFERED, FILE_ANY_ACCESS) // in: VR_INITIALIZE_JOB_FOR_VREG
#define IOCTL_VR_LOAD_DIFFERENCING_HIVE CTL_CODE(FILE_DEVICE_UNKNOWN, 2, METHOD_BUFFERED, FILE_ANY_ACCESS) // in: VR_LOAD_DIFFERENCING_HIVE
#define IOCTL_VR_CREATE_NAMESPACE_NODE CTL_CODE(FILE_DEVICE_UNKNOWN, 3, METHOD_BUFFERED, FILE_ANY_ACCESS) // in: VR_CREATE_NAMESPACE_NODE
#define IOCTL_VR_MODIFY_FLAGS CTL_CODE(FILE_DEVICE_UNKNOWN, 4, METHOD_BUFFERED, FILE_ANY_ACCESS) // in: VR_MODIFY_FLAGS
#define IOCTL_VR_CREATE_MULTIPLE_NAMESPACE_NODES CTL_CODE(FILE_DEVICE_UNKNOWN, 5, METHOD_BUFFERED, FILE_ANY_ACCESS) // in: VR_CREATE_MULTIPLE_NAMESPACE_NODES
#define IOCTL_VR_UNLOAD_DYNAMICALLY_LOADED_HIVES CTL_CODE(FILE_DEVICE_UNKNOWN, 6, METHOD_BUFFERED, FILE_ANY_ACCESS) // in: VR_UNLOAD_DYNAMICALLY_LOADED_HIVES
#define IOCTL_VR_GET_VIRTUAL_ROOT_KEY CTL_CODE(FILE_DEVICE_UNKNOWN, 7, METHOD_BUFFERED, FILE_ANY_ACCESS) // in: VR_GET_VIRTUAL_ROOT; out: VR_GET_VIRTUAL_ROOT_RESULT
#define IOCTL_VR_LOAD_DIFFERENCING_HIVE_FOR_HOST CTL_CODE(FILE_DEVICE_UNKNOWN, 8, METHOD_BUFFERED, FILE_ANY_ACCESS) // in: VR_LOAD_DIFFERENCING_HIVE_FOR_HOST
#define IOCTL_VR_UNLOAD_DIFFERENCING_HIVE_FOR_HOST CTL_CODE(FILE_DEVICE_UNKNOWN, 9, METHOD_BUFFERED, FILE_ANY_ACCESS) // in: VR_UNLOAD_DIFFERENCING_HIVE_FOR_HOST
// private
typedef struct _VR_INITIALIZE_JOB_FOR_VREG
{
HANDLE Job;
} VR_INITIALIZE_JOB_FOR_VREG, *PVR_INITIALIZE_JOB_FOR_VREG;
// rev
#define VR_FLAG_INHERIT_TRUST_CLASS 0x00000001
#define VR_FLAG_WRITE_THROUGH_HIVE 0x00000002 // since REDSTONE2
#define VR_FLAG_LOCAL_MACHINE_TRUST_CLASS 0x00000004 // since 21H1
// rev + private
typedef struct _VR_LOAD_DIFFERENCING_HIVE
{
HANDLE Job;
ULONG NextLayerIsHost;
ULONG Flags; // VR_FLAG_*
ULONG LoadFlags; // NtLoadKeyEx flags
USHORT KeyPathLength;
USHORT HivePathLength;
USHORT NextLayerKeyPathLength;
HANDLE FileAccessToken; // since 20H1
WCHAR Strings[ANYSIZE_ARRAY];
// ...
// WCHAR KeyPath[1];
// WCHAR HivePath[1];
// WCHAR NextLayerKeyPath[1];
} VR_LOAD_DIFFERENCING_HIVE, *PVR_LOAD_DIFFERENCING_HIVE;
// rev + private
typedef struct _VR_CREATE_NAMESPACE_NODE
{
HANDLE Job;
USHORT ContainerPathLength;
USHORT HostPathLength;
ULONG Flags;
ACCESS_MASK AccessMask; // since 20H1
WCHAR Strings[ANYSIZE_ARRAY];
// ...
// WCHAR ContainerPath[1];
// WCHAR HostPath[1];
} VR_CREATE_NAMESPACE_NODE, *PVR_CREATE_NAMESPACE_NODE;
// private
typedef struct _VR_MODIFY_FLAGS
{
HANDLE Job;
ULONG AddFlags;
ULONG RemoveFlags;
} VR_MODIFY_FLAGS, *PVR_MODIFY_FLAGS;
// private
typedef struct _NAMESPACE_NODE_DATA
{
ACCESS_MASK AccessMask;
USHORT ContainerPathLength;
USHORT HostPathLength;
ULONG Flags;
WCHAR Strings[ANYSIZE_ARRAY];
// ...
// WCHAR ContainerPath[1];
// WCHAR HostPath[1];
} NAMESPACE_NODE_DATA, *PNAMESPACE_NODE_DATA;
// private
typedef struct _VR_CREATE_MULTIPLE_NAMESPACE_NODES
{
HANDLE Job;
ULONG NumNewKeys;
NAMESPACE_NODE_DATA Keys[1];
} VR_CREATE_MULTIPLE_NAMESPACE_NODES, *PVR_CREATE_MULTIPLE_NAMESPACE_NODES;
// private
typedef struct _VR_UNLOAD_DYNAMICALLY_LOADED_HIVES
{
HANDLE Job;
} VR_UNLOAD_DYNAMICALLY_LOADED_HIVES, *PVR_UNLOAD_DYNAMICALLY_LOADED_HIVES;
// rev
#define VR_KEY_COMROOT 0 // \Registry\ComRoot\Classes
#define VR_KEY_MACHINE_SOFTWARE 1 // \Registry\Machine\Software // since REDSTONE2
#define VR_KEY_CONTROL_SET 2 // \Registry\Machine\System\ControlSet001 // since REDSTONE2
// rev
typedef struct _VR_GET_VIRTUAL_ROOT
{
HANDLE Job;
ULONG Index; // VR_KEY_* // since REDSTONE2
} VR_GET_VIRTUAL_ROOT, *PVR_GET_VIRTUAL_ROOT;
// rev
typedef struct _VR_GET_VIRTUAL_ROOT_RESULT
{
HANDLE Key;
} VR_GET_VIRTUAL_ROOT_RESULT, *PVR_GET_VIRTUAL_ROOT_RESULT;
// rev
typedef struct _VR_LOAD_DIFFERENCING_HIVE_FOR_HOST
{
ULONG LoadFlags; // NtLoadKeyEx flags
ULONG Flags; // VR_FLAG_* // since REDSTONE2
USHORT KeyPathLength;
USHORT HivePathLength;
USHORT NextLayerKeyPathLength;
HANDLE FileAccessToken; // since 20H1
WCHAR Strings[ANYSIZE_ARRAY];
// ...
// WCHAR KeyPath[1];
// WCHAR HivePath[1];
// WCHAR NextLayerKeyPath[1];
} VR_LOAD_DIFFERENCING_HIVE_FOR_HOST, *PVR_LOAD_DIFFERENCING_HIVE_FOR_HOST;
// rev
typedef struct _VR_UNLOAD_DIFFERENCING_HIVE_FOR_HOST
{
ULONG Reserved;
USHORT TargetKeyPathLength;
WCHAR TargetKeyPath[ANYSIZE_ARRAY];
} VR_UNLOAD_DIFFERENCING_HIVE_FOR_HOST, *PVR_UNLOAD_DIFFERENCING_HIVE_FOR_HOST;
//
// Key Open/Create Options
//
#define REG_OPTION_RESERVED (0x00000000L) // Parameter is reserved.
#define REG_OPTION_NON_VOLATILE (0x00000000L) // Key is preserved when system is rebooted.
#define REG_OPTION_VOLATILE (0x00000001L) // Key is not preserved when system is rebooted
#define REG_OPTION_CREATE_LINK (0x00000002L) // Created key is a symbolic link
#define REG_OPTION_BACKUP_RESTORE (0x00000004L) // open for backup or restore special access rules privilege required
#define REG_OPTION_OPEN_LINK (0x00000008L) // Open symbolic link
#define REG_OPTION_DONT_VIRTUALIZE (0x00000010L) // Disable Open/Read/Write virtualization for this open and the resulting handle.
#ifndef REG_LEGAL_OPTION
#define REG_LEGAL_OPTION \
(REG_OPTION_RESERVED | REG_OPTION_NON_VOLATILE |\
REG_OPTION_VOLATILE | REG_OPTION_CREATE_LINK |\
REG_OPTION_BACKUP_RESTORE | REG_OPTION_OPEN_LINK |\
REG_OPTION_DONT_VIRTUALIZE)
#endif
#ifndef REG_OPEN_LEGAL_OPTION
#define REG_OPEN_LEGAL_OPTION \
(REG_OPTION_RESERVED | REG_OPTION_BACKUP_RESTORE | \
REG_OPTION_OPEN_LINK | REG_OPTION_DONT_VIRTUALIZE)
#endif
//
// Key creation/open disposition
//
#define REG_CREATED_NEW_KEY (0x00000001L) // New Registry Key created
#define REG_OPENED_EXISTING_KEY (0x00000002L) // Existing Key opened
//
// hive format to be used by Reg(Nt)SaveKeyEx
//
#define REG_STANDARD_FORMAT 1
#define REG_LATEST_FORMAT 2
#define REG_NO_COMPRESSION 4
//
// Key restore & hive load flags
//
#define REG_WHOLE_HIVE_VOLATILE (0x00000001L) // Restore whole hive volatile
#define REG_REFRESH_HIVE (0x00000002L) // Unwind changes to last flush
#define REG_NO_LAZY_FLUSH (0x00000004L) // Never lazy flush this hive
#define REG_FORCE_RESTORE (0x00000008L) // Force the restore process even when we have open handles on subkeys
#define REG_APP_HIVE (0x00000010L) // Loads the hive visible to the calling process
#define REG_PROCESS_PRIVATE (0x00000020L) // Hive cannot be mounted by any other process while in use
#define REG_START_JOURNAL (0x00000040L) // Starts Hive Journal
#define REG_HIVE_EXACT_FILE_GROWTH (0x00000080L) // Grow hive file in exact 4k increments
#define REG_HIVE_NO_RM (0x00000100L) // No RM is started for this hive (no transactions)
#define REG_HIVE_SINGLE_LOG (0x00000200L) // Legacy single logging is used for this hive
#define REG_BOOT_HIVE (0x00000400L) // This hive might be used by the OS loader
#define REG_LOAD_HIVE_OPEN_HANDLE (0x00000800L) // Load the hive and return a handle to its root kcb
#define REG_FLUSH_HIVE_FILE_GROWTH (0x00001000L) // Flush changes to primary hive file size as part of all flushes
#define REG_OPEN_READ_ONLY (0x00002000L) // Open a hive's files in read-only mode
#define REG_IMMUTABLE (0x00004000L) // Load the hive, but don't allow any modification of it
#define REG_NO_IMPERSONATION_FALLBACK (0x00008000L) // Do not fall back to impersonating the caller if hive file access fails
#define REG_APP_HIVE_OPEN_READ_ONLY (REG_OPEN_READ_ONLY) // Open an app hive's files in read-only mode (if the hive was not previously loaded)
//
// Unload Flags
//
#define REG_FORCE_UNLOAD 1
#define REG_UNLOAD_LEGAL_FLAGS (REG_FORCE_UNLOAD)
/**
* Creates a new registry key routine or opens an existing one.
*
* @param[out] KeyHandle A pointer to a handle that receives the key handle.
* @param[in] DesiredAccess The access mask that specifies the desired access rights.
* @param[in] ObjectAttributes A pointer to an OBJECT_ATTRIBUTES structure that specifies the object attributes.
* @param[in] TitleIndex Reserved.
* @param[in, optional] Class A pointer to a UNICODE_STRING structure that specifies the class of the key.
* @param[in] CreateOptions The options to use when creating the key.
* @param[out, optional] Disposition A pointer to a variable that receives the disposition value.
* @return NTSTATUS Successful or errant status.
*/
NTSYSCALLAPI
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
);
#if (PHNT_VERSION >= PHNT_VISTA)
/**
* Creates a new registry key or opens an existing one, and it associates the key with a transaction.
*
* @param[out] KeyHandle A pointer to a handle that receives the key handle.
* @param[in] DesiredAccess The access mask that specifies the desired access rights.
* @param[in] ObjectAttributes A pointer to an OBJECT_ATTRIBUTES structure that specifies the object attributes.
* @param[in] TitleIndex Reserved.
* @param[in, optional] Class A pointer to a UNICODE_STRING structure that specifies the class of the key.
* @param[in] CreateOptions The options to use when creating the key.
* @param[in] TransactionHandle A handle to the transaction.
* @param[out, optional] Disposition A pointer to a variable that receives the disposition value.
* @return NTSTATUS Successful or errant status.
*/
NTSYSCALLAPI
NTSTATUS
NTAPI
NtCreateKeyTransacted(
_Out_ PHANDLE KeyHandle,
_In_ ACCESS_MASK DesiredAccess,
_In_ POBJECT_ATTRIBUTES ObjectAttributes,
_Reserved_ ULONG TitleIndex,
_In_opt_ PUNICODE_STRING Class,
_In_ ULONG CreateOptions,
_In_ HANDLE TransactionHandle,
_Out_opt_ PULONG Disposition
);
#endif
/**
* Opens an existing registry key.
*
* @param[out] KeyHandle A pointer to a handle that receives the key handle.
* @param[in] DesiredAccess The access mask that specifies the desired access rights.
* @param[in] ObjectAttributes A pointer to an OBJECT_ATTRIBUTES structure that specifies the object attributes.
* @return NTSTATUS Successful or errant status.
* @remarks NtOpenKey ignores the security information in the ObjectAttributes structure.
*/
NTSYSCALLAPI
NTSTATUS
NTAPI
NtOpenKey(
_Out_ PHANDLE KeyHandle,
_In_ ACCESS_MASK DesiredAccess,
_In_ POBJECT_ATTRIBUTES ObjectAttributes
);
#if (PHNT_VERSION >= PHNT_VISTA)
/**
* Opens an existing registry key and associates the key with a transaction.
*
* @param[out] KeyHandle A pointer to a handle that receives the key handle.
* @param[in] DesiredAccess The access mask that specifies the desired access rights.
* @param[in] ObjectAttributes A pointer to an OBJECT_ATTRIBUTES structure that specifies the object attributes.
* @param[in] TransactionHandle A handle to the transaction.
* @return NTSTATUS Successful or errant status.
*/
NTSYSCALLAPI
NTSTATUS
NTAPI
NtOpenKeyTransacted(
_Out_ PHANDLE KeyHandle,
_In_ ACCESS_MASK DesiredAccess,
_In_ POBJECT_ATTRIBUTES ObjectAttributes,
_In_ HANDLE TransactionHandle
);
#endif
#if (PHNT_VERSION >= PHNT_WIN7)
/**
* Opens an existing registry key with extended options.
*
* @param[out] KeyHandle A pointer to a handle that receives the key handle.
* @param[in] DesiredAccess The access mask that specifies the desired access rights.
* @param[in] ObjectAttributes A pointer to an OBJECT_ATTRIBUTES structure that specifies the object attributes.
* @param[in] OpenOptions The options to use when opening the key.
* @return NTSTATUS Successful or errant status.
*/
NTSYSCALLAPI
NTSTATUS
NTAPI
NtOpenKeyEx(
_Out_ PHANDLE KeyHandle,
_In_ ACCESS_MASK DesiredAccess,
_In_ POBJECT_ATTRIBUTES ObjectAttributes,
_In_ ULONG OpenOptions
);
/**
* Opens an existing registry key in a transaction with extended options.
*
* @param[out] KeyHandle A pointer to a handle that receives the key handle.
* @param[in] DesiredAccess The access mask that specifies the desired access rights.
* @param[in] ObjectAttributes A pointer to an OBJECT_ATTRIBUTES structure that specifies the object attributes.
* @param[in] OpenOptions The options to use when opening the key.
* @param[in] TransactionHandle A handle to the transaction.
* @return NTSTATUS Successful or errant status.
*/
NTSYSCALLAPI
NTSTATUS
NTAPI
NtOpenKeyTransactedEx(
_Out_ PHANDLE KeyHandle,
_In_ ACCESS_MASK DesiredAccess,
_In_ POBJECT_ATTRIBUTES ObjectAttributes,
_In_ ULONG OpenOptions,
_In_ HANDLE TransactionHandle
);
#endif
/**
* Deletes a registry key.
*
* @param[in] KeyHandle A handle to the key to be deleted.
* @return NTSTATUS Successful or errant status.
*/
NTSYSCALLAPI
NTSTATUS
NTAPI
NtDeleteKey(
_In_ HANDLE KeyHandle
);
/**
* Renames a registry key.
*
* @param[in] KeyHandle A handle to the key to be renamed.
* @param[in] NewName A pointer to a UNICODE_STRING structure that specifies the new name of the key.
* @return NTSTATUS Successful or errant status.
*/
NTSYSCALLAPI
NTSTATUS
NTAPI
NtRenameKey(
_In_ HANDLE KeyHandle,
_In_ PUNICODE_STRING NewName
);
/**
* Deletes a value from a registry key.
*
* @param[in] KeyHandle A handle to the key that contains the value to be deleted.
* @param[in] ValueName A pointer to a UNICODE_STRING structure that specifies the name of the value to be deleted.
* @return NTSTATUS Successful or errant status.
*/
NTSYSCALLAPI
NTSTATUS
NTAPI
NtDeleteValueKey(
_In_ HANDLE KeyHandle,
_In_ PUNICODE_STRING ValueName
);
/**
* Queries information about a registry key.
*
* @param[in] KeyHandle A handle to the key to be queried.
* @param[in] KeyInformationClass The type of information to be queried.
* @param[out] KeyInformation A pointer to a buffer that receives the key information.
* @param[in] Length The size of the buffer.
* @param[out] ResultLength A pointer to a variable that receives the size of the data returned.
* @return NTSTATUS Successful or errant status.
*/
NTSYSCALLAPI
NTSTATUS
NTAPI
NtQueryKey(
_In_ HANDLE KeyHandle,
_In_ KEY_INFORMATION_CLASS KeyInformationClass,
_Out_writes_bytes_to_opt_(Length, *ResultLength) PVOID KeyInformation,
_In_ ULONG Length,
_Out_ PULONG ResultLength
);
/**
* Sets information for a registry key.
*
* @param[in] KeyHandle A handle to the key to be modified.
* @param[in] KeySetInformationClass The type of information to be set.
* @param[in] KeySetInformation A pointer to a buffer that contains the key information.
* @param[in] KeySetInformationLength The size of the buffer.
* @return NTSTATUS Successful or errant status.
*/
NTSYSCALLAPI
NTSTATUS
NTAPI
NtSetInformationKey(
_In_ HANDLE KeyHandle,
_In_ KEY_SET_INFORMATION_CLASS KeySetInformationClass,
_In_reads_bytes_(KeySetInformationLength) PVOID KeySetInformation,
_In_ ULONG KeySetInformationLength
);
/**
* Queries the value of a registry key.
*
* @param[in] KeyHandle A handle to the key to be queried.
* @param[in] ValueName A pointer to a UNICODE_STRING structure that specifies the name of the value to be queried.
* @param[in] KeyValueInformationClass The type of information to be queried.
* @param[out] KeyValueInformation A pointer to a buffer that receives the value information.
* @param[in] Length The size of the buffer.
* @param[out] ResultLength A pointer to a variable that receives the size of the data returned.
* @return NTSTATUS Successful or errant status.
*/
NTSYSCALLAPI
NTSTATUS
NTAPI
NtQueryValueKey(
_In_ HANDLE KeyHandle,
_In_ PUNICODE_STRING ValueName,
_In_ KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
_Out_writes_bytes_to_opt_(Length, *ResultLength) PVOID KeyValueInformation,
_In_ ULONG Length,
_Out_ PULONG ResultLength
);
/**
* Sets the value of a registry key.
*
* @param[in] KeyHandle A handle to the key to be modified.
* @param[in] ValueName A pointer to a UNICODE_STRING structure that specifies the name of the value to be set.
* @param[in, optional] TitleIndex Reserved.
* @param[in] Type The type of the value.
* @param[in] Data A pointer to a buffer that contains the value data.
* @param[in] DataSize The size of the buffer.
* @return NTSTATUS Successful or errant status.
*/
NTSYSCALLAPI
NTSTATUS
NTAPI
NtSetValueKey(
_In_ HANDLE KeyHandle,
_In_ PUNICODE_STRING ValueName,
_In_opt_ ULONG TitleIndex,
_In_ ULONG Type,
_In_reads_bytes_opt_(DataSize) PVOID Data,
_In_ ULONG DataSize
);
/**
* Queries multiple values of a registry key.
*
* @param[in] KeyHandle A handle to the key to be queried.
* @param[in, out] ValueEntries A pointer to an array of KEY_VALUE_ENTRY structures that specify the values to be queried.
* @param[in] EntryCount The number of entries in the array.
* @param[out] ValueBuffer A pointer to a buffer that receives the value data.
* @param[in, out] BufferLength A pointer to a variable that specifies the size of the buffer and receives the size of the data returned.
* @param[out, optional] RequiredBufferLength A pointer to a variable that receives the size of the buffer required to hold the data.
* @return NTSTATUS Successful or errant status.
*/
NTSYSCALLAPI
NTSTATUS
NTAPI
NtQueryMultipleValueKey(
_In_ HANDLE KeyHandle,
_Inout_updates_(EntryCount) PKEY_VALUE_ENTRY ValueEntries,
_In_ ULONG EntryCount,
_Out_writes_bytes_(*BufferLength) PVOID ValueBuffer,
_Inout_ PULONG BufferLength,
_Out_opt_ PULONG RequiredBufferLength
);
/**
* Enumerates the subkeys of a registry key.
*
* @param[in] KeyHandle A handle to the key to be enumerated.
* @param[in] Index The index of the subkey to be enumerated.
* @param[in] KeyInformationClass The type of information to be queried.
* @param[out] KeyInformation A pointer to a buffer that receives the key information.
* @param[in] Length The size of the buffer.
* @param[out] ResultLength A pointer to a variable that receives the size of the data returned.
* @return NTSTATUS Successful or errant status.
*/
NTSYSCALLAPI
NTSTATUS
NTAPI
NtEnumerateKey(
_In_ HANDLE KeyHandle,
_In_ ULONG Index,
_In_ KEY_INFORMATION_CLASS KeyInformationClass,
_Out_writes_bytes_to_opt_(Length, *ResultLength) PVOID KeyInformation,
_In_ ULONG Length,
_Out_ PULONG ResultLength
);
/**
* Enumerates the values of a registry key.
*
* @param[in] KeyHandle A handle to the key to be enumerated.
* @param[in] Index The index of the value to be enumerated.
* @param[in] KeyValueInformationClass The type of information to be queried.
* @param[out] KeyValueInformation A pointer to a buffer that receives the value information.
* @param[in] Length The size of the buffer.
* @param[out] ResultLength A pointer to a variable that receives the size of the data returned.
* @return NTSTATUS Successful or errant status.
*/
NTSYSCALLAPI
NTSTATUS
NTAPI
NtEnumerateValueKey(
_In_ HANDLE KeyHandle,
_In_ ULONG Index,
_In_ KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
_Out_writes_bytes_to_opt_(Length, *ResultLength) PVOID KeyValueInformation,
_In_ ULONG Length,
_Out_ PULONG ResultLength
);
/**
* Flushes the changes to a registry key.
*
* @param[in] KeyHandle A handle to the key to be flushed.
* @return NTSTATUS Successful or errant status.
*/
NTSYSCALLAPI
NTSTATUS
NTAPI
NtFlushKey(
_In_ HANDLE KeyHandle
);
/**
* Compacts the specified registry keys.
*
* @param[in] Count The number of keys to be compacted.
* @param[in] KeyArray An array of handles to the keys to be compacted.
* @return NTSTATUS Successful or errant status.
*/
NTSYSCALLAPI
NTSTATUS
NTAPI
NtCompactKeys(
_In_ ULONG Count,
_In_reads_(Count) HANDLE KeyArray[]
);
/**
* Compresses a registry key.
*
* @param[in] KeyHandle A handle to the key to be compressed.
* @return NTSTATUS Successful or errant status.
*/
NTSYSCALLAPI
NTSTATUS
NTAPI
NtCompressKey(
_In_ HANDLE KeyHandle
);
/**
* Loads a registry key from a file.
*
* @param[in] TargetKey A pointer to an OBJECT_ATTRIBUTES structure that specifies the target key.
* @param[in] SourceFile A pointer to an OBJECT_ATTRIBUTES structure that specifies the source file.
* @return NTSTATUS Successful or errant status.
*/
NTSYSCALLAPI
NTSTATUS
NTAPI
NtLoadKey(
_In_ POBJECT_ATTRIBUTES TargetKey,
_In_ POBJECT_ATTRIBUTES SourceFile
);
/**
* Loads a registry key from a file with additional options.
*
* @param[in] TargetKey A pointer to an OBJECT_ATTRIBUTES structure that specifies the target key.
* @param[in] SourceFile A pointer to an OBJECT_ATTRIBUTES structure that specifies the source file.
* @param[in] Flags The options to use when loading the key.
* @return NTSTATUS Successful or errant status.
*/
NTSYSCALLAPI
NTSTATUS
NTAPI
NtLoadKey2(
_In_ POBJECT_ATTRIBUTES TargetKey,
_In_ POBJECT_ATTRIBUTES SourceFile,
_In_ ULONG Flags
);
/**
* Loads a registry key from a file with extended options.
*
* @param[in] TargetKey A pointer to an OBJECT_ATTRIBUTES structure that specifies the target key.
* @param[in] SourceFile A pointer to an OBJECT_ATTRIBUTES structure that specifies the source file.
* @param[in] Flags The options to use when loading the key.
* @param[in, optional] TrustClassKey A handle to the trust class key.
* @param[in, optional] Event A handle to an event.