-
Notifications
You must be signed in to change notification settings - Fork 2
/
kbfiltr.h
205 lines (145 loc) · 4.25 KB
/
kbfiltr.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
/*++
Copyright (c) 1997 Microsoft Corporation
Module Name:
kbfilter.h
Abstract:
This module contains the common private declarations for the keyboard
packet filter
Environment:
kernel mode only
--*/
#ifndef KBFILTER_H
#define KBFILTER_H
#pragma warning(disable:4201)
#include "ntddk.h"
#include "kbdmou.h"
#include <ntddkbd.h>
#include <ntdd8042.h>
#pragma warning(default:4201)
#include <wdf.h>
#define NTSTRSAFE_LIB
#include <ntstrsafe.h>
#include <initguid.h>
#include <devguid.h>
#include "public.h"
#define KBFILTER_POOL_TAG (ULONG) 'tlfK'
#define EnableDebugOutput
#ifdef EnableDebugOutput
#define DebugPrint(_x_) DbgPrint _x_
#else
#define DebugPrint(_x_)
#endif
#if DBG
#define TRAP() DbgBreakPoint()
#else
#define TRAP()
#endif
#define MIN(_A_,_B_) (((_A_) < (_B_)) ? (_A_) : (_B_))
typedef struct _DEVICE_EXTENSION
{
WDFDEVICE WdfDevice;
//
// Queue for handling requests that come from the rawPdo
//
WDFQUEUE rawPdoQueue;
//
// Number of creates sent down
//
LONG EnableCount;
//
// The real connect data that this driver reports to
//
CONNECT_DATA UpperConnectData;
//
// Previous initialization and hook routines (and context)
//
PVOID UpperContext;
PI8042_KEYBOARD_INITIALIZATION_ROUTINE UpperInitializationRoutine;
PI8042_KEYBOARD_ISR UpperIsrHook;
//
// Write function from within KbFilter_IsrHook
//
IN PI8042_ISR_WRITE_PORT IsrWritePort;
//
// Queue the current packet (ie the one passed into KbFilter_IsrHook)
//
IN PI8042_QUEUE_PACKET QueueKeyboardPacket;
//
// Context for IsrWritePort, QueueKeyboardPacket
//
IN PVOID CallContext;
//
// Cached Keyboard Attributes
//
KEYBOARD_ATTRIBUTES KeyboardAttributes;
} DEVICE_EXTENSION, *PDEVICE_EXTENSION;
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DEVICE_EXTENSION,
FilterGetData)
typedef struct _WORKER_ITEM_CONTEXT {
WDFREQUEST Request;
WDFIOTARGET IoTarget;
} WORKER_ITEM_CONTEXT, *PWORKER_ITEM_CONTEXT;
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(WORKER_ITEM_CONTEXT, GetWorkItemContext)
//
// Prototypes
//
DRIVER_INITIALIZE DriverEntry;
EVT_WDF_DRIVER_DEVICE_ADD KbFilter_EvtDeviceAdd;
EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL KbFilter_EvtIoDeviceControlForRawPdo;
EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL KbFilter_EvtIoDeviceControlFromRawPdo;
EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL KbFilter_EvtIoInternalDeviceControl;
NTSTATUS
KbFilter_InitializationRoutine(
IN PVOID InitializationContext,
IN PVOID SynchFuncContext,
IN PI8042_SYNCH_READ_PORT ReadPort,
IN PI8042_SYNCH_WRITE_PORT WritePort,
OUT PBOOLEAN TurnTranslationOn
);
BOOLEAN
KbFilter_IsrHook(
PVOID IsrContext,
PKEYBOARD_INPUT_DATA CurrentInput,
POUTPUT_PACKET CurrentOutput,
UCHAR StatusByte,
PUCHAR DataByte,
PBOOLEAN ContinueProcessing,
PKEYBOARD_SCAN_STATE ScanState
);
VOID
KbFilter_ServiceCallback(
IN PDEVICE_OBJECT DeviceObject,
IN PKEYBOARD_INPUT_DATA InputDataStart,
IN PKEYBOARD_INPUT_DATA InputDataEnd,
IN OUT PULONG InputDataConsumed
);
EVT_WDF_REQUEST_COMPLETION_ROUTINE
KbFilterRequestCompletionRoutine;
//
// IOCTL Related defintions
//
//
// Used to identify kbfilter bus. This guid is used as the enumeration string
// for the device id.
DEFINE_GUID(GUID_BUS_KBFILTER,
0xa65c87f9, 0xbe02, 0x4ed9, 0x92, 0xec, 0x1, 0x2d, 0x41, 0x61, 0x69, 0xfa);
// {A65C87F9-BE02-4ed9-92EC-012D416169FA}
DEFINE_GUID(GUID_DEVINTERFACE_KBFILTER,
0x3fb7299d, 0x6847, 0x4490, 0xb0, 0xc9, 0x99, 0xe0, 0x98, 0x6a, 0xb8, 0x86);
// {3FB7299D-6847-4490-B0C9-99E0986AB886}
#define KBFILTR_DEVICE_ID L"{A65C87F9-BE02-4ed9-92EC-012D416169FA}\\KeyboardFilter\0"
typedef struct _RPDO_DEVICE_DATA
{
ULONG InstanceNo;
//
// Queue of the parent device we will forward requests to
//
WDFQUEUE ParentQueue;
} RPDO_DEVICE_DATA, *PRPDO_DEVICE_DATA;
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(RPDO_DEVICE_DATA, PdoGetData)
NTSTATUS
KbFiltr_CreateRawPdo(
WDFDEVICE Device,
ULONG InstanceNo
);
#endif // KBFILTER_H