-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfilter.c
More file actions
732 lines (587 loc) · 22.8 KB
/
Copy pathfilter.c
File metadata and controls
732 lines (587 loc) · 22.8 KB
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
/*++
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:
filter.c
Abstract:
This module shows how to a write a generic filter driver. The driver demonstrates how
to support device I/O control requests through queues. All the I/O requests passed on to
the lower driver. This filter driver shows how to handle IRP postprocessing by forwarding
the requests with and without a completion routine. To forward with a completion routine
set the define FORWARD_REQUEST_WITH_COMPLETION to 1.
Environment:
Kernel mode
--*/
#include "filter.h"
#define BLOCK_IOCTL_KS_PROPERTY 0
#define BLOCK_IOCTL_KS_READ_STREAM 1
#ifdef ALLOC_PRAGMA
#pragma alloc_text (INIT, DriverEntry)
#pragma alloc_text (PAGE, FilterEvtDeviceAdd)
#endif
const GUID GUID_PROPSETID_Topology = { STATIC_KSPROPSETID_Topology };
const GUID GUID_PROPSETID_Pin = { STATIC_KSPROPSETID_Pin };
const GUID GUID_PROPSETID_Stream = { STATIC_KSPROPSETID_Stream };
const GUID GUID_PROPSETID_MemoryTransport = { STATIC_KSPROPSETID_MemoryTransport };
const GUID GUID_PROPSETID_Connection = { STATIC_KSPROPSETID_Connection };
const GUID GUID_PROPSETID_VidcapCameraControl = { STATIC_PROPSETID_VIDCAP_CAMERACONTROL };
NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
)
/*++
Routine Description:
Installable driver initialization entry point.
This entry point is called directly by the I/O system.
Arguments:
DriverObject - pointer to the driver object
RegistryPath - pointer to a unicode string representing the path,
to driver-specific key in the registry.
Return Value:
STATUS_SUCCESS if successful,
STATUS_UNSUCCESSFUL otherwise.
--*/
{
WDF_DRIVER_CONFIG config;
NTSTATUS status;
WDFDRIVER hDriver;
KdPrint(("[webcam-interception] Driver Sample\n"));
//
// Initialize driver config to control the attributes that
// are global to the driver. Note that framework by default
// provides a driver unload routine. If you create any resources
// in the DriverEntry and want to be cleaned in driver unload,
// you can override that by manually setting the EvtDriverUnload in the
// config structure. In general xxx_CONFIG_INIT macros are provided to
// initialize most commonly used members.
//
WDF_DRIVER_CONFIG_INIT(
&config,
FilterEvtDeviceAdd
);
//
// Create a framework driver object to represent our driver.
//
status = WdfDriverCreate(DriverObject,
RegistryPath,
WDF_NO_OBJECT_ATTRIBUTES,
&config,
&hDriver);
if (!NT_SUCCESS(status)) {
KdPrint(("[webcam-interception] WdfDriverCreate failed with status 0x%x\n", status));
}
return status;
}
NTSTATUS
FilterEvtDeviceAdd(
IN WDFDRIVER Driver,
IN PWDFDEVICE_INIT DeviceInit
)
/*++
Routine Description:
EvtDeviceAdd is called by the framework in response to AddDevice
call from the PnP manager. Here you can query the device properties
using WdfFdoInitWdmGetPhysicalDevice/IoGetDeviceProperty and based
on that, decide to create a filter device object and attach to the
function stack. If you are not interested in filtering this particular
instance of the device, you can just return STATUS_SUCCESS without creating
a framework device.
Arguments:
Driver - Handle to a framework driver object created in DriverEntry
DeviceInit - Pointer to a framework-allocated WDFDEVICE_INIT structure.
Return Value:
NTSTATUS
--*/
{
WDF_OBJECT_ATTRIBUTES deviceAttributes;
PFILTER_EXTENSION filterExt;
NTSTATUS status;
WDFDEVICE device;
WDF_IO_QUEUE_CONFIG ioQueueConfig;
#if DBG
UCHAR majorFunction;
#endif // DBG
PAGED_CODE();
UNREFERENCED_PARAMETER(Driver);
//
// Tell the framework that you are filter driver. Framework
// takes care of inheriting all the device flags & characteristics
// from the lower device you are attaching to.
//
WdfFdoInitSetFilter(DeviceInit);
#if DBG
//
// Register the EvtDeviceWdmIrpPreprocess callback for logging.
//
for (majorFunction = IRP_MJ_CREATE; majorFunction <= IRP_MJ_MAXIMUM_FUNCTION; majorFunction++) {
status = WdfDeviceInitAssignWdmIrpPreprocessCallback(DeviceInit,
FilterEvtIrpPreprocess,
majorFunction,
NULL,
0);
if (!NT_SUCCESS(status)) {
KdPrint(("[webcam-interception] WdfDeviceInitAssignWdmIrpPreprocessCallback failed with status code 0x%x\n", status));
}
}
#endif // DBG
//
// Register the EvtIoInCallerContext callback to deal with IOCTLs that need to stay in original context.
//
WdfDeviceInitSetIoInCallerContextCallback(DeviceInit, FilterEvtIoInCallerContext);
//
// Specify the size of device extension where we track per device
// context.
//
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&deviceAttributes, FILTER_EXTENSION);
//
// Create a framework device object. This call will inturn create
// a WDM deviceobject, attach to the lower stack and set the
// appropriate flags and attributes.
//
status = WdfDeviceCreate(&DeviceInit, &deviceAttributes, &device);
if (!NT_SUCCESS(status)) {
KdPrint(("[webcam-interception] WdfDeviceCreate failed with status code 0x%x\n", status));
return status;
}
filterExt = FilterGetData(device);
//
// Configure the default queue to be Parallel.
//
WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&ioQueueConfig,
WdfIoQueueDispatchParallel);
//
// Framework by default creates non-power managed queues for
// filter drivers.
//
ioQueueConfig.EvtIoDeviceControl = FilterEvtIoDeviceControl;
status = WdfIoQueueCreate(device,
&ioQueueConfig,
WDF_NO_OBJECT_ATTRIBUTES,
WDF_NO_HANDLE // pointer to default queue
);
if (!NT_SUCCESS(status)) {
KdPrint(("[webcam-interception] WdfIoQueueCreate failed 0x%x\n", status));
return status;
}
return status;
}
#if DBG
VOID
PrintGuidValues(LPCGUID lpGuid)
{
KdPrint(("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
lpGuid->Data1,
lpGuid->Data2,
lpGuid->Data3,
lpGuid->Data4[0],
lpGuid->Data4[1],
lpGuid->Data4[2],
lpGuid->Data4[3],
lpGuid->Data4[4],
lpGuid->Data4[5],
lpGuid->Data4[6],
lpGuid->Data4[7]));
}
VOID
LogIoctlKsProperty(
IN PIRP Irp,
IN PIO_STACK_LOCATION currentStack
)
{
PKSIDENTIFIER Request = currentStack->Parameters.DeviceIoControl.Type3InputBuffer;
if (IsEqualGUID(&Request->Set, &GUID_PROPSETID_Topology)) {
KdPrint(("\trequest: Topology\n"));
}
else if (IsEqualGUID(&Request->Set, &GUID_PROPSETID_Pin)) {
KdPrint(("\trequest: Pin\n"));
}
else if (IsEqualGUID(&Request->Set, &GUID_PROPSETID_Stream)) {
KdPrint(("\trequest: Stream\n"));
}
else if (IsEqualGUID(&Request->Set, &GUID_PROPSETID_MemoryTransport)) {
KdPrint(("\trequest: MemoryTransport\n"));
}
else if (IsEqualGUID(&Request->Set, &GUID_PROPSETID_Connection)) {
KdPrint(("\trequest: Connection\n"));
switch (Request->Id) {
case KSPROPERTY_CONNECTION_STATE: KdPrint(("\tKSPROPERTY_CONNECTION_STATE\n")); break;
case KSPROPERTY_CONNECTION_PRIORITY: KdPrint(("\tKSPROPERTY_CONNECTION_PRIORITY\n")); break;
case KSPROPERTY_CONNECTION_DATAFORMAT: KdPrint(("\tKSPROPERTY_CONNECTION_DATAFORMAT\n")); break;
case KSPROPERTY_CONNECTION_ALLOCATORFRAMING: KdPrint(("\tKSPROPERTY_CONNECTION_ALLOCATORFRAMING\n")); break;
case KSPROPERTY_CONNECTION_PROPOSEDATAFORMAT: KdPrint(("\tKSPROPERTY_CONNECTION_PROPOSEDATAFORMAT\n")); break;
case KSPROPERTY_CONNECTION_ACQUIREORDERING: KdPrint(("\tKSPROPERTY_CONNECTION_ACQUIREORDERING\n")); break;
case KSPROPERTY_CONNECTION_ALLOCATORFRAMING_EX: KdPrint(("\tKSPROPERTY_CONNECTION_ALLOCATORFRAMING_EX\n")); break;
case KSPROPERTY_CONNECTION_STARTAT: KdPrint(("\tKSPROPERTY_CONNECTION_STARTAT\n")); break;
}
if (Request->Id == KSPROPERTY_CONNECTION_STATE) {
PKSSTATE pksState = Irp->UserBuffer;
if (Request->Flags == KSPROPERTY_TYPE_SET) {
switch (*pksState) {
case KSSTATE_STOP:
KdPrint(("\tset type: KSSTATE_STOP\n"));
break;
case KSSTATE_ACQUIRE:
KdPrint(("\tset type: KSSTATE_ACQUIRE\n"));
break;
case KSSTATE_PAUSE:
KdPrint(("\tset type: KSSTATE_PAUSE\n"));
break;
case KSSTATE_RUN:
KdPrint(("\tset type: KSSTATE_RUN\n"));
break;
}
}
else {
KdPrint(("\tflags: 0x%x\n", Request->Flags));
}
}
}
else {
KdPrint(("\trequest: "));
PrintGuidValues(&Request->Set);
KdPrint(("\n"));
}
}
VOID
LogDeviceControlIrp(
IN PIRP Irp,
IN PIO_STACK_LOCATION currentStack
)
{
LPSTR ioctl;
ioctl = NULL;
switch (currentStack->Parameters.DeviceIoControl.IoControlCode) {
case IOCTL_KS_READ_STREAM: ioctl = "IOCTL_KS_READ_STREAM"; break;
case IOCTL_KS_WRITE_STREAM: ioctl = "IOCTL_KS_WRITE_STREAM"; break;
case IOCTL_KS_PROPERTY: ioctl = "IOCTL_KS_PROPERTY"; break;
case IOCTL_KS_METHOD: ioctl = "IOCTL_KS_METHOD"; break;
case IOCTL_KS_ENABLE_EVENT: ioctl = "IOCTL_KS_ENABLE_EVENT"; break;
}
if (ioctl) {
KdPrint(("\tioctl: %s\n", ioctl));
}
else {
KdPrint(("\tioctl: 0x%x\n", currentStack->Parameters.DeviceIoControl.IoControlCode));
}
switch (currentStack->Parameters.DeviceIoControl.IoControlCode) {
case IOCTL_KS_PROPERTY: LogIoctlKsProperty(Irp, currentStack); break;
}
}
VOID
LogCreateIrp(
IN PIO_STACK_LOCATION currentStack
)
{
USHORT i;
KdPrint(("\tfilename:"));
for (i = 0; i < currentStack->FileObject->FileName.Length / 2; i++) {
KdPrint((" %02X", LOBYTE(currentStack->FileObject->FileName.Buffer[i])));
KdPrint((" %02X", HIBYTE(currentStack->FileObject->FileName.Buffer[i])));
}
KdPrint(("\n"));
}
NTSTATUS
FilterEvtIrpPreprocess(
IN WDFDEVICE Device,
PIRP Irp
)
{
PIO_STACK_LOCATION currentStack;
LPSTR major;
currentStack = IoGetCurrentIrpStackLocation(Irp);
major = "???";
switch (currentStack->MajorFunction) {
case IRP_MJ_CREATE: major = "IRP_MJ_CREATE"; break;
case IRP_MJ_CREATE_NAMED_PIPE: major = "IRP_MJ_CREATE_NAMED_PIPE"; break;
case IRP_MJ_CLOSE: major = "IRP_MJ_CLOSE"; break;
case IRP_MJ_READ: major = "IRP_MJ_READ"; break;
case IRP_MJ_WRITE: major = "IRP_MJ_WRITE"; break;
case IRP_MJ_QUERY_INFORMATION: major = "IRP_MJ_QUERY_INFORMATION"; break;
case IRP_MJ_SET_INFORMATION: major = "IRP_MJ_SET_INFORMATION"; break;
case IRP_MJ_QUERY_EA: major = "IRP_MJ_QUERY_EA"; break;
case IRP_MJ_SET_EA: major = "IRP_MJ_SET_EA"; break;
case IRP_MJ_FLUSH_BUFFERS: major = "IRP_MJ_FLUSH_BUFFERS"; break;
case IRP_MJ_QUERY_VOLUME_INFORMATION: major = "IRP_MJ_QUERY_VOLUME_INFORMATION"; break;
case IRP_MJ_SET_VOLUME_INFORMATION: major = "IRP_MJ_SET_VOLUME_INFORMATION"; break;
case IRP_MJ_DIRECTORY_CONTROL: major = "IRP_MJ_DIRECTORY_CONTROL"; break;
case IRP_MJ_FILE_SYSTEM_CONTROL: major = "IRP_MJ_FILE_SYSTEM_CONTROL"; break;
case IRP_MJ_DEVICE_CONTROL: major = "IRP_MJ_DEVICE_CONTROL"; break;
case IRP_MJ_INTERNAL_DEVICE_CONTROL: major = "IRP_MJ_INTERNAL_DEVICE_CONTROL"; break;
case IRP_MJ_SHUTDOWN: major = "IRP_MJ_SHUTDOWN"; break;
case IRP_MJ_LOCK_CONTROL: major = "IRP_MJ_LOCK_CONTROL"; break;
case IRP_MJ_CLEANUP: major = "IRP_MJ_CLEANUP"; break;
case IRP_MJ_CREATE_MAILSLOT: major = "IRP_MJ_CREATE_MAILSLOT"; break;
case IRP_MJ_QUERY_SECURITY: major = "IRP_MJ_QUERY_SECURITY"; break;
case IRP_MJ_SET_SECURITY: major = "IRP_MJ_SET_SECURITY"; break;
case IRP_MJ_POWER: major = "IRP_MJ_POWER"; break;
case IRP_MJ_SYSTEM_CONTROL: major = "IRP_MJ_SYSTEM_CONTROL"; break;
case IRP_MJ_DEVICE_CHANGE: major = "IRP_MJ_DEVICE_CHANGE"; break;
case IRP_MJ_QUERY_QUOTA: major = "IRP_MJ_QUERY_QUOTA"; break;
case IRP_MJ_SET_QUOTA: major = "IRP_MJ_SET_QUOTA"; break;
case IRP_MJ_PNP: major = "IRP_MJ_PNP"; break;
}
if (major) {
KdPrint(("[webcam-interception] major: %s\n", major));
}
switch (currentStack->MajorFunction) {
case IRP_MJ_CREATE: LogCreateIrp(currentStack); break;
case IRP_MJ_DEVICE_CONTROL: LogDeviceControlIrp(Irp, currentStack); break;
}
IoSkipCurrentIrpStackLocation(Irp);
return WdfDeviceWdmDispatchPreprocessedIrp(Device, Irp);
}
#endif // DBG
VOID
FilterEvtIoInCallerContext(
IN WDFDEVICE Device,
IN WDFREQUEST Request
)
{
#if BLOCK_IOCTL_KS_PROPERTY
size_t inBufLen, outBufLen;
PVOID inBuf, outBuf;
WDFMEMORY InputMemoryBuffer, OutputMemoryBuffer;
PKSIDENTIFIER pKSIdent;
PKSSTATE pKSState;
#endif // BLOCK_IOCTL_KS_PROPERTY
WDF_REQUEST_PARAMETERS params;
NTSTATUS status = STATUS_SUCCESS;
WDF_REQUEST_PARAMETERS_INIT(¶ms);
WdfRequestGetParameters(Request, ¶ms);
#if BLOCK_IOCTL_KS_PROPERTY
if (params.Type == WdfRequestTypeDeviceControl &&
params.Parameters.DeviceIoControl.IoControlCode == IOCTL_KS_PROPERTY) {
//
// The I/O control code is METHOD_NEITHER.
// First, retrieve the virtual addresses of
// the input buffer.
//
status = WdfRequestRetrieveUnsafeUserInputBuffer(Request, sizeof(KSIDENTIFIER), &inBuf, &inBufLen);
if (!NT_SUCCESS(status)) {
goto Error;
}
//
// Next, probe and lock the read buffer.
//
status = WdfRequestProbeAndLockUserBufferForRead(Request, inBuf, inBufLen, &InputMemoryBuffer);
if (!NT_SUCCESS(status)) {
goto Error;
}
pKSIdent = WdfMemoryGetBuffer(InputMemoryBuffer, NULL);
if (IsEqualGUID(&pKSIdent->Set, &GUID_PROPSETID_Connection)) {
if (pKSIdent->Id == KSPROPERTY_CONNECTION_STATE) {
if (pKSIdent->Flags & KSPROPERTY_TYPE_SET) {
status = WdfRequestRetrieveUnsafeUserOutputBuffer(Request, sizeof(KSSTATE), &outBuf, &outBufLen);
if(!NT_SUCCESS(status)) {
goto Error;
}
//
// Note: even though it's an output buffer,
// we're going to read from it, that's how
// IOCTL_KS_PROPERTY works.
//
status = WdfRequestProbeAndLockUserBufferForRead(Request, outBuf, outBufLen, &OutputMemoryBuffer);
if(!NT_SUCCESS(status)) {
goto Error;
}
pKSState = WdfMemoryGetBuffer(OutputMemoryBuffer, NULL);
switch(*pKSState) {
case KSSTATE_ACQUIRE:
status = STATUS_INSUFFICIENT_RESOURCES;
break;
case KSSTATE_RUN:
status = STATUS_ACCESS_DENIED;
break;
}
}
}
}
if (!NT_SUCCESS(status)) {
goto Error;
}
}
#endif // BLOCK_IOCTL_KS_PROPERTY
status = WdfDeviceEnqueueRequest(Device, Request);
if (!NT_SUCCESS(status)) {
KdPrint(("[webcam-interception] WdfDeviceEnqueueRequest failed: %s\n", status));
goto Error;
}
return;
Error:
WdfRequestComplete(Request, status);
}
VOID
FilterEvtIoDeviceControl(
IN WDFQUEUE Queue,
IN WDFREQUEST Request,
IN size_t OutputBufferLength,
IN size_t InputBufferLength,
IN ULONG IoControlCode
)
/*++
Routine Description:
This routine is the dispatch routine for internal device control requests.
Arguments:
Queue - Handle to the framework queue object that is associated
with the I/O request.
Request - Handle to a framework request object.
OutputBufferLength - length of the request's output buffer,
if an output buffer is available.
InputBufferLength - length of the request's input buffer,
if an input buffer is available.
IoControlCode - the driver-defined or system-defined I/O control code
(IOCTL) that is associated with the request.
Return Value:
VOID
--*/
{
PFILTER_EXTENSION filterExt;
NTSTATUS status = STATUS_SUCCESS;
WDFDEVICE device;
WDFCONTEXT context = WDF_NO_CONTEXT;
UNREFERENCED_PARAMETER(OutputBufferLength);
UNREFERENCED_PARAMETER(InputBufferLength);
//KdPrint(("[webcam-interception] Entered FilterEvtIoDeviceControl\n"));
device = WdfIoQueueGetDevice(Queue);
filterExt = FilterGetData(device);
switch (IoControlCode) {
#if BLOCK_IOCTL_KS_READ_STREAM
case IOCTL_KS_READ_STREAM:
context = "IOCTL_KS_READ_STREAM";
break;
#endif // BLOCK_IOCTL_KS_READ_STREAM
}
if (!NT_SUCCESS(status)) {
WdfRequestComplete(Request, status);
return;
}
//
// Forward the request down. WdfDeviceGetIoTarget returns
// the default target, which represents the device attached to us below in
// the stack.
//
#if FORWARD_REQUEST_WITH_COMPLETION
//
// Use this routine to forward a request if you are interested in post
// processing the IRP.
//
FilterForwardRequestWithCompletionRoutine(Request,
WdfDeviceGetIoTarget(device),
context);
#else
FilterForwardRequest(Request, WdfDeviceGetIoTarget(device));
#endif
return;
}
VOID
FilterForwardRequest(
IN WDFREQUEST Request,
IN WDFIOTARGET Target
)
/*++
Routine Description:
Passes a request on to the lower driver.
--*/
{
WDF_REQUEST_SEND_OPTIONS options;
BOOLEAN ret;
NTSTATUS status;
//
// 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, Target, &options);
if (ret == FALSE) {
status = WdfRequestGetStatus(Request);
KdPrint(("[webcam-interception] WdfRequestSend failed: 0x%x\n", status));
WdfRequestComplete(Request, status);
}
return;
}
#if FORWARD_REQUEST_WITH_COMPLETION
VOID
FilterForwardRequestWithCompletionRoutine(
IN WDFREQUEST Request,
IN WDFIOTARGET Target,
IN WDFCONTEXT Context
)
/*++
Routine Description:
This routine forwards the request to a lower driver with
a completion so that when the request is completed by the
lower driver, it can regain control of the request and look
at the result.
--*/
{
BOOLEAN ret;
NTSTATUS status;
//
// The following function essentially copies the content of
// current stack location of the underlying IRP to the next one.
//
WdfRequestFormatRequestUsingCurrentType(Request);
WdfRequestSetCompletionRoutine(Request,
FilterRequestCompletionRoutine,
Context);
ret = WdfRequestSend(Request,
Target,
WDF_NO_SEND_OPTIONS);
if (ret == FALSE) {
status = WdfRequestGetStatus(Request);
KdPrint(("[webcam-interception] WdfRequestSend failed: 0x%x\n", status));
WdfRequestComplete(Request, status);
}
return;
}
VOID
FilterRequestCompletionRoutine(
IN WDFREQUEST Request,
IN WDFIOTARGET Target,
PWDF_REQUEST_COMPLETION_PARAMS CompletionParams,
IN WDFCONTEXT Context
)
/*++
Routine Description:
Completion Routine
Arguments:
Target - Target handle
Request - Request handle
Params - request completion params
Context - Driver supplied context
Return Value:
VOID
--*/
{
#if BLOCK_IOCTL_KS_READ_STREAM
PIRP Irp;
PKSSTREAM_HEADER pStreamHdr;
PUCHAR pMdlBufferOut;
#endif // BLOCK_IOCTL_KS_READ_STREAM
UNREFERENCED_PARAMETER(Target);
UNREFERENCED_PARAMETER(Context);
//KdPrint(("[webcam-interception] status: 0x%x\n", CompletionParams->IoStatus.Status));
#if BLOCK_IOCTL_KS_READ_STREAM
if (Context != WDF_NO_CONTEXT && CompletionParams->IoStatus.Status == STATUS_SUCCESS) {
Irp = WdfRequestWdmGetIrp(Request);
pStreamHdr = (PKSSTREAM_HEADER)Irp->AssociatedIrp.SystemBuffer;
if (pStreamHdr) {
if (Irp->MdlAddress) {
pMdlBufferOut = (PUCHAR)MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
// Fill the frame buffer with zero bytes.
RtlSecureZeroMemory(pMdlBufferOut, pStreamHdr->DataUsed);
// Set the frame size to zero.
pStreamHdr->DataUsed = 0;
}
}
}
#endif // BLOCK_IOCTL_KS_READ_STREAM
WdfRequestComplete(Request, CompletionParams->IoStatus.Status);
return;
}
#endif //FORWARD_REQUEST_WITH_COMPLETION