Hey All,
I have a driver that receives a path from user-land. The path is stored in
a PUNICODE_STRING and is something like: "c:\myFolder". I need to call
InitializeObjectAttributes(…) with this path which takes the object name.
If I pass the path I receive from the user into this function, it cannot
locate the name because it is not valid. Currently, my code prefixes the
user path with "\DosDevices" so that when I call
InitializeObjectAttributes, it is able to find it.
My question though is whether this is the cleanest approach for doing this?
and also, can I gaurantee that "\DosDevices" will exist on all machines?
From my understanding, \DosDevices\ is a symbolic link to ?? so it can be
deleted at any time right? Is there a way to automatically convert this user
path to its object equivalent?
Thanks
J
Code:
UNICODE_STRING pstrRootObjPath;
RtlInitUnicodeString(&pstrRootObjPath, L"\DosDevices");
// Not really sure the appropriate arguments to pass as the 3rd argument!?
OBJECT_ATTRIBUTES oaRoot;
InitializeObjectAttributes(&oaRoot,
const_cast<punicode_string>(&pstrRootObjPath), NULL, NULL, NULL);
HANDLE hRootDirectoryObject = NULL;
ulStatus = ZwCreateDirectoryObject(&hRootDirectoryObject, DIRECTORY_TRAVERSE
| DIRECTORY_QUERY, &oaRoot);
// using root object to search for the user’s specified object
OBJECT_ATTRIBUTES oa;
InitializeObjectAttributes(&oa, const_cast<punicode_string>(pstrUserPath),
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, hRootDirectoryObject,
NULL);
ZwClose(hRootDirectoryObject);
…
…</punicode_string></punicode_string>