-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathminifilter.rs
48 lines (44 loc) · 1.54 KB
/
minifilter.rs
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
use fsfilter_rs::driver_comm;
use fsfilter_rs::shared_def::{CDriverMsgs, IOMessage};
use std::io::Write;
use std::sync::mpsc::channel;
use std::time::Duration;
use std::{io, thread};
fn main() {
let driver = driver_comm::Driver::open_kernel_driver_com()
.expect("Cannot open driver communication (is the mini-filter started?)");
driver
.driver_set_app_pid()
.expect("Cannot set driver app pid");
let mut vecnew: Vec<u8> = Vec::with_capacity(65536);
let (tx_iomsgs, rx_iomsgs) = channel::<IOMessage>();
thread::spawn(move || loop {
if let Some(reply_irp) = driver.get_irp(&mut vecnew) {
if reply_irp.num_ops > 0 {
let drivermsgs = CDriverMsgs::new(&reply_irp);
for drivermsg in drivermsgs {
let iomsg = IOMessage::from(&drivermsg);
if tx_iomsgs.send(iomsg).is_ok() {
} else {
panic!("Cannot send iomsg");
}
}
} else {
// Don't use "continue" as jump statements are expensive "if reply_irp.num_ops > 0"
// continue;
thread::sleep(Duration::from_millis(2));
}
} else {
panic!("Can't receive Driver Message?");
}
});
{
let mut lock = io::stdout().lock();
loop {
if let Ok(mut io_message) = rx_iomsgs.recv() {
io_message.exepath();
write!(lock, "{:?}", io_message);
}
}
}
}