Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 12 +++++++++++- dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 2 +- dlls/ntoskrnl.exe/tests/driver.c | 17 ++++++++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 27c7d00c1a..3481f9da0e 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -315,6 +315,7 @@ static void ObReferenceObject( void *obj ) TRACE( "(%p) ref=%u\n", obj, ref ); }
+extern POBJECT_TYPE directory_type; static const POBJECT_TYPE *known_types[] = { &ExEventObjectType, @@ -324,7 +325,8 @@ static const POBJECT_TYPE *known_types[] = &IoFileObjectType, &PsProcessType, &PsThreadType, - &SeTokenObjectType + &SeTokenObjectType, + &directory_type };
static NTSTATUS kernel_object_from_handle( HANDLE handle, POBJECT_TYPE type, void **ret ) @@ -1440,6 +1442,14 @@ void WINAPI IoDeleteDevice( DEVICE_OBJECT *device ) }
+static const WCHAR directory_type_name[] = {'D','i','r','e','c','t','o','r','y',0}; + +static struct _OBJECT_TYPE _directory_type = { + directory_type_name +}; + +POBJECT_TYPE directory_type = &_directory_type; + /*********************************************************************** * IoCreateSymbolicLink (NTOSKRNL.EXE.@) */ diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index da16bc2e2a..a43badae4e 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -1345,7 +1345,7 @@ @ stdcall -private ZwMakeTemporaryObject(long) NtMakeTemporaryObject @ stdcall -private ZwMapViewOfSection(long long ptr long long ptr ptr long long long) NtMapViewOfSection @ stdcall -private ZwNotifyChangeKey(long long ptr ptr ptr long long ptr long long) NtNotifyChangeKey -@ stdcall -private ZwOpenDirectoryObject(ptr long ptr) NtOpenDirectoryObject +@ stdcall ZwOpenDirectoryObject(ptr long ptr) NtOpenDirectoryObject @ stdcall -private ZwOpenEvent(ptr long ptr) NtOpenEvent @ stdcall ZwOpenFile(ptr long ptr ptr long long) NtOpenFile @ stdcall -private ZwOpenJobObject(ptr long ptr) NtOpenJobObject diff --git a/dlls/ntoskrnl.exe/tests/driver.c b/dlls/ntoskrnl.exe/tests/driver.c index 64abca4c25..27755f83af 100644 --- a/dlls/ntoskrnl.exe/tests/driver.c +++ b/dlls/ntoskrnl.exe/tests/driver.c @@ -664,7 +664,7 @@ static void test_ob_reference(const WCHAR *test_path) { POBJECT_TYPE (WINAPI *pObGetObjectType)(void*); OBJECT_ATTRIBUTES attr = { sizeof(attr) }; - HANDLE event_handle, file_handle, file_handle2, thread_handle; + HANDLE event_handle, file_handle, file_handle2, thread_handle, directory_handle; FILE_OBJECT *file; void *obj1, *obj2; POBJECT_TYPE obj1_type; @@ -675,6 +675,7 @@ static void test_ob_reference(const WCHAR *test_path) NTSTATUS status;
static const WCHAR tmpW[] = {'.','t','m','p',0}; + static const WCHAR directoryW[] = {'\','D','e','v','i','c','e',0};
pObGetObjectType = get_proc_address("ObGetObjectType"); if (!pObGetObjectType) @@ -697,6 +698,12 @@ static void test_ob_reference(const WCHAR *test_path) ok(!status, "ZwCreateFile failed: %#x\n", status); ExFreePool(tmp_path);
+ RtlInitUnicodeString(&pathU, directoryW); + attr.ObjectName = &pathU; + attr.Attributes = OBJ_OPENIF; + status = ZwOpenDirectoryObject(&directory_handle, 0, &attr); + ok(!status, "ZwCreateDirectoryObject failed: %#x\n", status); + status = ZwDuplicateObject(NtCurrentProcess(), file_handle, NtCurrentProcess(), &file_handle2, 0, OBJ_KERNEL_HANDLE, DUPLICATE_SAME_ACCESS); ok(!status, "ZwDuplicateObject failed: %#x\n", status); @@ -769,6 +776,11 @@ static void test_ob_reference(const WCHAR *test_path) ObDereferenceObject(obj1); ObDereferenceObject(obj2);
+ status = ObReferenceObjectByHandle(directory_handle, SYNCHRONIZE, NULL, KernelMode, &obj1, NULL); + ok(!status, "ObReferenceObjectByHandle failed: %#x\n", status); + + ObDereferenceObject(obj1); + status = ZwClose(thread_handle); ok(!status, "ZwClose failed: %#x\n", status);
@@ -780,6 +792,9 @@ static void test_ob_reference(const WCHAR *test_path)
status = ZwClose(file_handle2); ok(!status, "ZwClose failed: %#x\n", status); + + status = ZwClose(directory_handle); + ok(!status, "ZwClose failed: %#x\n", status); }
static NTSTATUS main_test(DEVICE_OBJECT *device, IRP *irp, IO_STACK_LOCATION *stack, ULONG_PTR *info)