Hi all,
I am trying to get the DEVICE_OBJECT handle using ObOpenObjectByName(). The device object names that is passed to this API is of the form “\Device\device_obj_name”. The code snippet is as follows:
//==============================================//
RtlInitUnicodeString( &ObjName, L"\Device\KSecDD" ); // KSecDD just as an example.
InitializeObjectAttributes( &ObjectAttributes,
&ObjName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL );
ntStatus = ObOpenObjectByName( &ObjectAttributes,
NULL, // POBJECT_TYPE
KernelMode, // KPROCESSOR_MODE
NULL, // PACCESS_STATE
0x80000000, // ACCESS_MASK
NULL, // ParseContext
&hObject ); // Handle
if( STATUS_SUCCESS == ntStatus )
{
// Do some work…
ZwClose( hObject );
}
else
{
DbgPrint( “ObOpenObjectByName failed: 0x%x”, ntStatus );
}
//==============================================//
However, ObOpenObjectByName fails with error 0xC0000024 (STATUS_OBJECT_TYPE_MISMATCH). The same piece of code works fine if I try to get handle of a DRIVER_OBJECT (\Driver\driver_obj_name).
Any idea why ObOpenObjectByName() is failing to get the handle for a DEVICE_OBJECT? Any bug in this code??? It would be great if anybody can help me out on this!
Thanks!!!