diff options
| author | Fuwn <[email protected]> | 2022-01-04 15:08:12 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-01-04 15:08:12 -0800 |
| commit | 44b2fe789f50ac75b079e3d7495ef46bc2c9bfd6 (patch) | |
| tree | edff38046ad91a8952e2a9f3d121adc9206e6943 | |
| parent | chore(windows-kernel-rs): remove unused profiles (diff) | |
| download | driver-44b2fe789f50ac75b079e3d7495ef46bc2c9bfd6.tar.xz driver-44b2fe789f50ac75b079e3d7495ef46bc2c9bfd6.zip | |
feat(driver): use framework
| -rw-r--r-- | crates/driver/Cargo.toml | 11 | ||||
| -rw-r--r-- | crates/driver/src/lib.rs | 37 |
2 files changed, 13 insertions, 35 deletions
diff --git a/crates/driver/Cargo.toml b/crates/driver/Cargo.toml index 1ffeb53..d1f30d6 100644 --- a/crates/driver/Cargo.toml +++ b/crates/driver/Cargo.toml @@ -18,11 +18,6 @@ crate-type = ["cdylib"] [build-dependencies] windows-kernel-build = { path = "../windows-kernel-build" } -[dependencies.winapi] -git = "https://github.com/Trantect/winapi-rs.git" -branch = "feature/km" -features = [ - "wdm", - "ntstatus", - "ntdef" -] +[dependencies] +winapi = { git = "https://github.com/Trantect/winapi-rs.git", branch = "feature/km", features = ["wdm", "ntstatus", "ntdef"] } +windows-kernel-rs = { path = "../windows-kernel-rs" } diff --git a/crates/driver/src/lib.rs b/crates/driver/src/lib.rs index d0df8b7..1a51dc5 100644 --- a/crates/driver/src/lib.rs +++ b/crates/driver/src/lib.rs @@ -12,36 +12,19 @@ )] #![deny(clippy::all, clippy::nursery, clippy::pedantic)] -use winapi::{ - km::wdm::{DbgPrint, DRIVER_OBJECT}, - shared::ntdef::{NTSTATUS, UNICODE_STRING}, -}; +use windows_kernel_rs::{kernel_module, println, Driver, Error, KernelModule}; -#[panic_handler] -const fn panic(_info: &core::panic::PanicInfo<'_>) -> ! { loop {} } +struct Module; +impl KernelModule for Module { + fn init(_: Driver, _: &str) -> Result<Self, Error> { + println!("init()"); -// https://users.rust-lang.org/t/solved-hello-world-no-std-build-problem/23122/4 -#[lang = "eh_personality"] -const extern "C" fn eh_personality() {} - -/// # Safety -/// `unsafe` -#[no_mangle] -pub extern "system" fn driver_entry(driver: &mut DRIVER_OBJECT, _: &UNICODE_STRING) -> NTSTATUS { - unsafe { - DbgPrint("driver_entry()\0".as_ptr()); + Ok(Module) } - driver.DriverUnload = Some(driver_exit); - - winapi::shared::ntstatus::STATUS_SUCCESS -} - -/// # Safety -/// `unsafe` -#[no_mangle] -pub extern "system" fn driver_exit(_driver: &mut DRIVER_OBJECT) { - unsafe { - DbgPrint("driver_exit()\0".as_ptr()); + fn cleanup(&mut self, _: Driver) { + println!("cleanup()"); } } + +kernel_module!(Module); |