All,
I’m trying to use ObQueryNameString to simply print out the device name for the driver object above me. I will see all the trace statements then the crash. Sometimes I only get through one of the trace statements.
I’m mostly ignoring the status’ since this is debug only right now. I can see that the strings are equal so I know the name is being returned.
One thing I had tried was to allocate the buffer for the Unicode string in OBJECT_NAME_INFO, this has no effect and the documentation for this function states the buffer will contain the pointer to the string which tells me I don’t need to allocate the buffer since there is no copy involved.
Code:
EXTERN_C NTSTATUS NTAPI
ObQueryNameString(
PVOID Object,
POBJECT_NAME_INFORMATION ObjectNameInfo,
ULONG Length,
PULONG ReturnLength);
static NTSTATUS
DeviceAttachToStack(
IN PDEVICE_OBJECT pDevObj
)
{
PAGED_CODE();
NTSTATUS status = STATUS_UNSUCCESSFUL;
ULONG ReturnLength;
ULONG Length;
OBJECT_NAME_INFORMATION objName = {0};
PWCHAR ptemp = L"\Device\Harddisk0\DR0";
ObQueryNameString((PVOID)pDevObj, NULL, NULL, &ReturnLength);
Length = ReturnLength;
status = ObQueryNameString((PVOID)pDevObj,
&objName,
Length,
&ReturnLength);
BOOLEAN equal = MyUtilIsStringEqual(objName.Name.Buffer, ptemp);
MyTrace(TRACE_LEVEL_WARNING, DRV_DBG_DEVICE_SUPPORT,
“%s: Strings %wZ and %ws are equal: %d\n”, FUNCTION,
&objName.Name, ptemp, equal);
MyTrace(TRACE_LEVEL_INFORMATION, DRV_DBG_DEVICE_SUPPORT,
“%s: Attached Device Name %wZ for device %p w/status 0x%x.\n”,
FUNCTION, &objName.Name, pDevObj, status);
return status;
In this case, I only see the first trace statement:
DeviceAttachToStack: Strings \Device\Harddisk0\DR0 and \Device\Harddisk0\DR0 are equal: 1
Then a bugcheck …
Unknown bugcheck code (0)
Unknown bugcheck description
Arguments:
Arg1: 0000000000000000
Arg2: 0000000000000000
Arg3: 0000000000000000
Arg4: 0000000000000000
Debugging Details:
PROCESS_NAME: System
FAULTING_IP:
mydriver!DeviceAttachToStack+13a [mydriver.cpp @ 155]
fffff880`01badada 488b4018 mov rax,qword ptr [rax+18h]
ERROR_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%08lx referenced memory at 0x%08lx. The memory could not be %s.
EXCEPTION_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%08lx referenced memory at 0x%08lx. The memory could not be %s.
EXCEPTION_PARAMETER1: 0000000000000000
EXCEPTION_PARAMETER2: ffffffffffffffff
READ_ADDRESS: ffffffffffffffff
FOLLOWUP_IP:
fffff880`01badada 488b4018 mov rax,qword ptr [rax+18h]
BUGCHECK_STR: ACCESS_VIOLATION
DEFAULT_BUCKET_ID: WIN7_DRIVER_FAULT
CURRENT_IRQL: 0
LAST_CONTROL_TRANSFER: from 005c006500630069 to fffff88001badada
STACK_TEXT:
fffff880021f49e0 005c0065
00630069 : 0064007200610048 006b0073
00690064 00520044005c0030 fffff880
00000030 : MyDriver!DeviceAttachToStack+0x13a [mydriver.cpp @ 155]
fffff880021f4a60 00640072
00610048 : 006b007300690064 00520044
005c0030 fffff88000000030 00000000
00000000 : 0x005c006500630069 fffff880
021f4a68 006b007300690064 : 00520044
005c0030 fffff88000000030 00000000
00000000 fffffa8303805d10 : 0x00640072
00610048
fffff880021f4a70 00520044
005c0030 : fffff88000000030 00000000
00000000 fffffa8303805d10 fffffa83
03800e00 : 0x006b007300690064 fffff880
021f4a78 fffff88000000030 : 00000000
00000000 fffffa8303805d10 fffffa83
03800e00 fffffa83037f28a0 : 0x00520044
005c0030
fffff880021f4a80 00000000
00000000 : fffffa8303805d10 fffffa83
03800e00 fffffa83037f28a0 fffffa83
037f2800 : 0xfffff880`00000030