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>
44 #include <rosrtl/string.h>
46 ////////////////////////////////////////////////////
50 static PUCHAR pPatchAddress
;
51 static ULONG ulOldOffset
= 0;
52 static ULONG ulKeyPatchFlags
;
54 void (*old_handle_scancode
)(UCHAR
,int);
56 UCHAR ucBreakKey
= 'd'; // key that will break into debugger in combination with CTRL
58 ////////////////////////////////////////////////////
62 //***********************************************************************************
63 // PiceKbdIsr - keyboard isr hook routine.
64 // IsrContext - context that we passed to keyboard driver in internal iocontrol
65 // pCurrentInput, pCurrentOutput - not implemented yet
66 // StatusByte - keyboard status register
67 // pByte - pointer to the byte read from keyboard data port. can be changed.
68 // pContinueProcessing - should keyboard driver continue processing this byte.
69 //***********************************************************************************
72 PKEYBOARD_INPUT_DATA pCurrentInput
,
73 POUTPUT_PACKET pCurrentOutput
,
76 PBOOLEAN pContinueProcessing
,
77 PKEYBOARD_SCAN_STATE pScanState
80 static BOOLEAN bControl
= FALSE
;
81 BOOLEAN bForward
=TRUE
; // should we let keyboard driver process this keystroke
82 BOOLEAN isDown
=!(*pByte
& 0x80);
83 UCHAR ucKey
= *pByte
& 0x7f;
87 // BUG?? should protect with spinlock since bControl is static.
88 DPRINT((0,"PiceKbdIsr(pByte: %x, val: %x,%u)\n",pByte
,*pByte
,isDown
));
89 DPRINT((0,"PiceKbdIsr(1): bControl = %u bForward = %u bEnterNow = %u\n",bControl
,bForward
,bEnterNow
));
93 DPRINT((0,"bControl: %x, ucKey: %x, breakkey: %x\n", bControl
, ucKey
, AsciiToScan(ucBreakKey
)));
99 else if(bControl
==TRUE
&& ucKey
==AsciiToScan(ucBreakKey
)) // CTRL-D
101 // fake a CTRL-D release call
104 // simulate an initial break
108 pushl $returnpoint\n\t \
109 pushl $" STR(REASON_CTRLF
) "\n\t \
110 jmp NewInt31Handler\n\t \
112 *pByte
= 0x1d | 0x80 | 0x7f;
115 else if((ucKey
== 66|| ucKey
== 68) && bStepping
)
128 else if((ucKey
== 66|| ucKey
== 68) && bStepping
)
133 *pContinueProcessing
= bForward
;
134 DPRINT((5,"*pContinueProcessing: %d\n", *pContinueProcessing
));
139 //***********************************************************************************
140 // PiceSendIoctl - send internal_io_control to the driver
141 // Target - Device Object that receives control request
143 // InputBuffer - Type3Buffer will be pointing here
144 // InputBufferLength - length of inputbuffer
145 //***********************************************************************************
146 NTSTATUS
PiceSendIoctl(PDEVICE_OBJECT Target
, ULONG Ioctl
,
147 PVOID InputBuffer
, ULONG InputBufferLength
)
150 NTSTATUS status
= STATUS_SUCCESS
;
151 IO_STATUS_BLOCK iosb
;
154 KeInitializeEvent(&event
,
159 if (NULL
== (irp
= IoBuildDeviceIoControlRequest(Ioctl
,
168 DPRINT((0,"PiceSendIoctl: STATUS_INSUFFICIENT_RESOURCES\n"));
169 return STATUS_INSUFFICIENT_RESOURCES
;
172 status
= IoCallDriver(Target
, irp
);
174 if (STATUS_PENDING
== status
) {
176 status
= KeWaitForSingleObject(&event
,
182 ASSERT(STATUS_SUCCESS
== status
);
183 status
= iosb
.Status
;
185 DPRINT((0,"PiceSendIoctl: status: %d\n",NT_SUCCESS(status
)));
189 //**************************************************
190 // PatchKeyboardDriver - set keyboard driver hook.
191 // We use interface supported by standard keyboard drivers.
192 //**************************************************
193 BOOLEAN
PatchKeyboardDriver(void)
195 PINTERNAL_I8042_HOOK_KEYBOARD phkData
;
196 //When we have i8042 driver this should be changed!!!!!!!
197 UNICODE_STRING DevName
= ROS_STRING_INITIALIZER(L
"\\Device\\Keyboard");
198 PDEVICE_OBJECT kbdDevice
= NULL
;
199 PFILE_OBJECT FO
= NULL
;
204 //Get pointer to keyboard device
205 if( !NT_SUCCESS( status
= IoGetDeviceObjectPointer( &DevName
, FILE_READ_ACCESS
, &FO
, &kbdDevice
) ) )
207 DPRINT((0,"PatchKeyboardDriver: IoGetDeviceObjectPointer status: %x\n", status
));
210 phkData
= ExAllocatePool( PagedPool
, sizeof( INTERNAL_I8042_HOOK_KEYBOARD
) );
211 RtlZeroMemory( phkData
, sizeof( INTERNAL_I8042_HOOK_KEYBOARD
) );
213 phkData
->IsrRoutine
= (PI8042_KEYBOARD_ISR
) PiceKbdIsr
;
214 phkData
->Context
= (PVOID
) NULL
; //DeviceObject;
216 //call keyboard device internal io control to hook keyboard input stream
217 status
= PiceSendIoctl( kbdDevice
, IOCTL_INTERNAL_I8042_HOOK_KEYBOARD
,
218 phkData
, sizeof( INTERNAL_I8042_HOOK_KEYBOARD
) );
219 DPRINT((0,"PatchKeyboardDriver: PiceSendIoctl status: %x\n", status
));
222 ObDereferenceObject(FO
);
227 return NT_SUCCESS(status
);
230 void RestoreKeyboardDriver(void)
233 DbgPrint("RestoreKeyboardDriver: Not Implemented yet!!!\n");