- Talking to HID minidriver from usermode
- Posted by Kim Povlsen on April 4th, 2005
Hi.
I'm trying to talk to a HID minidriver (keyboard collection) from a usermode
program.
I know this is not practical, but that it _can_ be done.
HIDCLASS stops any normal attempt on doing a IRP_MJ_CREATE from CreateFile
in usermode.
So what I've done (which I know is kinda illegal) is to create an extra
DeviceObject in my AddDevice routine, which I register with a symbolic link.
I then hook & chain IRP_MJ_CREATE and IRP_MJ_CLOSE, for my minidriver
DriverObject.
It hooks alright when initializing the driver, but I still get a "File not
found", when I try to open the object with CreateFile from usermode.
Any ideas? Or maybe other ways to talk to hid minidrivers with keyboard
collection?
Thanks in advance!
/Kim
- Posted by Ray Trent on April 5th, 2005
That's pretty much the standard way to talk to a keyboard/mouse filter
driver, so I'd say it's ok, but I suppose it depends on exactly what
you're doing :-).
Kim Povlsen wrote:
--
.../ray\..
- Posted by W!NTER$ on April 5th, 2005
I met the same problem with yours while I was doing a virtual audio
driver.
If I try to open the driver in user mode, it always failed that it said
'File not found'. Then I used some tricks to distinguish the opens
performed by my application.
If IrpStack->FileObject->FileName.Buffer is NULL, I assume that this
open is performed by my application. Yes, it's very urgly. But it works.
- Posted by Kim Povlsen on April 5th, 2005
Well I know how to distinguish my application from others. The problem is,
that I never get down to my hooked routine in the driver.
I create the deviceobject like this:
RtlInitUnicodeString(&targetname, L"\\Device\\fakehid");
RtlInitUnicodeString(&linkname, L"\\DosDevices\\kimpix");
ntStatus = IoCreateDevice(DriverObject,
sizeof(DEVICE_EXTENSION),
&targetname,
FILE_DEVICE_UNKNOWN,
FILE_DEVICE_SECURE_OPEN,
FALSE,
&deviceObject);
and then create the symbolic link:
ntStatus = IoCreateSymbolicLink(&linkname, &targetname);
This works alright.
I then chain & hook when HIDCLASS asks for the
IOCTL_HID_GET_REPORT_DESCRIPTOR (just so I don't hook too early).
The pointers to the IRP_MJ_CREATE and CLOSE changes just fine.
(My hooked routines gets called a few times while the minidriver is
installing. So they work alright).
My CreateFile then looks like this:
HANDLE Handle = CreateFile("\\\\.\\kimpix",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
But nomather what I try, I get "File not found" back from GetLastError.
(And as I wrote above: my hooked routines doesn't get called, when I call
CreateFile).
Any ideas what could be wrong?
Thanks in advance!
/Kim P.
"W!NTER$" <winters_z@163.com> skrev i en meddelelse
news:1112666145.261947.98160@o13g2000cwo.googlegro ups.com...
- Posted by Doron Holan [MS] on April 5th, 2005
did you clear the DO_DEVICE_INITIALIZING bit from deviceObject->Flags?
d
--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
"Kim Povlsen" <kim@kimpix.dk> wrote in message
news:u$ho%233bOFHA.1172@TK2MSFTNGP12.phx.gbl...
- Posted by Ray Trent on April 5th, 2005
Perhaps I'm not understanding what you're saying here. What do you mean
by "hooked routine"? The IRP_MJ_CREATE for a device object you create
this way should call your own driver's dispatch routine, not anything
related to the HID stack...
In fact, I can't think of any reason you should need to hook the HID
stack's dispatch routines. It sounds like a really bad idea.
Kim Povlsen wrote:
--
.../ray\..
- Posted by Kim Povlsen on April 5th, 2005
Thanks Doron. Works now ;-)
Ray: It's a hid minidriver, so HIDCLASS will receive i.e IRP_MJ_CREATE for
this minidrivers driverobject.
So I need to hook onto this IRP. So in case I get a IRP from my usermode
program, I process it, if it's from somewhere else (most probably HIDCLASS),
then I'll chain it to the original Dispatch-routine, that HIDCLASS uses.
This method is only needed for the generic desktop devices(keyboard, mouse,
joystick).
I don't know if that made it more clear about what I'm doing ;-)
Anyway.. it's working now.
Thanks for replying!
/Kim
"Ray Trent" <ratrent@nospam.nospam> skrev i en meddelelse
news:uCwtq8fOFHA.1396@TK2MSFTNGP10.phx.gbl...
- Posted by Doron Holan [MS] on April 6th, 2005
the typical way that this is done is to create a 2ndary top level collection
and to expose each setting as a feature report. you then see these changes
in your miniport w/out any hooking.
d
--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
"Kim Povlsen" <kim@kimpix.dk> wrote in message
news:%23YU2IigOFHA.508@TK2MSFTNGP12.phx.gbl...
- Posted by DaveB on June 2nd, 2005
I have a similar problem with device name. When one uses \\.\name-0 in a
createfile, where does Windows really look for that name? Can I see it with
regedt32? I updated my code to enumerate my name with a number, but not just
tacking a char on the end of the string, and now I can't createfile to the
old name.
"Kim Povlsen" wrote:
- Posted by Maxim S. Shatskih on June 3rd, 2005
Windows looks as \??\name-0
--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com
"DaveB" <DaveB@discussions.microsoft.com> wrote in message
news:4FCD6ABA-33D2-473F-9B11-A9FB5AD1CFD1@microsoft.com...