diff options
| author | Fuwn <[email protected]> | 2022-01-04 13:48:00 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-01-04 13:48:00 -0800 |
| commit | c33b9e296ab9563f2b180a8fa63155665055261e (patch) | |
| tree | 086cf2702939fd25769fea83e117d7058af2e75a /crates/windows-kernel-sys/examples | |
| parent | fix(makefile.toml): tidy up (diff) | |
| download | driver-c33b9e296ab9563f2b180a8fa63155665055261e.tar.xz driver-c33b9e296ab9563f2b180a8fa63155665055261e.zip | |
feat(examples): lots of new examples
Thanks, StephanvanSchaik.
Diffstat (limited to 'crates/windows-kernel-sys/examples')
3 files changed, 61 insertions, 0 deletions
diff --git a/crates/windows-kernel-sys/examples/generate_bindings/Cargo.toml b/crates/windows-kernel-sys/examples/generate_bindings/Cargo.toml new file mode 100644 index 0000000..92579f7 --- /dev/null +++ b/crates/windows-kernel-sys/examples/generate_bindings/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "generate_bindings" +version = "0.1.0" +authors = ["Fuwn <[email protected]>"] +edition = "2021" +publish = false + +[lib] +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"] } +windows-kernel-sys = { path = "../../../windows-kernel-sys" } diff --git a/crates/windows-kernel-sys/examples/generate_bindings/build.rs b/crates/windows-kernel-sys/examples/generate_bindings/build.rs new file mode 100644 index 0000000..362047d --- /dev/null +++ b/crates/windows-kernel-sys/examples/generate_bindings/build.rs @@ -0,0 +1 @@ +fn main() { windows_kernel_build::build().unwrap() } diff --git a/crates/windows-kernel-sys/examples/generate_bindings/src/lib.rs b/crates/windows-kernel-sys/examples/generate_bindings/src/lib.rs new file mode 100644 index 0000000..636cadb --- /dev/null +++ b/crates/windows-kernel-sys/examples/generate_bindings/src/lib.rs @@ -0,0 +1,43 @@ +#![no_std] +#![feature(lang_items, const_extern_fn)] +#![deny( + warnings, + nonstandard_style, + unused, + future_incompatible, + rust_2018_idioms +)] +#![deny(clippy::all, clippy::nursery, clippy::pedantic)] + +use windows_kernel_sys::{ + base::{DRIVER_OBJECT, NTSTATUS, STATUS_SUCCESS, UNICODE_STRING}, + ntoskrnl::DbgPrint, +}; + +#[panic_handler] +const fn panic(_info: &core::panic::PanicInfo<'_>) -> ! { loop {} } + +#[lang = "eh_personality"] +const extern "C" fn eh_personality() {} + +/// # Safety +/// `unsafe` +#[no_mangle] +pub unsafe extern "system" fn driver_entry( + driver: &mut DRIVER_OBJECT, + _: &UNICODE_STRING, +) -> NTSTATUS { + // DbgPrint("driver_entry()\0".as_ptr() as _); + DbgPrint("driver_entry()\0".as_ptr().cast()); + + driver.DriverUnload = Some(driver_exit); + + STATUS_SUCCESS +} + +/// # Safety +/// `unsafe` +#[no_mangle] +pub unsafe extern "C" fn driver_exit(_driver: *mut DRIVER_OBJECT) { + DbgPrint("driver_exit()\0".as_ptr().cast()); +} |