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
- Easy install option:
- Install the latest version from link
- Expand the ISO image to c:\ewdk
- Start Environment by running in command prompt:
c:\ewdk\LaunchBuildEnv.cmd
- Easy install option:
-
Install Clang
- Easy install option:
winget install LLVM.LLVM
- Easy install option:
-
Install Rust
- Easy install option for x64 systems:
Invoke-RestMethod -Uri "https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe" -OutFile "$env:USERPROFILE\Downloads\rustup-init.exe"
& "$env:USERPROFILE\Downloads\rustup-init.exe" -y
Run the following commands after setting up Rust.
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-edit cargo-workspaces
cargo doc --document-private-items --open
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.
-
If Bitlocker is enabled, suspend Bitlocker Example:
manage-bde -protectors -disable C:
-
Turn off Secure Boot via your UEFI/BIOS Settings Example:
shutdown -r -o -t 0
then pick Advanced -> UEFI Settings -
If Bitlocker is enabled, suspend Bitlocker again Example:
manage-bde -protectors -disable C:
-
Turn on test signing
bcdedit /set testsigning on
-
Reboot
shutdown -r -t 0
-
Copy the following to the DUT (Device Under Test: the computer you want to test the driver on):
- The driver
package
folder located in the Cargo Output Directory. The Cargo Output Directory changes based off of build profile, target architecture, etc.
- Ex.
<REPO_ROOT>\target\x86_64-pc-windows-msvc\debug\package
,<REPO_ROOT>\target\x86_64-pc-windows-msvc\release\package
,<REPO_ROOT>\target\aarch64-pc-windows-msvc\debug\package
,<REPO_ROOT>\target\aarch64-pc-windows-msvc\release\package
,<REPO_ROOT>\target\debug\package
,<REPO_ROOT>\target\release\package
- The version of
devgen.exe
from the WDK Developer Tools that matches the archtecture of your DUT
- Ex.
C:\ewdk\Program Files\Windows Kits\10\Tools\10.0.22621.0\x64\devgen.exe
- The driver
-
Install the Certificate on the DUT:
- Double click the certificate
- Click Install Certificate
- Store Location: Local Machine -> Next
- Place all certificates in the following Store -> Browse -> Trusted Root Certification Authorities -> Ok -> Next
- Repeat 2-4 for Store -> Browse -> Trusted Publishers -> Ok -> Next
- Finish
-
Install the driver from Admin Command Prompt:
- In the package directory, run:
pnputil.exe /add-driver echo_2.inf /install
- In the package directory, run:
-
Create a software device from Admin Command Prompt:
- 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 included sample app.
-
cargo run --bin echoapp
- Send single write and read request synchronously
-
cargo run --bin echoapp -- -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.