├── .gitignore ├── Cargo.toml ├── LICENSE ├── README.md ├── i686-kernel-windows-msvc.json ├── rust-toolchain ├── src └── lib.rs ├── win-kmd-native-lib ├── Cargo.toml ├── build.rs ├── src │ └── lib.rs └── win7 │ └── km │ ├── x64 │ ├── fltMgr.lib │ ├── fwpkclnt.lib │ ├── ndis.lib │ └── ntoskrnl.lib │ └── x86 │ ├── fltMgr.lib │ ├── fwpkclnt.lib │ ├── ndis.lib │ └── ntoskrnl.lib └── x86_64-kernel-windows-msvc.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target/ 4 | 5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 6 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 7 | Cargo.lock 8 | 9 | # These are backup files generated by rustfmt 10 | **/*.rs.bk 11 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = ["saber "] 3 | edition = "2018" 4 | name = "win-driver-example" 5 | version = "0.1.0" 6 | 7 | [dependencies.win-kmd-alloc] 8 | git = "https://github.com/woodgear/win-kmd-alloc.git" 9 | branch = "feature/km" 10 | 11 | [dependencies.win-kmd-native-lib] 12 | path = "./win-kmd-native-lib" 13 | 14 | [dependencies.winapi] 15 | git = "https://github.com/Trantect/winapi-rs.git" 16 | branch = "feature/km" 17 | features = [ 18 | "wdm", 19 | "ntstatus", 20 | ] 21 | 22 | [lib] 23 | crate-type = ["dylib"] 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Trantect 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Prepare build environment 2 | ```bash 3 | cargo install cargo-xbuild 4 | ``` 5 | 6 | # Build drivers 7 | ```bash 8 | # build driver for x64 9 | cargo xbuild --target x86_64-kernel-windows-msvc.json 10 | # build driver for x86 11 | cargo xbuild --target i686-kernel-windows-msvc.json 12 | ``` 13 | 14 | # Acknowledges 15 | * [winapi-kmd-rs](https://github.com/pravic/winapi-kmd-rs) 16 | * [blog_os](https://os.phil-opp.com/) 17 | * [cargo-xbuild](https://github.com/rust-osdev/cargo-xbuild) 18 | -------------------------------------------------------------------------------- /i686-kernel-windows-msvc.json: -------------------------------------------------------------------------------- 1 | { 2 | "abi-return-struct-as-int": true, 3 | "arch": "x86", 4 | "cpu": "pentium4", 5 | "crt-static-allows-dylibs": true, 6 | "crt-static-respected": true, 7 | "data-layout": "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32", 8 | "dll-prefix": "", 9 | "dll-suffix": ".sys", 10 | "dynamic-linking": true, 11 | "emit-debug-gdb-scripts": false, 12 | "env": "msvc", 13 | "exe-suffix": ".exe", 14 | "executables": true, 15 | "has-elf-tls": false, 16 | "is-builtin": true, 17 | "is-like-msvc": true, 18 | "is-like-windows": true, 19 | "linker-flavor": "msvc", 20 | "llvm-target": "i686-pc-windows-msvc", 21 | "max-atomic-width": 64, 22 | "os": "windows", 23 | "pre-link-args": { 24 | "msvc": [ 25 | "/NOLOGO", 26 | "/NODEFAULTLIB", 27 | "/SUBSYSTEM:NATIVE", 28 | "/DRIVER", 29 | "/RELEASE", 30 | "/NXCOMPAT", 31 | "/DYNAMICBASE", 32 | "/INCREMENTAL:NO", 33 | "/MANIFEST:NO" 34 | ] 35 | }, 36 | "post-link-args": { 37 | "msvc": [ 38 | "/OPT:REF,ICF", 39 | "/noimplib", 40 | "/ENTRY:DriverEntry", 41 | "/MERGE:.edata=.rdata", 42 | "/MERGE:.rustc=.data", 43 | "/INTEGRITYCHECK" 44 | ] 45 | }, 46 | "requires-uwtable": true, 47 | "staticlib-prefix": "", 48 | "staticlib-suffix": ".lib", 49 | "target-c-int-width": "32", 50 | "target-endian": "little", 51 | "target-family": "windows", 52 | "target-pointer-width": "32", 53 | "vendor": "pc", 54 | "features": "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float", 55 | "code-model": "kernel", 56 | "relocation-model": "dynamic-no-pic", 57 | "disable-redzone": true, 58 | "eliminate-frame-pointer": true, 59 | "panic-strategy": "abort" 60 | 61 | } 62 | -------------------------------------------------------------------------------- /rust-toolchain: -------------------------------------------------------------------------------- 1 | nightly -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | #![allow(non_snake_case)] 3 | #![feature(alloc)] 4 | #![feature(alloc_prelude)] 5 | 6 | extern crate alloc; 7 | extern crate win_kmd_alloc; 8 | extern crate win_kmd_native_lib; 9 | 10 | use crate::win_kmd_alloc::KernelAlloc; 11 | use winapi::{ 12 | shared::{ 13 | ntstatus::*, 14 | ntdef::*, 15 | }, 16 | }; 17 | use core::panic::PanicInfo; 18 | 19 | #[global_allocator] 20 | static GLOBAL: KernelAlloc = KernelAlloc; 21 | 22 | #[panic_handler] 23 | fn panic(_info: &PanicInfo) -> ! { 24 | loop {} 25 | } 26 | 27 | #[no_mangle] 28 | pub extern "system" fn DriverEntry(_driver: PVOID, _path: PVOID) -> NTSTATUS { 29 | STATUS_SUCCESS 30 | } 31 | -------------------------------------------------------------------------------- /win-kmd-native-lib/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "win-kmd-native-lib" 3 | version = "0.1.0" 4 | authors = ["saber "] 5 | edition = "2018" 6 | build = "build.rs" 7 | -------------------------------------------------------------------------------- /win-kmd-native-lib/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | use std::env::var; 3 | use std::path::Path; 4 | 5 | let target = var("TARGET").unwrap(); 6 | 7 | if target.contains("x86_64") { 8 | let dir = var("CARGO_MANIFEST_DIR").unwrap(); 9 | println!("cargo:rustc-link-search=native={}", Path::new(&dir).join(r#"win7\km\x64"#).display()); 10 | } 11 | 12 | if target.contains("i686") { 13 | let dir = var("CARGO_MANIFEST_DIR").unwrap(); 14 | println!("cargo:rustc-link-search=native={}", Path::new(&dir).join(r#"win7\km\x86"#).display()); 15 | } 16 | } -------------------------------------------------------------------------------- /win-kmd-native-lib/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] -------------------------------------------------------------------------------- /win-kmd-native-lib/win7/km/x64/fltMgr.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trantect/win_driver_example/ca8fcd68570059acc6acd947a06a25f26b28576a/win-kmd-native-lib/win7/km/x64/fltMgr.lib -------------------------------------------------------------------------------- /win-kmd-native-lib/win7/km/x64/fwpkclnt.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trantect/win_driver_example/ca8fcd68570059acc6acd947a06a25f26b28576a/win-kmd-native-lib/win7/km/x64/fwpkclnt.lib -------------------------------------------------------------------------------- /win-kmd-native-lib/win7/km/x64/ndis.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trantect/win_driver_example/ca8fcd68570059acc6acd947a06a25f26b28576a/win-kmd-native-lib/win7/km/x64/ndis.lib -------------------------------------------------------------------------------- /win-kmd-native-lib/win7/km/x64/ntoskrnl.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trantect/win_driver_example/ca8fcd68570059acc6acd947a06a25f26b28576a/win-kmd-native-lib/win7/km/x64/ntoskrnl.lib -------------------------------------------------------------------------------- /win-kmd-native-lib/win7/km/x86/fltMgr.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trantect/win_driver_example/ca8fcd68570059acc6acd947a06a25f26b28576a/win-kmd-native-lib/win7/km/x86/fltMgr.lib -------------------------------------------------------------------------------- /win-kmd-native-lib/win7/km/x86/fwpkclnt.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trantect/win_driver_example/ca8fcd68570059acc6acd947a06a25f26b28576a/win-kmd-native-lib/win7/km/x86/fwpkclnt.lib -------------------------------------------------------------------------------- /win-kmd-native-lib/win7/km/x86/ndis.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trantect/win_driver_example/ca8fcd68570059acc6acd947a06a25f26b28576a/win-kmd-native-lib/win7/km/x86/ndis.lib -------------------------------------------------------------------------------- /win-kmd-native-lib/win7/km/x86/ntoskrnl.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trantect/win_driver_example/ca8fcd68570059acc6acd947a06a25f26b28576a/win-kmd-native-lib/win7/km/x86/ntoskrnl.lib -------------------------------------------------------------------------------- /x86_64-kernel-windows-msvc.json: -------------------------------------------------------------------------------- 1 | { 2 | "abi-return-struct-as-int": true, 3 | "arch": "x86_64", 4 | "cpu": "x86-64", 5 | "crt-static-allows-dylibs": true, 6 | "crt-static-respected": true, 7 | "data-layout": "e-m:w-i64:64-f80:128-n8:16:32:64-S128", 8 | "dll-prefix": "", 9 | "dll-suffix": ".sys", 10 | "dynamic-linking": true, 11 | "emit-debug-gdb-scripts": false, 12 | "env": "msvc", 13 | "exe-suffix": ".exe", 14 | "executables": true, 15 | "has-elf-tls": false, 16 | "is-builtin": true, 17 | "is-like-msvc": true, 18 | "is-like-windows": true, 19 | "linker-flavor": "msvc", 20 | "llvm-target": "x86_64-pc-windows-msvc", 21 | "max-atomic-width": 64, 22 | "os": "windows", 23 | "pre-link-args": { 24 | "msvc": [ 25 | "/NOLOGO", 26 | "/NODEFAULTLIB", 27 | "/SUBSYSTEM:NATIVE", 28 | "/DRIVER", 29 | "/RELEASE", 30 | "/NXCOMPAT", 31 | "/DYNAMICBASE", 32 | "/INCREMENTAL:NO", 33 | "/MANIFEST:NO" 34 | ] 35 | }, 36 | "post-link-args": { 37 | "msvc": [ 38 | "/OPT:REF,ICF", 39 | "/noimplib", 40 | "/ENTRY:DriverEntry", 41 | "/MERGE:.edata=.rdata", 42 | "/MERGE:.rustc=.data", 43 | "/INTEGRITYCHECK" 44 | ] 45 | }, 46 | "requires-uwtable": true, 47 | "staticlib-prefix": "", 48 | "staticlib-suffix": ".lib", 49 | "target-c-int-width": "32", 50 | "target-endian": "little", 51 | "target-family": "windows", 52 | "target-pointer-width": "64", 53 | "vendor": "pc", 54 | "features": "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float", 55 | "code-model": "kernel", 56 | "relocation-model": "dynamic-no-pic", 57 | "disable-redzone": true, 58 | "eliminate-frame-pointer": true, 59 | "panic-strategy": "abort" 60 | } --------------------------------------------------------------------------------