[KMTESTS:OB] Write some object information querying tests

This commit is contained in:
George Bișoc 2023-03-19 22:38:31 +01:00
parent 29fc7bb33e
commit 1b33c9415c
No known key found for this signature in database
GPG Key ID: 688C4FBE25D7DEF6
3 changed files with 74 additions and 0 deletions

View File

@ -88,6 +88,7 @@ list(APPEND KMTEST_DRV_SOURCE
ntos_mm/ZwCreateSection.c
ntos_mm/ZwMapViewOfSection.c
ntos_ob/ObHandle.c
ntos_ob/ObQuery.c
ntos_ob/ObReference.c
ntos_ob/ObSecurity.c
ntos_ob/ObSymbolicLink.c

View File

@ -56,6 +56,7 @@ KMT_TESTFUNC Test_NpfsFileInfo;
KMT_TESTFUNC Test_NpfsReadWrite;
KMT_TESTFUNC Test_NpfsVolumeInfo;
KMT_TESTFUNC Test_ObHandle;
KMT_TESTFUNC Test_ObQuery;
KMT_TESTFUNC Test_ObReference;
KMT_TESTFUNC Test_ObSecurity;
KMT_TESTFUNC Test_ObSymbolicLink;
@ -137,6 +138,7 @@ const KMT_TEST TestList[] =
{ "NpfsReadWrite", Test_NpfsReadWrite },
{ "NpfsVolumeInfo", Test_NpfsVolumeInfo },
{ "ObHandle", Test_ObHandle },
{ "ObQuery", Test_ObQuery },
{ "ObReference", Test_ObReference },
{ "ObSecurity", Test_ObSecurity },
{ "ObSymbolicLink", Test_ObSymbolicLink },

View File

@ -0,0 +1,71 @@
/*
* PROJECT: ReactOS kernel-mode tests
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Kernel mode tests for object information querying
* COPYRIGHT: Copyright 2023 George Bișoc <george.bisoc@reactos.org>
*/
#include <kmt_test.h>
#define OBJ_WINSTA_DIRECTORY_NAME_INFO_SIZE (sizeof(UNICODE_STRING) + sizeof(L"\\Windows"))
#define OBJ_DIRECTORY_TYPE_INFO_SIZE (sizeof(OBJECT_TYPE_INFORMATION) + (wcslen(L"\\Directory") * sizeof(WCHAR)))
static
VOID
ObjectBasicInformationTests(VOID)
{
NTSTATUS Status;
HANDLE WinStaDirHandle;
OBJECT_BASIC_INFORMATION BasicInfo;
ULONG ReturnLength;
OBJECT_ATTRIBUTES ObjectAttributes;
static UNICODE_STRING WinStaDir = RTL_CONSTANT_STRING(L"\\Windows");
/* We must be in PASSIVE_LEVEL to do all of this stuff */
ok_irql(PASSIVE_LEVEL);
/* Create a path to \Windows directory */
InitializeObjectAttributes(&ObjectAttributes,
&WinStaDir,
OBJ_CASE_INSENSITIVE | OBJ_OPENIF | OBJ_KERNEL_HANDLE,
NULL,
NULL);
Status = ZwOpenDirectoryObject(&WinStaDirHandle,
DIRECTORY_QUERY | DIRECTORY_TRAVERSE,
&ObjectAttributes);
if (!NT_SUCCESS(Status))
{
ok(FALSE, "Failed to open \\Windows directory (Status 0x%lx)\n", Status);
return;
}
/* Give 0 as information length, this must fail */
Status = ZwQueryObject(WinStaDirHandle,
ObjectBasicInformation,
&BasicInfo,
0,
&ReturnLength);
ok_eq_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Do a proper query now */
Status = ZwQueryObject(WinStaDirHandle,
ObjectBasicInformation,
&BasicInfo,
sizeof(BasicInfo),
&ReturnLength);
ok_eq_hex(Status, STATUS_SUCCESS);
/* \Windows is currently used */
ok(BasicInfo.HandleCount != 0, "\\Windows is in use but HandleCount is 0!\n");
ok(BasicInfo.PointerCount != 0, "\\Windows is in use but PointerCount is 0!\n");
ok_eq_ulong(BasicInfo.NameInfoSize, OBJ_WINSTA_DIRECTORY_NAME_INFO_SIZE);
ok_eq_ulong(BasicInfo.TypeInfoSize, OBJ_DIRECTORY_TYPE_INFO_SIZE);
ZwClose(WinStaDirHandle);
}
START_TEST(ObQuery)
{
ObjectBasicInformationTests();
}