-
Notifications
You must be signed in to change notification settings - Fork 24
/
shared.c
64 lines (55 loc) · 1.28 KB
/
shared.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "shared.h"
NTSTATUS
My_IoGetDeviceObjectPointer(
IN PUNICODE_STRING ObjectName,
IN ACCESS_MASK DesiredAccess,
OUT PFILE_OBJECT *FileObject,
OUT PDEVICE_OBJECT *DeviceObject
)
{
PFILE_OBJECT fileObject;
OBJECT_ATTRIBUTES objectAttributes;
HANDLE fileHandle;
IO_STATUS_BLOCK ioStatus;
NTSTATUS status;
InitializeObjectAttributes(&objectAttributes,
ObjectName,
OBJ_KERNEL_HANDLE,
(HANDLE)NULL,
(PSECURITY_DESCRIPTOR)NULL);
status = ZwOpenFile(&fileHandle,
DesiredAccess,
&objectAttributes,
&ioStatus,
FILE_SHARE_READ,
FILE_NON_DIRECTORY_FILE);
if (NT_SUCCESS(status))
{
status = ObReferenceObjectByHandle(fileHandle,
0,
*IoFileObjectType,
KernelMode,
(PVOID *)&fileObject,
NULL);
if (NT_SUCCESS(status))
{
*FileObject = fileObject;
*DeviceObject = IoGetBaseFileSystemDeviceObject(fileObject);
}
ZwClose(fileHandle);
}
return status;
}
void *FindDevNodeRecurse(PDEVICE_OBJECT a1, ULONGLONG *a2)
{
struct DEVOBJ_EXTENSION_FIX *attachment;
attachment = a1->DeviceObjectExtension;
if ((!attachment->AttachedTo) && (!attachment->DeviceNode)) return;
if ((!attachment->DeviceNode) && (attachment->AttachedTo))
{
FindDevNodeRecurse(attachment->AttachedTo, a2);
return;
}
*a2 = (ULONGLONG)attachment->DeviceNode;
return;
}