Skip to content
This repository was archived by the owner on Aug 10, 2024. It is now read-only.

Commit 464e956

Browse files
committed
upgrade application dependencies and refactor
1 parent f47ad57 commit 464e956

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

windows-rust-application/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "rust"
2+
name = "application"
33
version = "0.1.0"
44
edition = "2021"
55

@@ -8,7 +8,7 @@ edition = "2021"
88
[dependencies]
99

1010
[dependencies.windows-sys]
11-
version = "0.45.0"
11+
version = "0.48.0"
1212
features = [
1313
"Win32_Storage_InstallableFileSystems",
1414
"Win32_Foundation",

windows-rust-application/src/main.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,39 @@ use windows_sys::Win32::Storage::InstallableFileSystems::{
1010
static mut PORT: HANDLE = -1;
1111

1212
fn main() {
13-
println!("Press ctrl-z to ctrl-c to exit...");
14-
1513
let mut byterec = 0;
16-
let buffer = "Hello from Rust user application\n\0".as_bytes().as_ptr() as *const c_void;
14+
let buffer = "Hello from Rust user space application\n\0"
15+
.as_bytes()
16+
.as_ptr()
17+
.cast::<c_void>();
1718
let bufferlen = 50;
1819
let rbuffer_size = 256;
1920
let mut rbuffer: Vec<u8> = vec![0; rbuffer_size];
20-
let recbuffer: *mut c_void = rbuffer.as_mut_ptr() as *mut c_void;
21+
let recbuffer: *mut c_void = rbuffer.as_mut_ptr().cast::<c_void>();
2122

2223
unsafe {
2324
if PORT == -1
2425
&& FilterConnectCommunicationPort(w!("\\mf"), 0, null(), 0, null(), &mut PORT) != 0
2526
{
26-
panic!("port connection failed");
27+
panic!("Port connection failed");
2728
}
2829
}
2930

31+
println!("Connection to minifilter was successful!!!");
32+
3033
unsafe {
3134
if FilterSendMessage(PORT, buffer, bufferlen as u32, recbuffer, 50, &mut byterec) != 0 {
32-
println!("failed to get message");
35+
println!("Failed to get kernel message");
3336
} else {
34-
let pchar = recbuffer as *mut i8;
37+
let pchar = recbuffer.cast::<i8>();
3538
let string = std::ffi::CStr::from_ptr(pchar)
3639
.to_str()
3740
.expect("Not a valid String");
38-
print!("{}", string);
41+
println!("Message from minifilter: {string}");
3942
}
4043
}
4144

45+
println!("\nPress ctrl-z to ctrl-c to exit...\n");
46+
4247
loop {}
4348
}

0 commit comments

Comments
 (0)