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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//! Device Object.

use ::{NTSTATUS, UNICODE_STRING};
use ::driver_object::DRIVER_OBJECT;
use ::irp::{IRP, PIRP};
use ::dpc::KDPC;
use ::event::KEVENT;
use ::object::*;
use ::PVOID;

extern "system"
{
	pub fn IoCreateDevice(DriverObject: &mut DRIVER_OBJECT, DeviceExtensionSize: u32, DeviceName: *const UNICODE_STRING,
		DeviceType: u32, DeviceCharacteristics: u32, Exclusive: bool, DeviceObject: *mut*mut DEVICE_OBJECT) -> NTSTATUS;

	pub fn IoDeleteDevice(DeviceObject: &mut DEVICE_OBJECT) -> NTSTATUS;
	pub fn IoCreateSymbolicLink(SymbolicLinkName: &UNICODE_STRING, DeviceName: &UNICODE_STRING) -> NTSTATUS;
	pub fn IoDeleteSymbolicLink(SymbolicLinkName: &UNICODE_STRING) -> NTSTATUS;
}

/// Device object flags.
#[repr(C)]
pub enum DEVICE_FLAGS {
	NONE = 0,
	DO_VERIFY_VOLUME                = 0x00000002,
	DO_BUFFERED_IO                  = 0x00000004,
	DO_EXCLUSIVE                    = 0x00000008,
	DO_DIRECT_IO                    = 0x00000010,
	DO_MAP_IO_BUFFER                = 0x00000020,
	DO_DEVICE_HAS_NAME              = 0x00000040,
	DO_DEVICE_INITIALIZING          = 0x00000080,
	DO_SYSTEM_BOOT_PARTITION        = 0x00000100,
	DO_LONG_TERM_REQUESTS           = 0x00000200,
	DO_NEVER_LAST_DEVICE            = 0x00000400,
	DO_SHUTDOWN_REGISTERED          = 0x00000800,
	DO_BUS_ENUMERATED_DEVICE        = 0x00001000,
	DO_POWER_PAGABLE                = 0x00002000,
	DO_POWER_INRUSH                 = 0x00004000,
	DO_POWER_NOOP                   = 0x00008000,
	DO_LOW_PRIORITY_FILESYSTEM      = 0x00010000,
	DO_XIP                          = 0x00020000
}

/// The `DEVICE_OBJECT` structure is used by the operating system to represent a device object.
#[repr(C)]
pub struct DEVICE_OBJECT
{
	pub Type: u16,
	pub Size: u16,
	pub ReferenceCount: i32,
	pub DriverObject: *const DRIVER_OBJECT,
	pub NextDevice: *mut DEVICE_OBJECT,
	pub AttachedDevice: *mut DEVICE_OBJECT,
	pub CurrentIrp: *const IRP,
	pub Timer: *mut u8,
	pub Flags: u32,
	pub Characteristics: u32,
	pub Vpb: *mut u8,
	pub DeviceExtension: *mut u8,
	pub DeviceType: u32,
	pub StackSize: u8,
	pub Queue: *mut WAIT_CONTEXT_BLOCK,
	pub AlignmentRequirement: u32,
	pub DeviceQueue: KDEVICE_QUEUE,
	pub Dpc: KDPC,
	pub ActiveThreadCount: u32,
	pub SecurityDescriptor: *const u8,
	pub DeviceLock: KEVENT,
	pub SectorSize: u16,
	pub Spare1: u16,
	pub DeviceObjectExtension: *mut DEVOBJ_EXTENSION,
	pub Reserved: *const u8,
}

/// Device object extension structure.
#[repr(C)]
pub struct DEVOBJ_EXTENSION
{
	Type: u16,
	Size: u16,
	DeviceObject: *mut DEVICE_OBJECT,
	PowerFlags: u32,
	Dope: *mut u8,
	ExtensionFlags: u32,
	DeviceNode: *mut u8,
	AttachedTo: *mut DEVICE_OBJECT,
	StartIoCount: i32,
	StartIoKey: i32,
	StartIoFlags: u32,
	Vpb: *mut u8,
}

pub type PDEVICE_OBJECT = *mut DEVICE_OBJECT;

pub type PDRIVER_CANCEL = Option<extern "system" fn (DeviceObject: PDEVICE_OBJECT, Irp: PIRP)>;

pub type PDRIVER_DISPATCH = Option<extern "system" fn (DeviceObject: &mut DEVICE_OBJECT, Irp: &mut IRP) -> NTSTATUS>;

pub type PIO_COMPLETION_ROUTINE = Option<extern "system" fn (DeviceObject: PDEVICE_OBJECT, Irp: PIRP, Context: PVOID) -> NTSTATUS>;