Désoler j'avais pas compris.


Alors voila je te dépose le code complet que tu puisse le compiler.
//MAKEFILE
#
# DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source
# file to this component. This file merely indirects to the real make file
# that is shared by all the driver components of the Windows NT DDK
#
!INCLUDE $(NTMAKEENV)\makefile.def
//SOURCESTARGETNAME=TEST1
TARGETPATH=OBJ
TARGETTYPE=DRIVER
INCLUDES=..\..\inc
TARGETLIBS=$(DDK_LIB_PATH)\user32.lib
TARGETLIBS=$(DDK_LIB_PATH)\ndis.lib
SOURCES=test1.c
//test1.htypedef struct _DEVICE_EXTENSION
{
PDEVICE_OBJECT pKeyboardDevice; //pointer to next keyboard device on device stack
}DEVICE_EXTENSION, *PDEVICE_EXTENSION;
//Fonction methode
NTSTATUS DispatchRead(IN PDEVICE_OBJECT pDeviceObject, IN PIRP pIrp);
NTSTATUS OnReadCompletion(IN PDEVICE_OBJECT pDeviceObject, IN PIRP pIrp, IN PVOID Context);
NTSTATUS DispatchPassDown(IN PDEVICE_OBJECT pDeviceObject, IN PIRP pIrp);
VOID OnUnload( IN PDRIVER_OBJECT DriverObject );
VOID S_Switch();
//test1.c#include "ntddk.h"
#include "ntddkbd.h"
#include "winuser.h"
#include "test1.h"
int numPendingIrps = 0;
BOOLEAN DeskS = 1;
VOID OnUnload( IN PDRIVER_OBJECT pDriverObject )
{
PDEVICE_EXTENSION pKeyboardDeviceExtension;
KTIMER kTimer;
LARGE_INTEGER timeout;
DbgPrint("OnUnload");
pKeyboardDeviceExtension = (PDEVICE_EXTENSION)pDriverObject->DeviceObject->DeviceExtension;
IoDetachDevice(pKeyboardDeviceExtension->pKeyboardDevice);
DbgPrint("Keyboard hook detached from device...\nWaiting tagged irp die");
timeout.QuadPart = 1000000; //.1 s
KeInitializeTimer(&kTimer);
while(numPendingIrps > 0)
{
//Set the timer
KeSetTimer(&kTimer,timeout,NULL);
KeWaitForSingleObject(&kTimer,Executive,KernelMode,FALSE ,NULL);
}
IoDeleteDevice(pDriverObject->DeviceObject);
DbgPrint("Tagged IRPs dead...Terminating...\n");
}
NTSTATUS DispatchPassDown(IN PDEVICE_OBJECT pDeviceObject, IN PIRP pIrp)
{
DbgPrint("DispatchPassDown");
IoSkipCurrentIrpStackLocation(pIrp);
return IoCallDriver(((PDEVICE_EXTENSION) pDeviceObject->DeviceExtension)->pKeyboardDevice ,pIrp);
}
NTSTATUS OnReadCompletion(IN PDEVICE_OBJECT pDeviceObject, IN PIRP pIrp, IN PVOID Context)
{
PDEVICE_EXTENSION pKeyboardDeviceExtension;
int i;
PKEYBOARD_INPUT_DATA keys;
int numKeys;
DbgPrint("OnReadCompletion");
pKeyboardDeviceExtension = (PDEVICE_EXTENSION)pDeviceObject->DeviceExtension;
if(pIrp->IoStatus.Status == STATUS_SUCCESS)
{
keys = (PKEYBOARD_INPUT_DATA)pIrp->AssociatedIrp.SystemBuffer;
numKeys = pIrp->IoStatus.Information / sizeof(KEYBOARD_INPUT_DATA);
for(i = 0; i < numKeys; i++)
{
if(keys[i].Flags == KEY_BREAK)
{
DbgPrint("%s\n","Key Up");
if(keys[i].MakeCode == 0x38)
{
DbgPrint("LAlt Release");
S_Switch();
}
}
}
}
if(pIrp->PendingReturned)
IoMarkIrpPending(pIrp);
numPendingIrps--;
return pIrp->IoStatus.Status;
}
NTSTATUS DispatchRead(IN PDEVICE_OBJECT pDeviceObject, IN PIRP pIrp)
{
PIO_STACK_LOCATION currentIrpStack;
PIO_STACK_LOCATION nextIrpStack;
DbgPrint("DispatchRead");
currentIrpStack = IoGetCurrentIrpStackLocation(pIrp);
nextIrpStack = IoGetNextIrpStackLocation(pIrp);
*nextIrpStack = *currentIrpStack;
IoSetCompletionRoutine(pIrp, OnReadCompletion, pDeviceObject, TRUE, TRUE, TRUE);
numPendingIrps++;
return IoCallDriver(((PDEVICE_EXTENSION) pDeviceObject->DeviceExtension)->pKeyboardDevice ,pIrp);
}
NTSTATUS DriverEntry( IN PDRIVER_OBJECT pDriverObject, IN PUNICODE_STRING RegistryPath )
{
int i;
PDEVICE_OBJECT pKeyboardDeviceObject;
NTSTATUS status;
PDEVICE_EXTENSION pKeyboardDeviceExtension;
CCHAR ntNameBuffer[64] = "\\Device\\KeyboardClass0";
STRING ntNameString;
UNICODE_STRING uKeyboardDeviceName;
DbgPrint("Driver Loaded");
pDriverObject->DriverUnload = OnUnload;
for( i = 0 ; i < IRP_MJ_MAXIMUM_FUNCTION; i++ )
pDriverObject->MajorFunction[i] = DispatchPassDown;
pDriverObject->MajorFunction[IRP_MJ_READ] = DispatchRead;
status = IoCreateDevice( pDriverObject, sizeof(DEVICE_EXTENSION), NULL, FILE_DEVICE_KEYBOARD, 0, TRUE, &pKeyboardDeviceObject);
if(!NT_SUCCESS(status))
return status;
pKeyboardDeviceObject->Flags = pKeyboardDeviceObject->Flags | (DO_BUFFERED_IO | DO_POWER_PAGABLE);
pKeyboardDeviceObject->Flags = pKeyboardDeviceObject->Flags & ~DO_DEVICE_INITIALIZING;
RtlZeroMemory(pKeyboardDeviceObject->DeviceExtension, sizeof(DEVICE_EXTENSION));
pKeyboardDeviceExtension = (PDEVICE_EXTENSION)pKeyboardDeviceObject->DeviceExtension;
RtlInitAnsiString(&ntNameString, ntNameBuffer);
RtlAnsiStringToUnicodeString(&uKeyboardDeviceName, &ntNameString, TRUE);
IoAttachDevice(pKeyboardDeviceObject, &uKeyboardDeviceName, &pKeyboardDeviceExtension->pKeyboardDevice);
RtlFreeUnicodeString(&uKeyboardDeviceName);
DbgPrint("Clavier Hooker");
return STATUS_SUCCESS;
}
VOID S_Switch()
{
HWINSTA proc_ws;
char desk_s[15];
char desk_default[15];
HDESK hdesk_s;
HDESK hdesk_default;
DbgPrint("Switch Deskstop");
proc_ws = GetProcessWindowStation();
if(DeskS == 0) //si on est sur le bureau par defaut
{
sprintf(desk_s, "desk");
hdesk_s = OpenDesktop(desk_s, DF_ALLOWOTHERACCOUNTHOOK, FALSE, GENERIC_ALL);
SwitchDesktop(hdesk_s);
CloseDesktop(hdesk_s);
desk_s = 1;
}
else if(DeskS == 1)
{
sprintf(desk_default, "Default");
hdesk_default = OpenDesktop(desk_default, DF_ALLOWOTHERACCOUNTHOOK, FALSE, GENERIC_ALL);
SwitchDesktop(hdesk_default);
CloseDesktop(hdesk_default);
}
else
DbgPrint("Erreur dans le switch de desktop...Veuillez redemarrer le driver....");
}