From:	SMTP%"roman@softwinter.com" 29-JAN-1998 17:59:41.05
To:	"'Jon Daley'" <jondaley@CMU.EDU>, "ntfsd@atria.com" <ntfsd@atria.com>
CC:	
Subj:	RE: [ntfsd] Keyboard hook

-----BEGIN PGP SIGNED MESSAGE-----

> >Code, I post yesterday will not miss nothing.
> I cannot get your code to work.  It appears to be set up
fundamentally
> differently than mine.  The partial functions that you talked about,
like
> DriverEntry and such must be different than mine.  Could you
possibly send
> me more complete code?

I believe that all other routines you have already!


PDEVICE_OBJECT HookDeviceObject;
PDEVICE_OBJECT kbdDevice;

NTSTATUS AttachFilter( IN PDRIVER_OBJECT DriverObject, WCHAR
*DeviceName, PDEVICE_OBJECT *device, PDEVICE_OBJECT *HookDeviceObject,
DEVICE_TYPE dtype);
NTSTATUS CancelPendings(PDEVICE_OBJECT deviceObject);

int ShiftStatus;
int ControlStatus;
int AltStatus;
int ScanHotKey;




NTSTATUS
DriverEntry(
    IN OUT PDRIVER_OBJECT   DriverObject,
    IN PUNICODE_STRING      RegistryPath
    )
{
    NTSTATUS        ntStatus;
    UNICODE_STRING  paramPath;
	PAGED_CODE(); 
    //
    //
    // Initialize the driver object with this driver's entry points.
    //
	ShiftStatus=0;
	ControlStatus=0;
	AltStatus=0;
	ScanHotKey=1;

    DriverObject->MajorFunction[IRP_MJ_CREATE]			= 
    DriverObject->MajorFunction[IRP_MJ_CLOSE]			= 
    DriverObject->MajorFunction[IRP_MJ_READ]			= 
    DriverObject->MajorFunction[IRP_MJ_WRITE]			= 
	DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS]	=
	DriverObject->MajorFunction[IRP_MJ_CLEANUP]			=
    DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL]	=
DispatchGeneral;


    DriverObject->DriverUnload = EncDiskUnloadDriver;

	HookDeviceObject = kbdDevice = NULL;
	AttachFilter( DriverObject, L"\\Device\\KeyboardClass0",  
			&kbdDevice, &HookDeviceObject, FILE_DEVICE_KEYBOARD);
	if (kbdDevice) CancelPendings(kbdDevice);

    ntStatus = EncDiskInitializeDisk(DriverObject, &paramPath);
    return ntStatus;
}



VOID EncDiskUnloadDriver (IN PDRIVER_OBJECT DriverObject)
{
    PDEVICE_OBJECT deviceObject = FindCommandDevice(DriverObject);

 if ( deviceObject != NULL )
    {
        PENCCOMDISK_EXTENSION      diskExtension =
(PENCCOMDISK_EXTENSION)
						deviceObject->DeviceExtension;

        if (diskExtension != NULL)
        {
			UNICODE_STRING ntLinkName;

			    RtlInitUnicodeString( &ntLinkName, L"\\DosDevices\\"
DEVICE_NAME );
                IoDeleteSymbolicLink( &ntLinkName );
        }
#ifdef SKIPLOGOUT
        SeUnregisterLogonSessionTerminatedRoutine(Logout);
#endif
		if (kbdDevice) IoDetachDevice(kbdDevice);
		if (kbdDevice) CancelPendings(kbdDevice);
		kbdDevice = NULL;
		if (HookDeviceObject) IoDeleteDevice(HookDeviceObject);
		HookDeviceObject = NULL;
        IoDeleteDevice( deviceObject );
    }
}


NTSTATUS DispatchGeneral(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP           Irp )
{
    PENCDISK_EXTENSION  diskExtension=
				(PENCDISK_EXTENSION)DeviceObject->DeviceExtension;

    switch (DeviceObject->DeviceType)
    {
/*
        case FILE_DEVICE_DISK:
                return SecureDispatchGeneral(DeviceObject, Irp );
        case FILE_SECURE_DEVICE_DISK:
                return CommandDispatchGeneral(DeviceObject, Irp );
*/
        case FILE_DEVICE_KEYBOARD:
                return HotKeyDispatchGeneral(DeviceObject, Irp );
    }

    DiskDump(DERRORS, ("Unknow device?\n"));
    Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
    Irp->IoStatus.Information = 0;
    IoCompleteRequest( Irp, IO_NO_INCREMENT );
    
    return Irp->IoStatus.Status;
}






NTSTATUS HotKeyDispatchGeneral(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP           Irp )
{
	PIO_STACK_LOCATION currentIrpStack =
IoGetCurrentIrpStackLocation(Irp);
    PIO_STACK_LOCATION nextIrpStack    =
IoGetNextIrpStackLocation(Irp);
    // Push params down for keyboard class driver.
    *nextIrpStack = *currentIrpStack;
    // Set the completion callback, so we can "frob" the keyboard
data.
    if (nextIrpStack->MajorFunction == IRP_MJ_READ)
		IoSetCompletionRoutine( Irp, HotKeyReadComplete, DeviceObject, TRUE,
FALSE, FALSE );
    // Return the results of the call to the keyboard class driver.
    return IoCallDriver( kbdDevice, Irp );
}


Have a nice day - unless you've made other plans :),

Roman Rutman
roman@softwinter.com

-----BEGIN PGP SIGNATURE-----
Version: PGP for Business Security 5.5

iQCVAwUBNNDGoRFtKtoCwwQZAQH9pwP/d7GToe6THuOwg3e0/U0ENvPQSnsgVCru
aD3AMyDNb5LzkGxSFSlYlokTIcXfUQDoGLQy9JcXbCowk3wCmchISdiRqdt/8SkB
sxBWVzHrEcuuQCN7HpXc9MLiP7h0wB6eUmgu5Hef2wLQloMAszxm6mAZZmyTV5gs
PEn4Ntl75Z0=
=7tQA
-----END PGP SIGNATURE-----

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[ To unsubscribe, send email to ntfsd-request@atria.com with body
UNSUBSCRIBE (the subject is ignored). ]
================== RFC 822 Headers ==================
Return-Path: owner-ntfsd@atria.com
Received: by norlmn.gce.com (UCX X4.2-14, OpenVMS E7.1-1H1 Alpha);
	Thu, 29 Jan 1998 17:56:31 -0500
Received: from gw.atria.com (gw.atria.com [192.88.237.2]) by mercury.mv.net (8.8.8/mem-971025) with SMTP id RAA13750 for <everhart@arisia.gce.com>; Thu, 29 Jan 1998 17:39:06 -0500 (EST)
Received: by gw.atria.com id <PAA10408@gw.atria.com> Thu, 29 Jan 1998 15:12:56 -0500    
Received: from noodle.mentasoftware.com by gw.atria.com id <PAA10400@gw.atria.com> Thu, 29 Jan 1998 15:12:51 -0500    
Received: from test_pc ([207.232.21.21]) by noodle.mentasoftware.com
          (Netscape Messaging Server 3.01)  with SMTP id 280;
          Thu, 29 Jan 1998 22:10:24 +0200
Received: by localhost with Microsoft MAPI; Thu, 29 Jan 1998 22:12:49 +0200
Message-ID: <01BD2D03.09000530.roman@softwinter.com>
From: "Roman Rutman (sw)" <roman@softwinter.com>
Reply-To: "roman@softwinter.com" <roman@softwinter.com>
To: "'Jon Daley'" <jondaley@CMU.EDU>, "ntfsd@atria.com" <ntfsd@atria.com>
Subject: RE: [ntfsd] Keyboard hook
Date: Thu, 29 Jan 1998 22:12:48 +0200
Organization: Soft Winter
X-Mailer: Microsoft Internet E-mail/MAPI - 8.0.0.4211
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sender: owner-ntfsd@atria.com
Precedence: bulk
X-Majordomo-Taboo: ntfsd
