3 Copyright (c) 1998-2001 Klaus P. Gerlicher
11 hooking of kernel internal keyboard interrupt handler
20 Reactos Port: Eugene Ingerman
25 15-Nov-2000: general cleanup of source files
26 12/1/2001 reactos port
30 This file may be distributed under the terms of the GNU Public License.
34 ////////////////////////////////////////////////////
40 #include <asm/system.h>
42 #include <ddk/ntddkbd.h>
43 #include <ddk/ntdd8042.h>
45 ////////////////////////////////////////////////////
49 static PUCHAR pPatchAddress
;
50 static ULONG ulOldOffset
= 0;
51 static ULONG ulKeyPatchFlags
;
53 void (*old_handle_scancode
)(UCHAR
,int);
55 UCHAR ucBreakKey
= 'D'; // key that will break into debugger in combination with CTRL
57 ////////////////////////////////////////////////////
61 //***********************************************************************************
62 // PiceKbdIsr - keyboard isr hook routine.
63 // IsrContext - context that we passed to keyboard driver in internal iocontrol
64 // pCurrentInput, pCurrentOutput - not implemented yet
65 // StatusByte - keyboard status register
66 // pByte - pointer to the byte read from keyboard data port. can be changed.
67 // pContinueProcessing - should keyboard driver continue processing this byte.
68 //***********************************************************************************
71 PKEYBOARD_INPUT_DATA pCurrentInput
,
72 POUTPUT_PACKET pCurrentOutput
,
75 PBOOLEAN pContinueProcessing
,
76 PKEYBOARD_SCAN_STATE pScanState
79 static BOOLEAN bControl
= FALSE
;
80 BOOLEAN bForward
=TRUE
; // should we let keyboard driver process this keystroke
81 BOOLEAN isDown
=!(*pByte
& 0x80);
82 UCHAR ucKey
= *pByte
& 0x7f;
85 // BUG!! should protect with spinlock since bControl is static.
86 DPRINT((0,"PiceKbdIsr(%x,%u)\n",pByte
,isDown
));
87 DPRINT((0,"PiceKbdIsr(1): bControl = %u bForward = %u bEnterNow = %u\n",bControl
,bForward
,bEnterNow
));
96 else if(bControl
==TRUE
&& ucKey
==AsciiToScan(ucBreakKey
)) // CTRL-D
98 // fake a CTRL-D release call
103 else if((ucKey
== 66|| ucKey
== 68) && bStepping
)
116 else if((ucKey
== 66|| ucKey
== 68) && bStepping
)
121 *ContinueProcessing
= bForward
;
126 //***********************************************************************************
127 // PiceSendIoctl - send internal_io_control to the driver
128 // Target - Device Object that receives control request
130 // InputBuffer - Type3Buffer will be pointing here
131 // InputBufferLength - length of inputbuffer
132 //***********************************************************************************
133 NTSTATUS
PiceSendIoctl(PDEVICE_OBJECT Target
, ULONG Ioctl
,
134 PVOID InputBuffer
, ULONG InputBufferLength
)
137 NTSTATUS status
= STATUS_SUCCESS
;
138 IO_STATUS_BLOCK iosb
;
141 KeInitializeEvent(&event
,
146 if (NULL
== (irp
= IoBuildDeviceIoControlRequest(Ioctl
,
155 return STATUS_INSUFFICIENT_RESOURCES
;
158 status
= IoCallDriver(Target
, irp
);
160 if (STATUS_PENDING
== status
) {
162 status
= KeWaitForSingleObject(&event
,
168 assert(STATUS_SUCCESS
== status
);
169 status
= iosb
.Status
;
175 //**************************************************
176 // PatchKeyboardDriver - set keyboard driver hook.
177 // We use interface supported by standard keyboard drivers.
178 //**************************************************
179 BOOLEAN
PatchKeyboardDriver(void)
181 PINTERNAL_I8042_HOOK_KEYBOARD phkData
;
182 UNICODE_STRING DevName
;
183 PDEVICE_OBJECT kbdDevice
= NULL
;
184 PFILE_OBJECT FO
= NULL
;
188 //When we have i8042 driver this should be changed!!!!!!!
189 RtlInitUnicodeString(&DevName
, L
"\\Device\\Keyboard");
191 //Get pointer to keyboard device
192 if( !NT_SUCCESS( IoGetDeviceObjectPointer( &DevName
, FILE_READ_ACCESS
, &FO
, &kbdDevice
) ) )
195 phkData
= ExAllocatePool( PagedPool
, sizeof( INTERNAL_I8042_HOOK_KEYBOARD
) );
196 RtlZeroMemory( phkData
, sizeof( INTERNAL_I8042_HOOK_KEYBOARD
) );
198 phkData
->IsrRoutine
= (PI8042_KEYBOARD_ISR
) PiceKbdIsr
;
199 phkData
->Context
= (PVOID
) NULL
; //DeviceObject;
201 //call keyboard device internal io control to hook keyboard input stream
202 status
= PiceSendIoctl( kbdDevice
, IOCTL_INTERNAL_I8042_HOOK_KEYBOARD
,
203 phkData
, sizeof( INTERNAL_I8042_HOOK_KEYBOARD
) );
206 ObDereferenceObject(FO
);
211 return NT_SUCCESS(status
);
214 void RestoreKeyboardDriver(void)
217 DbgPrint("RestoreKeyboardDriver: Not Implemented yet!!!\n");