Hi, all.
In application mode, I got the below result by FindFirstFile API.
CString strFolder;
WIN32_FIND_DATA FindData = { 0 };
HANDLE handle = NULL;
strFolder = L"c:\docume~1";
handle = FindFirstFile(strFolder, &FindData);
As result, it returns “Documents and Settings” in cFileName field and “DOCUME~1” in cAlternate field.
In kernel mode, I write below code to get the same result.
NTSTATUS status = STATUS_SUCCESS;
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING uszDosDevicePath = CONSTANT_UNICODE_STRING(L"\??\c:\docume~1");
HANDLE hFindFile;
IO_STATUS_BLOCK IoStatusBlock = { 0 };
struct SEARCH_BUFFER {
FILE_BOTH_DIR_INFORMATION DirInfo;
WCHAR Names[260];
} buffer;
PFILE_BOTH_DIR_INFORMATION pFileBothDirInfo;
InitializeObjectAttributes(&ObjectAttributes, &uszDosDevicePath, OBJ_CASE_INSENSITIVE, 0, 0);
status = ZwOpenFile(&hFindFile, FILE_LIST_DIRECTORY | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock, FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT | FILE_OPEN_FOR_BACKUP_INTENT);
RtlZeroMemory(&buffer, sizeof(buffer));
pFileBothDirInfo = &buffer.DirInfo;
status = ZwQueryDirectoryFile(
hFindFile,
NULL,
NULL,
NULL,
&IoStatusBlock,
pFileBothDirInfo,
sizeof(buffer),
FileBothDirectoryInformation,
TRUE,
NULL,
FALSE
);
if (!NT_SUCCESS(status))
{
ZwClose(hFindFile);
return;
}
ZwQueryDirectoryFile returns STATUS_SUCCESS, but pFileBothDirInfo->FileName is “.”, not “Documents and Settings”.
Q1 : Why it returns the different result of Ring3? How can i get the same result ?.
And after that, I called it again.
pFileBothDirInfo = (PFILE_BOTH_DIR_INFORMATION) bufNext;
status = ZwQueryDirectoryFile(
hFindFile,
NULL,
NULL,
NULL,
&IoStatusBlock,
pFileBothDirInfo,
4096,
FileBothDirectoryInformation,
FALSE,
NULL,
FALSE
);
It also returns STATUS_SUCCESS, but pFileBothDirInfo didn’t query some folders such as “administrator” or “TestPC” (“TestPC” is a windows user name).
But in Ring3 mode, I can get all directory infos by FindNextFile.
Q2. How can i get all all directory informations in kernel mode?
Thanx.