-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
regfltr.c
871 lines (650 loc) · 25 KB
/
regfltr.c
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
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
PURPOSE.
Module Name:
regfltr.c
Abstract:
Sample driver used to run the kernel mode registry callback samples.
Environment:
Kernel mode only
--*/
#include "regfltr.h"
//
// The root key used in the samples
//
HANDLE g_RootKey;
LPCWSTR
GetTransactionNotifyClassString (
_In_ ULONG TransactionNotifcation
);
LPCWSTR
GetNotifyClassString (
_In_ REG_NOTIFY_CLASS NotifyClass
);
VOID
DeleteTestKeys(
);
NTSTATUS
Callback (
_In_ PVOID CallbackContext,
_In_opt_ PVOID Argument1,
_In_opt_ PVOID Argument2
)
/*++
Routine Description:
This is the registry callback we'll register to intercept all registry
operations.
Arguments:
CallbackContext - The value that the driver passed to the Context parameter
of CmRegisterCallbackEx when it registers this callback routine.
Argument1 - A REG_NOTIFY_CLASS typed value that identifies the type of
registry operation that is being performed and whether the callback
is being called in the pre or post phase of processing.
Argument2 - A pointer to a structure that contains information specific
to the type of the registry operation. The structure type depends
on the REG_NOTIFY_CLASS value of Argument1. Refer to MSDN for the
mapping from REG_NOTIFY_CLASS to REG_XXX_KEY_INFORMATION.
Return Value:
Status returned from the helper callback routine or STATUS_SUCCESS if
the registry operation did not originate from this process.
--*/
{
NTSTATUS Status = STATUS_SUCCESS;
REG_NOTIFY_CLASS NotifyClass;
PCALLBACK_CONTEXT CallbackCtx;
CallbackCtx = (PCALLBACK_CONTEXT)CallbackContext;
NotifyClass = (REG_NOTIFY_CLASS)(ULONG_PTR)Argument1;
//
// Ignore registry activity from other processes. If this callback
// wasn't registered by the current process, simply return success.
//
if (CallbackCtx->ProcessId != PsGetCurrentProcessId()) {
return STATUS_SUCCESS;
}
InfoPrint("\tCallback: Altitude-%S, NotifyClass-%S.",
CallbackCtx->AltitudeBuffer,
GetNotifyClassString(NotifyClass));
//
// Invoke a helper method depending on the value of CallbackMode in
// CallbackCtx.
//
if (Argument2 == NULL) {
//
// This should never happen but the sal annotation on the callback
// function marks Argument 2 as opt and is looser than what
// it actually is.
//
ErrorPrint("\tCallback: Argument 2 unexpectedly 0. Filter will "
"abort and return success.");
return STATUS_SUCCESS;
}
switch (CallbackCtx->CallbackMode) {
case CALLBACK_MODE_PRE_NOTIFICATION_BLOCK:
Status = CallbackPreNotificationBlock(CallbackCtx, NotifyClass, Argument2);
break;
case CALLBACK_MODE_PRE_NOTIFICATION_BYPASS:
Status = CallbackPreNotificationBypass(CallbackCtx, NotifyClass, Argument2);
break;
case CALLBACK_MODE_POST_NOTIFICATION_OVERRIDE_SUCCESS:
Status = CallbackPostNotificationOverrideSuccess(CallbackCtx, NotifyClass, Argument2);
break;
case CALLBACK_MODE_POST_NOTIFICATION_OVERRIDE_ERROR:
Status = CallbackPostNotificationOverrideError(CallbackCtx, NotifyClass, Argument2);
break;
case CALLBACK_MODE_TRANSACTION_ENLIST:
Status = CallbackTransactionEnlist(CallbackCtx, NotifyClass, Argument2);
break;
case CALLBACK_MODE_TRANSACTION_REPLAY:
Status = CallbackTransactionReplay(CallbackCtx, NotifyClass, Argument2);
break;
case CALLBACK_MODE_SET_OBJECT_CONTEXT:
Status = CallbackSetObjectContext(CallbackCtx, NotifyClass, Argument2);
break;
case CALLBACK_MODE_SET_CALL_CONTEXT:
Status = CallbackSetCallContext(CallbackCtx, NotifyClass, Argument2);
break;
case CALLBACK_MODE_MULTIPLE_ALTITUDE_MONITOR:
Status = CallbackMonitor(CallbackCtx, NotifyClass, Argument2);
break;
case CALLBACK_MODE_MULTIPLE_ALTITUDE_BLOCK_DURING_PRE:
case CALLBACK_MODE_MULTIPLE_ALTITUDE_INTERNAL_INVOCATION:
Status = CallbackMultipleAltitude(CallbackCtx, NotifyClass, Argument2);
break;
case CALLBACK_MODE_CAPTURE:
Status = CallbackCapture(CallbackCtx, NotifyClass, Argument2);
break;
case CALLBACK_MODE_VERSION_BUGCHECK:
Status = CallbackBugcheck(CallbackCtx, NotifyClass, Argument2);
break;
case CALLBACK_MODE_VERSION_CREATE_OPEN_V1:
Status = CallbackCreateOpenV1(CallbackCtx, NotifyClass, Argument2);
break;
default:
ErrorPrint("Unknown Callback Mode: %d", CallbackCtx->CallbackMode);
Status = STATUS_INVALID_PARAMETER;
}
return Status;
}
NTSTATUS
RMCallback(
_In_ PKENLISTMENT EnlistmentObject,
_In_ PVOID RMContext,
_In_ PVOID TransactionContext,
_In_ ULONG TransactionNotification,
_Inout_ PLARGE_INTEGER TMVirtualClock,
_In_ ULONG ArgumentLength,
_In_ PVOID Argument
)
/*++
Routine Description:
This callback recieves transaction notifications.
Arguments:
EnlistmentObject - Enlistment that this notification is about
RMContext - The value specified for the RMKey parameter of the
TmEnableCallbacks routine
TransactionContext - Value specified for the EnlistmentKey parameter
of the ZwCreateEnlistment routine
TransactionNotification - Type of notification
TmVirtualClock - Pointer to virtual clock value of time when KTM prepared
the notification.
ArgumentLength - Length in bytes of the Argument buffer.
Argument - Buffer containing notification-spcefic arguments.
Return Value:
Always STATUS_SUCCESS
--*/
{
PRMCALLBACK_CONTEXT Context = (PRMCALLBACK_CONTEXT) TransactionContext;
NTSTATUS Status = STATUS_SUCCESS;
UNREFERENCED_PARAMETER(EnlistmentObject);
UNREFERENCED_PARAMETER(RMContext);
UNREFERENCED_PARAMETER(ArgumentLength);
UNREFERENCED_PARAMETER(Argument);
InfoPrint("\tRMCallback: NotifyClass-%S.",
GetTransactionNotifyClassString(TransactionNotification));
//
// Transaction notifications are bit masks. Record which one(s)
// this callback received.
//
Context->Notification |= TransactionNotification;
//
// Call the Tm*Complete methods to inform KTM that we have completed
// processing. (Note: It is possible to use the Zw version of
// these APIs as well).
//
// Make sure that all the notifications you request are handled. The
// type of notification this routine gets is specified when you enlist
// in a transaction.
//
switch(TransactionNotification) {
case TRANSACTION_NOTIFY_COMMIT:
Status = TmCommitComplete(EnlistmentObject,
TMVirtualClock);
break;
case TRANSACTION_NOTIFY_ROLLBACK:
Status = TmRollbackComplete(EnlistmentObject,
TMVirtualClock);
break;
default:
ErrorPrint("Unsupported Transaction Notification: %x",
TransactionNotification);
NT_ASSERT(FALSE);
}
//
// It is safe to close the enlistment handle here.
// Closing it before the transaction aborts or commits will abort
// the transaction.
//
if (Context->Enlistment != NULL) {
ZwClose(Context->Enlistment);
Context->Enlistment = NULL;
}
return Status;
}
NTSTATUS
DoCallbackSamples(
_In_ PDEVICE_OBJECT DeviceObject,
_In_ PIRP Irp
)
/*++
Routine Description:
This routine creates the root test key and then invokes the sample.
It records the results of each sample in an array that it returns to
the usermode program.
Arguments:
DeviceObject - The device object receiving the request.
Irp - The request packet.
Return Value:
NTSTATUS
--*/
{
NTSTATUS Status;
PIO_STACK_LOCATION IrpStack;
ULONG OutputBufferLength;
PDO_KERNELMODE_SAMPLES_OUTPUT Output;
UNICODE_STRING KeyPath;
OBJECT_ATTRIBUTES KeyAttributes;
UNREFERENCED_PARAMETER(DeviceObject);
//
// Get the output buffer from the irp and check it is as large as expected.
//
IrpStack = IoGetCurrentIrpStackLocation(Irp);
OutputBufferLength = IrpStack->Parameters.DeviceIoControl.OutputBufferLength;
if (OutputBufferLength < sizeof (DO_KERNELMODE_SAMPLES_OUTPUT)) {
Status = STATUS_INVALID_PARAMETER;
goto Exit;
}
Output = (PDO_KERNELMODE_SAMPLES_OUTPUT) Irp->AssociatedIrp.SystemBuffer;
//
// Clean up test keys in case the sample terminated uncleanly.
//
DeleteTestKeys();
//
// Create the root key and the modified root key
//
RtlInitUnicodeString(&KeyPath, ROOT_KEY_ABS_PATH);
InitializeObjectAttributes(&KeyAttributes,
&KeyPath,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
NULL,
NULL);
Status = ZwCreateKey(&g_RootKey,
KEY_ALL_ACCESS,
&KeyAttributes,
0,
NULL,
0,
NULL);
if (!NT_SUCCESS(Status)) {
ErrorPrint("ZwCreateKey failed. Status 0x%x", Status);
return Status;
}
//
// Call each demo and record the results in the Output->SampleResults
// array
//
Output->SampleResults[KERNELMODE_SAMPLE_PRE_NOTIFICATION_BLOCK] =
PreNotificationBlockSample();
Output->SampleResults[KERNELMODE_SAMPLE_PRE_NOTIFICATION_BYPASS] =
PreNotificationBypassSample();
Output->SampleResults[KERNELMODE_SAMPLE_POST_NOTIFICATION_OVERRIDE_SUCCESS] =
PostNotificationOverrideSuccessSample();
Output->SampleResults[KERNELMODE_SAMPLE_POST_NOTIFICATION_OVERRIDE_ERROR] =
PostNotificationOverrideErrorSample();
Output->SampleResults[KERNELMODE_SAMPLE_TRANSACTION_ENLIST] =
TransactionEnlistSample();
Output->SampleResults[KERNELMODE_SAMPLE_TRANSACTION_REPLAY] =
TransactionReplaySample();
Output->SampleResults[KERNELMODE_SAMPLE_SET_CALL_CONTEXT] =
SetObjectContextSample();
Output->SampleResults[KERNELMODE_SAMPLE_SET_OBJECT_CONTEXT] =
SetCallContextSample();
Output->SampleResults[KERNELMODE_SAMPLE_MULTIPLE_ALTITUDE_BLOCK_DURING_PRE] =
MultipleAltitudeBlockDuringPreSample();
Output->SampleResults[KERNELMODE_SAMPLE_MULTIPLE_ALTITUDE_INTERNAL_INVOCATION] =
MultipleAltitudeInternalInvocationSample();
Output->SampleResults[KERNELMODE_SAMPLE_VERSION_CREATE_OPEN_V1] =
CreateOpenV1Sample();
Irp->IoStatus.Information = sizeof(DO_KERNELMODE_SAMPLES_OUTPUT);
Exit:
if (g_RootKey) {
ZwDeleteKey(g_RootKey);
ZwClose(g_RootKey);
}
InfoPrint("");
InfoPrint("Kernel Mode Samples End");
InfoPrint("");
return Status;
}
NTSTATUS
RegisterCallback(
_In_ PDEVICE_OBJECT DeviceObject,
_In_ PIRP Irp
)
/*++
Routine Description:
Registers a callback with the specified callback mode and altitude
Arguments:
DeviceObject - The device object receiving the request.
Irp - The request packet.
Return Value:
Status from CmRegisterCallbackEx
--*/
{
NTSTATUS Status = STATUS_SUCCESS;
PIO_STACK_LOCATION IrpStack;
ULONG InputBufferLength;
ULONG OutputBufferLength;
PREGISTER_CALLBACK_INPUT RegisterCallbackInput;
PREGISTER_CALLBACK_OUTPUT RegisterCallbackOutput;
PCALLBACK_CONTEXT CallbackCtx = NULL;
//
// Get the input and output buffer from the irp and
// check they are the expected size
//
IrpStack = IoGetCurrentIrpStackLocation(Irp);
InputBufferLength = IrpStack->Parameters.DeviceIoControl.InputBufferLength;
OutputBufferLength = IrpStack->Parameters.DeviceIoControl.OutputBufferLength;
if ((InputBufferLength < sizeof(REGISTER_CALLBACK_INPUT)) ||
(OutputBufferLength < sizeof (REGISTER_CALLBACK_OUTPUT))) {
Status = STATUS_INVALID_PARAMETER;
goto Exit;
}
RegisterCallbackInput = (PREGISTER_CALLBACK_INPUT) Irp->AssociatedIrp.SystemBuffer;
//
// Create the callback context from the specified callback mode and altitude
//
CallbackCtx = CreateCallbackContext(RegisterCallbackInput->CallbackMode,
RegisterCallbackInput->Altitude);
if (CallbackCtx == NULL) {
Status = STATUS_INSUFFICIENT_RESOURCES;
goto Exit;
}
//
// Register the callback
//
Status = CmRegisterCallbackEx(Callback,
&CallbackCtx->Altitude,
DeviceObject->DriverObject,
(PVOID) CallbackCtx,
&CallbackCtx->Cookie,
NULL);
if (!NT_SUCCESS(Status)) {
ErrorPrint("CmRegisterCallback failed. Status 0x%x", Status);
goto Exit;
}
if (!InsertCallbackContext(CallbackCtx)) {
Status = STATUS_UNSUCCESSFUL;
goto Exit;
}
//
// Fill the output buffer with the Cookie received from registering the
// callback and the pointer to the callback context.
//
RegisterCallbackOutput = (PREGISTER_CALLBACK_OUTPUT)Irp->AssociatedIrp.SystemBuffer;
RegisterCallbackOutput->Cookie = CallbackCtx->Cookie;
Irp->IoStatus.Information = sizeof(REGISTER_CALLBACK_OUTPUT);
Exit:
if (!NT_SUCCESS(Status)) {
ErrorPrint("RegisterCallback failed. Status 0x%x", Status);
if (CallbackCtx != NULL) {
DeleteCallbackContext(CallbackCtx);
}
} else {
InfoPrint("RegisterCallback succeeded");
}
return Status;
}
NTSTATUS
UnRegisterCallback(
_In_ PDEVICE_OBJECT DeviceObject,
_In_ PIRP Irp
)
/*++
Routine Description:
Unregisters a callback with the specified cookie and clean up the
callback context.
Arguments:
DeviceObject - The device object receiving the request.
Irp - The request packet.
Return Value:
Status from CmUnRegisterCallback
--*/
{
NTSTATUS Status = STATUS_SUCCESS;
PIO_STACK_LOCATION IrpStack;
ULONG InputBufferLength;
PUNREGISTER_CALLBACK_INPUT UnRegisterCallbackInput;
PCALLBACK_CONTEXT CallbackCtx;
UNREFERENCED_PARAMETER(DeviceObject);
//
// Get the input buffer and check its size
//
IrpStack = IoGetCurrentIrpStackLocation(Irp);
InputBufferLength = IrpStack->Parameters.DeviceIoControl.InputBufferLength;
if (InputBufferLength < sizeof(UNREGISTER_CALLBACK_INPUT)) {
Status = STATUS_INVALID_PARAMETER;
goto Exit;
}
UnRegisterCallbackInput = (PUNREGISTER_CALLBACK_INPUT) Irp->AssociatedIrp.SystemBuffer;
//
// Unregister the callback with the cookie
//
Status = CmUnRegisterCallback(UnRegisterCallbackInput->Cookie);
if (!NT_SUCCESS(Status)) {
ErrorPrint("CmUnRegisterCallback failed. Status 0x%x", Status);
goto Exit;
}
//
// Free the callback context buffer
//
CallbackCtx = FindAndRemoveCallbackContext(UnRegisterCallbackInput->Cookie);
if (CallbackCtx != NULL) {
DeleteCallbackContext(CallbackCtx);
}
Exit:
if (!NT_SUCCESS(Status)) {
ErrorPrint("UnRegisterCallback failed. Status 0x%x", Status);
} else {
InfoPrint("UnRegisterCallback succeeded");
}
InfoPrint("");
return Status;
}
NTSTATUS
GetCallbackVersion(
_In_ PDEVICE_OBJECT DeviceObject,
_In_ PIRP Irp
)
/*++
Routine Description:
Calls CmGetCallbackVersion
Arguments:
DeviceObject - The device object receiving the request.
Irp - The request packet.
Return Value:
NTSTATUS
--*/
{
NTSTATUS Status = STATUS_SUCCESS;
PIO_STACK_LOCATION IrpStack;
ULONG OutputBufferLength;
PGET_CALLBACK_VERSION_OUTPUT GetCallbackVersionOutput;
UNREFERENCED_PARAMETER(DeviceObject);
//
// Get the output buffer and verify its size
//
IrpStack = IoGetCurrentIrpStackLocation(Irp);
OutputBufferLength = IrpStack->Parameters.DeviceIoControl.OutputBufferLength;
if (OutputBufferLength < sizeof(GET_CALLBACK_VERSION_OUTPUT)) {
Status = STATUS_INVALID_PARAMETER;
goto Exit;
}
GetCallbackVersionOutput = (PGET_CALLBACK_VERSION_OUTPUT) Irp->AssociatedIrp.SystemBuffer;
//
// Call CmGetCallbackVersion and store the results in the output buffer
//
CmGetCallbackVersion(&GetCallbackVersionOutput->MajorVersion,
&GetCallbackVersionOutput->MinorVersion);
Irp->IoStatus.Information = sizeof(GET_CALLBACK_VERSION_OUTPUT);
Exit:
if (!NT_SUCCESS(Status)) {
ErrorPrint("GetCallbackVersion failed. Status 0x%x", Status);
} else {
InfoPrint("GetCallbackVersion succeeded");
}
return Status;
}
LPCWSTR
GetNotifyClassString (
_In_ REG_NOTIFY_CLASS NotifyClass
)
/*++
Routine Description:
Converts from NotifyClass to a string
Arguments:
NotifyClass - value that identifies the type of registry operation that
is being performed
Return Value:
Returns a string of the name of NotifyClass.
--*/
{
switch (NotifyClass) {
case RegNtPreDeleteKey: return L"RegNtPreDeleteKey";
case RegNtPreSetValueKey: return L"RegNtPreSetValueKey";
case RegNtPreDeleteValueKey: return L"RegNtPreDeleteValueKey";
case RegNtPreSetInformationKey: return L"RegNtPreSetInformationKey";
case RegNtPreRenameKey: return L"RegNtPreRenameKey";
case RegNtPreEnumerateKey: return L"RegNtPreEnumerateKey";
case RegNtPreEnumerateValueKey: return L"RegNtPreEnumerateValueKey";
case RegNtPreQueryKey: return L"RegNtPreQueryKey";
case RegNtPreQueryValueKey: return L"RegNtPreQueryValueKey";
case RegNtPreQueryMultipleValueKey: return L"RegNtPreQueryMultipleValueKey";
case RegNtPreKeyHandleClose: return L"RegNtPreKeyHandleClose";
case RegNtPreCreateKeyEx: return L"RegNtPreCreateKeyEx";
case RegNtPreOpenKeyEx: return L"RegNtPreOpenKeyEx";
case RegNtPreFlushKey: return L"RegNtPreFlushKey";
case RegNtPreLoadKey: return L"RegNtPreLoadKey";
case RegNtPreUnLoadKey: return L"RegNtPreUnLoadKey";
case RegNtPreQueryKeySecurity: return L"RegNtPreQueryKeySecurity";
case RegNtPreSetKeySecurity: return L"RegNtPreSetKeySecurity";
case RegNtPreRestoreKey: return L"RegNtPreRestoreKey";
case RegNtPreSaveKey: return L"RegNtPreSaveKey";
case RegNtPreReplaceKey: return L"RegNtPreReplaceKey";
case RegNtPostDeleteKey: return L"RegNtPostDeleteKey";
case RegNtPostSetValueKey: return L"RegNtPostSetValueKey";
case RegNtPostDeleteValueKey: return L"RegNtPostDeleteValueKey";
case RegNtPostSetInformationKey: return L"RegNtPostSetInformationKey";
case RegNtPostRenameKey: return L"RegNtPostRenameKey";
case RegNtPostEnumerateKey: return L"RegNtPostEnumerateKey";
case RegNtPostEnumerateValueKey: return L"RegNtPostEnumerateValueKey";
case RegNtPostQueryKey: return L"RegNtPostQueryKey";
case RegNtPostQueryValueKey: return L"RegNtPostQueryValueKey";
case RegNtPostQueryMultipleValueKey: return L"RegNtPostQueryMultipleValueKey";
case RegNtPostKeyHandleClose: return L"RegNtPostKeyHandleClose";
case RegNtPostCreateKeyEx: return L"RegNtPostCreateKeyEx";
case RegNtPostOpenKeyEx: return L"RegNtPostOpenKeyEx";
case RegNtPostFlushKey: return L"RegNtPostFlushKey";
case RegNtPostLoadKey: return L"RegNtPostLoadKey";
case RegNtPostUnLoadKey: return L"RegNtPostUnLoadKey";
case RegNtPostQueryKeySecurity: return L"RegNtPostQueryKeySecurity";
case RegNtPostSetKeySecurity: return L"RegNtPostSetKeySecurity";
case RegNtPostRestoreKey: return L"RegNtPostRestoreKey";
case RegNtPostSaveKey: return L"RegNtPostSaveKey";
case RegNtPostReplaceKey: return L"RegNtPostReplaceKey";
case RegNtCallbackObjectContextCleanup: return L"RegNtCallbackObjectContextCleanup";
default:
return L"Unsupported REG_NOTIFY_CLASS";
}
}
LPCWSTR
GetTransactionNotifyClassString (
_In_ ULONG TransactionNotifcation
)
/*++
Routine Description:
Converts from TransactionNotification to a string
Arguments:
TransactionNotification - value that identifies the type of
transaction notification
Return Value:
Returns a string of the name of TransactionNotification
--*/
{
switch (TransactionNotifcation) {
case TRANSACTION_NOTIFY_COMMIT: return L"TRANSACTION_NOTIFY_COMMIT";
case TRANSACTION_NOTIFY_ROLLBACK: return L"TRANSACTION_NOTIFY_ROLLBACK";
default:
return L"Unsupported Transaction Notification";
}
}
VOID
DeleteTestKeys(
)
/*++
--*/
{
NTSTATUS Status;
UNICODE_STRING KeyPath;
OBJECT_ATTRIBUTES KeyAttributes;
HANDLE RootKey = NULL;
HANDLE ChildKey = NULL;
//
// Check if the root key can be opened. If it can be opened, a previous
// run must have not completed cleanly. Delete the key and recreate the
// root key.
//
RtlInitUnicodeString(&KeyPath, ROOT_KEY_ABS_PATH);
InitializeObjectAttributes(&KeyAttributes,
&KeyPath,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
NULL,
NULL);
Status = ZwOpenKey(&RootKey,
KEY_ALL_ACCESS,
&KeyAttributes);
if (Status == STATUS_OBJECT_NAME_NOT_FOUND) {
return;
} else if (!NT_SUCCESS(Status)) {
ErrorPrint("Opening root key fails with unexpected status %x.", Status);
}
RtlInitUnicodeString(&KeyPath, KEY_NAME);
InitializeObjectAttributes(&KeyAttributes,
&KeyPath,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
RootKey,
NULL);
Status = ZwOpenKey(&ChildKey,
KEY_ALL_ACCESS,
&KeyAttributes);
if (NT_SUCCESS(Status)) {
ZwDeleteKey(ChildKey);
ZwClose(ChildKey);
ChildKey = NULL;
} else if (Status != STATUS_OBJECT_NAME_NOT_FOUND) {
ErrorPrint("Opening %S key fails with unexpected status %x.",
KEY_NAME,
Status);
}
RtlInitUnicodeString(&KeyPath, NOT_MODIFIED_KEY_NAME);
InitializeObjectAttributes(&KeyAttributes,
&KeyPath,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
RootKey,
NULL);
Status = ZwOpenKey(&ChildKey,
KEY_ALL_ACCESS,
&KeyAttributes);
if (NT_SUCCESS(Status)) {
ZwDeleteKey(ChildKey);
ZwClose(ChildKey);
ChildKey = NULL;
} else if (Status != STATUS_OBJECT_NAME_NOT_FOUND) {
ErrorPrint("Opening %S key fails with unexpected status %x.",
NOT_MODIFIED_KEY_NAME,
Status);
}
RtlInitUnicodeString(&KeyPath, MODIFIED_KEY_NAME);
InitializeObjectAttributes(&KeyAttributes,
&KeyPath,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
RootKey,
NULL);
Status = ZwOpenKey(&ChildKey,
KEY_ALL_ACCESS,
&KeyAttributes);
if (NT_SUCCESS(Status)) {
ZwDeleteKey(ChildKey);
ZwClose(ChildKey);
ChildKey = NULL;
} else if (Status != STATUS_OBJECT_NAME_NOT_FOUND) {
ErrorPrint("Opening %S key fails with unexpected status %x.",
MODIFIED_KEY_NAME,
Status);
}
ZwDeleteKey(RootKey);
ZwClose(RootKey);
return;
}