ReactOS  0.4.14-dev-614-gbfd8a84
patch.c File Reference
#include "remods.h"
#include "precomp.h"
#include <ntddkbd.h>
#include <ntdd8042.h>
#include <rosrtl/string.h>
Include dependency graph for patch.c:

Go to the source code of this file.

Functions

BOOLEAN PiceKbdIsr (PVOID IsrContext, PKEYBOARD_INPUT_DATA pCurrentInput, POUTPUT_PACKET pCurrentOutput, UCHAR StatusByte, PUCHAR pByte, PBOOLEAN pContinueProcessing, PKEYBOARD_SCAN_STATE pScanState)
 
NTSTATUS PiceSendIoctl (PDEVICE_OBJECT Target, ULONG Ioctl, PVOID InputBuffer, ULONG InputBufferLength)
 
BOOLEAN PatchKeyboardDriver (void)
 
void RestoreKeyboardDriver (void)
 

Variables

static PUCHAR pPatchAddress
 
static ULONG ulOldOffset = 0
 
static ULONG ulKeyPatchFlags
 
void(* old_handle_scancode )(UCHAR, int)
 
char tempPatch [256]
 
UCHAR ucBreakKey = 'd'
 

Function Documentation

◆ PatchKeyboardDriver()

BOOLEAN PatchKeyboardDriver ( void  )

Definition at line 193 of file patch.c.

194 {
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;
201 
202  ENTER_FUNC();
203 
204  //Get pointer to keyboard device
205  if( !NT_SUCCESS( status = IoGetDeviceObjectPointer( &DevName, FILE_READ_ACCESS, &FO, &kbdDevice ) ) )
206  {
207  DPRINT((0,"PatchKeyboardDriver: IoGetDeviceObjectPointer status: %x\n", status));
208  return FALSE;
209  }
210  phkData = ExAllocatePool( PagedPool, sizeof( INTERNAL_I8042_HOOK_KEYBOARD ) );
211  RtlZeroMemory( phkData, sizeof( INTERNAL_I8042_HOOK_KEYBOARD ) );
212 
214  phkData->Context = (PVOID) NULL; //DeviceObject;
215 
216  //call keyboard device internal io control to hook keyboard input stream
218  phkData, sizeof( INTERNAL_I8042_HOOK_KEYBOARD ) );
219  DPRINT((0,"PatchKeyboardDriver: PiceSendIoctl status: %x\n", status));
220 
221 
223  ExFreePool(phkData);
224 
225  LEAVE_FUNC();
226 
227  return NT_SUCCESS(status);
228 }
#define FILE_READ_ACCESS
Definition: nt_native.h:610
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS PiceSendIoctl(PDEVICE_OBJECT Target, ULONG Ioctl, PVOID InputBuffer, ULONG InputBufferLength)
Definition: patch.c:146
#define LEAVE_FUNC()
Definition: debug.h:43
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1435
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
BOOLEAN PiceKbdIsr(PVOID IsrContext, PKEYBOARD_INPUT_DATA pCurrentInput, POUTPUT_PACKET pCurrentOutput, UCHAR StatusByte, PUCHAR pByte, PBOOLEAN pContinueProcessing, PKEYBOARD_SCAN_STATE pScanState)
Definition: patch.c:70
OUT PI8042_KEYBOARD_ISR IsrRoutine
Definition: ntdd8042.h:179
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
void * PVOID
Definition: retypes.h:9
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
* PFILE_OBJECT
Definition: iotypes.h:1955
static const WCHAR L[]
Definition: oid.c:1250
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define IOCTL_INTERNAL_I8042_HOOK_KEYBOARD
Definition: ntdd8042.h:36
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ENTER_FUNC()
Definition: debug.h:42
BOOLEAN(NTAPI * PI8042_KEYBOARD_ISR)(PVOID IsrContext, PKEYBOARD_INPUT_DATA CurrentInput, POUTPUT_PACKET CurrentOutput, UCHAR StatusByte, PUCHAR Byte, PBOOLEAN ContinueProcessing, PKEYBOARD_SCAN_STATE ScanState)
Definition: ntdd8042.h:167
static SERVICE_STATUS status
Definition: service.c:31
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
Definition: ps.c:97

Referenced by InitPICE().

◆ PiceKbdIsr()

BOOLEAN PiceKbdIsr ( PVOID  IsrContext,
PKEYBOARD_INPUT_DATA  pCurrentInput,
POUTPUT_PACKET  pCurrentOutput,
UCHAR  StatusByte,
PUCHAR  pByte,
PBOOLEAN  pContinueProcessing,
PKEYBOARD_SCAN_STATE  pScanState 
)

Definition at line 70 of file patch.c.

79 {
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;
84 
85  ENTER_FUNC();
86 
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));
90 
91  if(isDown)
92  {
93  DPRINT((0,"bControl: %x, ucKey: %x, breakkey: %x\n", bControl, ucKey, AsciiToScan(ucBreakKey)));
94  // CTRL pressed
95  if(ucKey==0x1d)
96  {
97  bControl=TRUE;
98  }
99  else if(bControl==TRUE && ucKey==AsciiToScan(ucBreakKey)) // CTRL-D
100  {
101  // fake a CTRL-D release call
102  bEnterNow=TRUE;
103  bControl=FALSE;
104  // simulate an initial break
105  __asm__("\n\t \
106  pushfl\n\t \
107  pushl %cs\n\t \
108  pushl $returnpoint\n\t \
109  pushl $" STR(REASON_CTRLF) "\n\t \
110  jmp NewInt31Handler\n\t \
111  returnpoint:");
112  *pByte = 0x1d | 0x80 | 0x7f;
113  bForward=TRUE;
114  }
115  else if((ucKey == 66|| ucKey == 68) && bStepping)
116  {
117  bForward=FALSE;
118  }
119 
120  }
121  else
122  {
123  // CTRL released
124  if(ucKey==0x1d)
125  {
126  bControl=FALSE;
127  }
128  else if((ucKey == 66|| ucKey == 68) && bStepping)
129  {
130  bForward=FALSE;
131  }
132  }
133  *pContinueProcessing = bForward;
134  DPRINT((5,"*pContinueProcessing: %d\n", *pContinueProcessing));
135  LEAVE_FUNC();
136  return TRUE;
137 }
volatile BOOLEAN bEnterNow
Definition: shell.c:75
#define TRUE
Definition: types.h:120
#define LEAVE_FUNC()
Definition: debug.h:43
BOOLEAN bStepping
Definition: parse.c:63
#define STR(x)
Definition: utils.h:34
__asm__("\t.globl GetPhys\n" "GetPhys:\t\n" "mflr 0\n\t" "stwu 0,-16(1)\n\t" "mfmsr 5\n\t" "andi. 6,5,0xffef\n\t" "mtmsr 6\n\t" "isync\n\t" "sync\n\t" "lwz 3,0(3)\n\t" "mtmsr 5\n\t" "isync\n\t" "sync\n\t" "lwz 0,0(1)\n\t" "addi 1,1,16\n\t" "mtlr 0\n\t" "blr")
UCHAR ucBreakKey
Definition: patch.c:56
unsigned char BOOLEAN
void DPRINT(...)
Definition: polytest.cpp:61
volatile BOOLEAN bControl
Definition: shell.c:70
UCHAR AsciiToScan(UCHAR s)
Definition: utils.c:2113
unsigned char UCHAR
Definition: xmlstorage.h:181
#define ENTER_FUNC()
Definition: debug.h:42
#define REASON_CTRLF
Definition: shell.h:73

Referenced by PatchKeyboardDriver().

◆ PiceSendIoctl()

NTSTATUS PiceSendIoctl ( PDEVICE_OBJECT  Target,
ULONG  Ioctl,
PVOID  InputBuffer,
ULONG  InputBufferLength 
)

Definition at line 146 of file patch.c.

148 {
149  KEVENT event;
152  PIRP irp;
153 
156  FALSE
157  );
158 
159  if (NULL == (irp = IoBuildDeviceIoControlRequest(Ioctl,
160  Target,
161  InputBuffer,
163  0,
164  0,
165  TRUE,
166  &event,
167  &iosb))) {
168  DPRINT((0,"PiceSendIoctl: STATUS_INSUFFICIENT_RESOURCES\n"));
170  }
171 
172  status = IoCallDriver(Target, irp);
173 
174  if (STATUS_PENDING == status) {
175 
177  Executive,
178  KernelMode,
179  FALSE,
180  NULL);
181 
183  status = iosb.Status;
184  }
185  DPRINT((0,"PiceSendIoctl: status: %d\n",NT_SUCCESS(status)));
186  return status;
187 }
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
CHAR InputBuffer[80]
Definition: conmgr.c:33
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
_Must_inspect_result_ typedef _In_ ULONG _In_ BOOLEAN Target
Definition: iotypes.h:1068
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
struct _cl_event * event
Definition: glext.h:7739
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG InputBufferLength
Definition: fltkernel.h:1372
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by PatchKeyboardDriver().

◆ RestoreKeyboardDriver()

void RestoreKeyboardDriver ( void  )

Definition at line 230 of file patch.c.

231 {
232  ENTER_FUNC();
233  DbgPrint("RestoreKeyboardDriver: Not Implemented yet!!!\n");
234  LEAVE_FUNC();
235 }
#define DbgPrint
Definition: loader.c:25
#define LEAVE_FUNC()
Definition: debug.h:43
#define ENTER_FUNC()
Definition: debug.h:42

Referenced by CleanUpPICE().

Variable Documentation

◆ old_handle_scancode

void(* old_handle_scancode) (UCHAR, int)

Definition at line 54 of file patch.c.

◆ pPatchAddress

PUCHAR pPatchAddress
static

Definition at line 50 of file patch.c.

◆ tempPatch

char tempPatch[256]

Definition at line 55 of file patch.c.

◆ ucBreakKey

UCHAR ucBreakKey = 'd'

Definition at line 56 of file patch.c.

Referenced by COMMAND_PROTOTYPE(), and PiceKbdIsr().

◆ ulKeyPatchFlags

ULONG ulKeyPatchFlags
static

Definition at line 52 of file patch.c.

◆ ulOldOffset

ULONG ulOldOffset = 0
static

Definition at line 51 of file patch.c.