This is a multi-part message in MIME format.
------=_NextPart_000_0043_01C7BEEE.4FAA4040
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi Everybody,
I write usb camera filter driver, i see toaster filter example in DDK =
and make the same. but i have a problem when use mode application access =
filter driver by IOCL.
Following is kernel mode code is create object control
NTSTATUS
FilterCreateControlObject(
IN PDEVICE_OBJECT DeviceObject
)
{
UNICODE_STRING ntDeviceName;
UNICODE_STRING symbolicLinkName;
PCONTROL_DEVICE_EXTENSION deviceExtension;
NTSTATUS status =3D STATUS_UNSUCCESSFUL;
UNICODE_STRING sddlString;
//PAGED_CODE();
//
// Using unsafe function so that the IRQL remains at PASSIVE_LEVEL.
// IoCreateDeviceSecure & IoCreateSymbolocLink must be called at
// PASSIVE_LEVEL.
//
ExAcquireFastMutexUnsafe(&ControlMutex);
//
// If this is a first instance of the device, then create a =
controlobject.
// and register dispatch points to handle ioctls.
//
if(1 =3D=3D ++InstanceCount)
{
DbgPrint("Start Create Object\n");
//
// Initialize the unicode strings
//
RtlInitUnicodeString(&ntDeviceName, NTDEVICE_NAME_STRING);
RtlInitUnicodeString(&symbolicLinkName, SYMBOLIC_NAME_STRING);
//
// Initialize a security descriptor string. Refer to SDDL docs in =
theSDK
// for more info.
//
RtlInitUnicodeString(&sddlString, L"D:P(A;;GA;;;SY)(A;;GA;;;BA)");
//
// Create a named deviceobject so that applications or drivers
// can directly talk to us without going through the entire stack.
// This call could fail if there are not enough resources or
// another deviceobject of same name exits (name collision).
// Let us use the new IoCreateDeviceSecure and specify a security
// descriptor (SD) that allows only System and Admin groups to access =
the
// control device. Let us also specify a unique guid to allow =
administrators
// to change the SD if he desires to do so without changing the =
driver.
// The SD will be stored in
// HKLM\SYSTEM\CCSet\Control\Class\<GUID>\Properties\Security
// An admin can overide the SD specified in the below call by =
modifying
// the registry.
//=20
status =3D IoCreateDeviceSecure(DeviceObject->DriverObject,
sizeof(CONTROL_DEVICE_EXTENSION),
&ntDeviceName,
FILE_DEVICE_UNKNOWN,
FILE_DEVICE_SECURE_OPEN,
FALSE,
&sddlString,=20
(LPCGUID)&GUID_SD_FILTER_CONTROL_OBJECT,
&ControlDeviceObject
);
if(NT_SUCCESS(status)) {
=20
ControlDeviceObject->Flags |=3D DO_BUFFERED_IO;
status =3D IoCreateSymbolicLink(&symbolicLinkName, &ntDeviceName);
if(!NT_SUCCESS(status)) {
IoDeleteDevice(ControlDeviceObject);
DebugPrint(("IoCreateSymbolicLink failed %x\n", status));
goto End;
}
deviceExtension =3D ControlDeviceObject->DeviceExtension;
deviceExtension->Type =3D DEVICE_TYPE_CDO;
deviceExtension->ControlData =3D NULL;
deviceExtension->Deleted =3D FALSE;
ControlDeviceObject->Flags &=3D ~DO_DEVICE_INITIALIZING;
}else {
DebugPrint(("IoCreateDevice failed %x\n", status));
}
=20
DbgPrint("End Create Object\n");
}
End:
=20
ExReleaseFastMutexUnsafe(&ControlMutex);
return status;
}
Following is user mode application to access filter driver by IOCL:
HANDLE hdevice =3D CreateFile(TEXT("\\\\.\\UsbcameraFilter"), =
GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hdevice =3D=3D INVALID_HANDLE_VALUE)
{
printf("Unable to open UsbcameraFilter device - error %d\n", =
GetLastError());
return 1;
}
When i run debug user mode application it display error in WinDbg is:
Access violation - code c0000005 (!!! second chance !!!)
nt!IofCallDriver+0x24:
804ec046 8b7108 mov esi,[ecx+0x8]
I don't know why, Everyone have experience about write usb camera filter =
driver pls help me, thanks very alot.
David,
------=_NextPart_000_0043_01C7BEEE.4FAA4040
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2180" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Hi Everybody,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I write usb camera filter driver, i see =
toaster=20
filter example in DDK and make the same. but i have a problem when use =
mode=20
application access filter driver by IOCL.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Following is kernel mode code is =
create object=20
control</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial=20
size=3D2>NTSTATUS<BR>FilterCreateControlObject(<BR> &nbs=
p; =20
IN PDEVICE_OBJECT =
DeviceObject<BR> =20
)<BR>{<BR> UNICODE_STRING ntDeviceName;<BR>&n=
bsp;UNICODE_STRING symbolicLinkName;<BR> PCON=
TROL_DEVICE_EXTENSION deviceExtension;<BR> NTSTATUS =
status=20
=3D=20
STATUS_UNSUCCESSFUL;<BR> UNICODE_STRING sddlS=
tring;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> //PAGED_CODE();</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> //<BR> // Using unsafe =
function so that=20
the IRQL remains at PASSIVE_LEVEL.<BR> // IoCreateDeviceSecure =
&=20
IoCreateSymbolocLink must be called at<BR> //=20
PASSIVE_LEVEL.<BR> //<BR> ExAcquireFastMutexUnsafe(&Control=
Mutex);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> //<BR> // If this is a first =
instance of=20
the device, then create a controlobject.<BR> // and register =
dispatch=20
points to handle ioctls.<BR> //<BR> if(1 =3D=3D=20
++InstanceCount)<BR> {<BR> DbgPrint("Start Create=20
Object\n");<BR> //<BR> // Initialize the unicode=20
strings<BR> //<BR> RtlInitUnicodeString(&ntDevi=
ceName,=20
NTDEVICE_NAME_STRING);<BR> RtlInitUnicodeString(&symbolicL=
inkName,=20
SYMBOLIC_NAME_STRING);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> //<BR> // =
Initialize a=20
security descriptor string. Refer to SDDL docs in =
theSDK<BR> // for=20
more=20
info.<BR> //<BR> RtlInitUnicodeString(&sddlStri=
ng,=20
L"D:P(A;;GA;;;SY)(A;;GA;;;BA)");</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> //<BR> // Create =
a named=20
deviceobject so that applications or drivers<BR> // can =
directly talk=20
to us without going through the entire stack.<BR> // This =
call could=20
fail if there are not enough resources or<BR> // another =
deviceobject=20
of same name exits (name collision).<BR> // Let us use the =
new=20
IoCreateDeviceSecure and specify a security<BR> // descriptor =
(SD)=20
that allows only System and Admin groups to access the<BR> // =
control=20
device. Let us also specify a unique guid to allow=20
administrators<BR> // to change the SD if he desires to do so =
without=20
changing the driver.<BR> // The SD will be stored=20
in<BR> //=20
HKLM\SYSTEM\CCSet\Control\Class\<GUID>\Properties\Security<BR> =
; //=20
An admin can overide the SD specified in the below call by=20
modifying<BR> // the registry.<BR> // =
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> status =3D=20
IoCreateDeviceSecure(DeviceObject->DriverObject,<BR> =
sizeof(CONTROL_DEVICE_EXTENSION),<BR>=
&ntDeviceName,<=
BR> FILE_DEVICE_UNKN=
OWN,<BR> FILE_DEVICE=
_SECURE_OPEN,<BR> FA=
LSE,<BR> &sddlSt=
ring,=20
<BR> (LPCGUID)&G=
UID_SD_FILTER_CONTROL_OBJECT,<BR> &nbs=
p; &ControlDeviceObject<BR> &=
nbsp; );</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2> if(NT_SUCCESS(status))=20
{<BR> <BR> ControlDeviceObj=
ect->Flags=20
|=3D DO_BUFFERED_IO;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> status =3D=20
IoCreateSymbolicLink(&symbolicLinkName, =
&ntDeviceName);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2> if(!NT_SUCCESS(status))=20
{<BR> IoDeleteDevice(ControlDeviceObject);<B=
R> DebugPrint(("IoCreateSymbolicLink=20
failed %x\n", status));<BR> goto=20
End;<BR> }</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> deviceExtension =
=3D=20
ControlDeviceObject->DeviceExtension;<BR> devic=
eExtension->Type=20
=3D =
DEVICE_TYPE_CDO;<BR> deviceExtension->ControlDa=
ta =3D=20
NULL;<BR> deviceExtension->Deleted =3D=20
FALSE;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial=20
size=3D2> ControlDeviceObject->Flags &=3D=20
~DO_DEVICE_INITIALIZING;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> }else=20
{<BR> DebugPrint(("IoCreateDevice failed %x\n",=20
status));<BR> }<BR> </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> DbgPrint("End Create=20
Object\n");<BR> }</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial=20
size=3D2>End:<BR> <BR> ExReleaseFastMutexUnsafe(&ControlMut=
ex);<BR> return=20
status;<BR>}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Following is user mode application to =
access filter=20
driver by IOCL:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>HANDLE hdevice =3D =
CreateFile(TEXT("</FONT><A><FONT=20
face=3DArial size=3D2>\\\\.\\UsbcameraFilter</FONT></A><FONT =
face=3DArial size=3D2>"),=20
GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);<BR> if (hdevice =
=3D=3D=20
INVALID_HANDLE_VALUE)<BR> {<BR> printf("Unable to open=20
UsbcameraFilter device - error %d\n", =
GetLastError());<BR> return=20
1;<BR> }</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>When i run debug user mode application =
it display=20
error in WinDbg is:</FONT></DIV>
<DIV>
<P><FONT face=3DArial size=3D2>Access violation - code c0000005 (!!! =
second chance=20
!!!)</FONT></P>
<P><FONT face=3DArial size=3D2>nt!IofCallDriver+0x24:</FONT></P>
<P><FONT face=3DArial size=3D2>804ec046 8b7108 mov =
esi,[ecx+0x8]</FONT></P>
<P><FONT face=3DArial size=3D2>I don't know why, Everyone =
have experience about=20
write usb camera filter driver pls help me, thanks very alot.</FONT></P>
<P><FONT face=3DArial size=3D2>David,</FONT></P></DIV></BODY></HTML>
------=_NextPart_000_0043_01C7BEEE.4FAA4040--