fixed usage of NtQueryDirectoryObject()

svn path=/trunk/; revision=13310
This commit is contained in:
Thomas Bluemel 2005-01-26 13:54:53 +00:00
parent c4ee7a37ef
commit c7348f1204

View file

@ -79,10 +79,14 @@ StatusToName (NTSTATUS Status)
return "STATUS_PATH_SYNTAX_BAD";
case STATUS_NO_MORE_ENTRIES:
return "STATUS_NO_MORE_ENTRIES";
case STATUS_MORE_ENTRIES:
return "STATUS_MORE_ENTRIES";
case STATUS_ACCESS_DENIED:
return "STATUS_ACCESS_DENIED";
case STATUS_UNSUCCESSFUL:
return "STATUS_UNSUCCESSFUL";
case STATUS_INVALID_HANDLE:
return "STATUS_INVALID_HANDLE";
}
sprintf (RawValue, "0x%08lx", Status);
return (const char *) RawValue;
@ -173,8 +177,9 @@ ListDirectory (
OBJECT_ATTRIBUTES ObjectAttributes;
NTSTATUS Status;
HANDLE DirectoryHandle;
BYTE DirectoryEntry [MAX_DIR_ENTRY * sizeof(OBJECT_DIRECTORY_INFORMATION)];
BYTE DirectoryEntry [512];
POBJECT_DIRECTORY_INFORMATION pDirectoryEntry = (POBJECT_DIRECTORY_INFORMATION) DirectoryEntry;
POBJECT_DIRECTORY_INFORMATION pDirectoryEntries = (POBJECT_DIRECTORY_INFORMATION) DirectoryEntry;
ULONG Context = 0;
ULONG ReturnLength = 0;
ULONG EntryCount = 0;
@ -217,25 +222,23 @@ ListDirectory (
return (FALSE);
}
printf ("\n Directory of %s\n\n", DirectoryNameA);
for(;;)
{
/*
* Enumerate each item in the directory.
*/
Status = NtQueryDirectoryObject (
DirectoryHandle,
pDirectoryEntry,
pDirectoryEntries,
sizeof DirectoryEntry,
FALSE,/* ReturnSingleEntry */
TRUE, /* RestartScan */
FALSE, /* RestartScan */
& Context,
& ReturnLength
);
if (!NT_SUCCESS(Status))
if (!NT_SUCCESS(Status) && Status != STATUS_NO_MORE_ENTRIES)
{
if (STATUS_NO_MORE_ENTRIES == Status)
{
NtClose (DirectoryHandle);
return TRUE;
}
printf (
"Failed to query directory object (Status: %s)\n",
StatusToName (Status)
@ -243,7 +246,12 @@ ListDirectory (
NtClose (DirectoryHandle);
return (FALSE);
}
while (0 != pDirectoryEntry->ObjectTypeName.Length)
if (Status == STATUS_NO_MORE_ENTRIES)
{
break;
}
pDirectoryEntry = pDirectoryEntries;
while (EntryCount < Context)
{
CHAR ObjectNameA [MAX_PATH];
CHAR TypeNameA [MAX_PATH];
@ -283,9 +291,10 @@ ListDirectory (
RawUszAsz (pDirectoryEntry->ObjectName.Buffer, ObjectNameA)
);
}
++ EntryCount;
++ pDirectoryEntry;
++ EntryCount;
}
};
printf ("\n\t%lu object(s)\n", EntryCount);
/*
* Free any resource.