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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
use ::NTSTATUS;
use ::basedef::*;
use ::event::PKEVENT;
use ::device_object::*;
use ::file_object::*;
use ::basedef::IO_PRIORITY::*;
use ::KIRQL;
pub type PIRP = *mut IRP;
pub type PIO_STACK_LOCATION = *mut IO_STACK_LOCATION;
extern "system"
{
fn IoCompleteRequest(Irp: PIRP, PriorityBoost: KPRIORITY_BOOST);
}
#[repr(u8)]
pub enum IRP_MJ
{
CREATE,
CREATE_NAMED_PIPE,
CLOSE,
READ,
WRITE,
QUERY_INFORMATION,
SET_INFORMATION,
QUERY_EA,
SET_EA,
FLUSH_BUFFERS,
QUERY_VOLUME_INFORMATION,
SET_VOLUME_INFORMATION,
DIRECTORY_CONTROL,
FILE_SYSTEM_CONTROL,
DEVICE_CONTROL,
INTERNAL_DEVICE_CONTROL,
SHUTDOWN,
LOCK_CONTROL,
CLEANUP,
CREATE_MAILSLOT,
QUERY_SECURITY,
SET_SECURITY,
POWER,
SYSTEM_CONTROL,
DEVICE_CHANGE,
QUERY_QUOTA,
SET_QUOTA,
PNP,
MAXIMUM_FUNCTION,
}
#[repr(C)]
pub struct IRP
{
pub Type: u16,
pub Size: u16,
pub MdlAddress: PVOID,
pub Flags: u32,
pub SystemBuffer: PVOID,
pub ThreadListEntry: LIST_ENTRY,
pub IoStatus: IO_STATUS_BLOCK,
pub RequestorMode: KPROCESSOR_MODE,
pub PendingReturned: bool,
pub StackCount: i8,
pub CurrentLocation: i8,
pub Cancel: bool,
pub CancelIrql: KIRQL,
pub ApcEnvironment: u8,
pub AllocationFlags: u8,
pub UserIosb: PIO_STATUS_BLOCK,
pub UserEvent: PKEVENT,
pub UserApcRoutine: PIO_APC_ROUTINE,
pub UserApcContext: PVOID,
pub CancelRoutine: PDRIVER_CANCEL,
pub UserBuffer: PVOID,
pub Overlay: _IRP_OVERLAY,
}
#[repr(C)]
pub struct _IRP_OVERLAY
{
pub DriverContext: [PVOID; 4],
pub Thread: PETHREAD,
pub AuxiliaryBuffer: PVOID,
pub ListEntry: LIST_ENTRY,
pub CurrentStackLocation: PIO_STACK_LOCATION,
pub OriginalFileObject: PFILE_OBJECT,
}
#[repr(C)]
pub struct IO_STACK_LOCATION
{
pub MajorFunction: u8,
pub MinorFunction: u8,
pub Flags: u8,
pub Control: u8,
pub Parameters: [PVOID; 4],
pub DeviceObject: PDEVICE_OBJECT,
pub FileObject: PFILE_OBJECT,
pub CompletionRoutine: PIO_COMPLETION_ROUTINE,
pub Context: PVOID,
}
#[repr(C)]
pub struct _IO_STACK_LOCATION_READ
{
pub Length: u32,
pub Key: u32,
pub ByteOffset: i64,
}
impl IRP {
pub fn get_current_stack_location(&mut self) -> &mut IO_STACK_LOCATION {
unsafe { &mut *self.Overlay.CurrentStackLocation }
}
pub fn complete_request(&mut self, Status: NTSTATUS) -> NTSTATUS {
self.IoStatus.Status = Status;
unsafe { IoCompleteRequest(self, IO_NO_INCREMENT) };
return Status;
}
}
impl IO_STACK_LOCATION {
pub fn ParametersRead(&mut self) -> &mut _IO_STACK_LOCATION_READ {
unsafe { ::core::mem::transmute(&mut self.Parameters) }
}
}