This is a Rust port of the driver samples from the original Windows Driver Samples on Github.
The repository provides examples and best practices for Windows driver development in Rust using crates from windows-drivers-rs.
- Set up EWDK Build Environment.
- Install Clang.
- Install Rust.
Run the following commands after setting up Rust.
rustup toolchain add nightly-msvc
cargo install cargo-make --no-default-features --features tls-native
Note on arm64: ARM64 support for ring is not released yet, so TLS features must be disabled until arm64 is officially supported by ring (probably in 0.17.0 release)
These are not-required, but may make it easier to work in a rust environment:
cargo install cargo-expand
cargo install cargo-edit
cargo install cargo-workspaces
Use cargo doc --document-private-items --open
to compile and open documentation
From an EWDK development command prompt, run:
cargo make
If build is successful, this will stamp the INF and create a CAT file placed with driver binary and INF in Package
folder.
- Copy the following to the DUT (Device Under Test: the computer you want to test the driver on):
.\target\..configuration..\package
Path\To\Driver\DriverCertificate.cer
- The version of
devgen.exe
from the WDK Developer Tools that matches the archtecture of your DUT
- Ex.
C:\Program Files\Windows Kits\10\Tools\10.0.22621.0\x64\devgen.exe
- Install the Certificate on the DUT:
- Double click the certificate
- Click Install Certificate
- Select a Store Location (Either Store Location is Fine) -> Next
- Place all certificates in the following Store -> Browse -> Trusted Root Certification Authorities -> Ok -> Next
- Finish
- Install the driver:
- In the package directory, run:
pnputil.exe /add-driver echo_2.inf /install
- In the package directory, run:
- Create a software device:
- In the directory that
devgen.exe
was copied to, run:devgen.exe /add /hardwareid "root\ECHO_2"
- In the directory that
- To capture prints:
- Start DebugView
- Enable
Capture Kernel
- Enable
Enable Verbose Kernel Output
- Enable
- Alternatively, you can see prints in an active Windbg session.
- Attach WinDBG
ed nt!Kd_DEFAULT_Mask 0xFFFFFFFF
- Start DebugView
The echo driver can be tested by using the echo executable
-
Echoapp.exe --- Send single write and read request synchronously
-
Echoapp.exe -Async --- Send 100 reads and writes asynchronously
Exit the app anytime by pressing Ctrl-C
Take a look at the compilation of the new and changed driver-related content for Windows 11. Areas of improvement include camera, print, display, Near Field Communication (NFC), WLAN, Bluetooth, and more.
Find out what's new in the WDK
The Windows Driver Frameworks (WDF) are a set of libraries that make it simple to write high-quality device drivers.
Use the samples in this repo to guide your Windows driver development. Whether you're just getting started or porting an older driver to the newest version of Windows, code samples are valuable guides on how to write drivers.
For information about important changes that need to be made to the WDK sample drivers before releasing device drivers based on the sample code, see the following topic:
From Sample Code to Production Driver - What to Change in the Samples
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.