Skip to content

Latest commit

 

History

History
144 lines (98 loc) · 6.24 KB

README.md

File metadata and controls

144 lines (98 loc) · 6.24 KB

Rust Driver Samples

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.

Getting Started

Pre-requisites

Required

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

Rust Setup

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)

Optional

These are not-required, but may make it easier to work in a rust environment:

cargo install cargo-expand cargo-edit cargo-workspaces

Documentation

cargo doc --document-private-items --open

Build and Test

Build

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.

Install

One Time PC Setup

  1. If Bitlocker is enabled, suspend Bitlocker Example: manage-bde -protectors -disable C:

  2. Turn off Secure Boot via your UEFI/BIOS Settings Example: shutdown -r -o -t 0 then pick Advanced -> UEFI Settings

  3. If Bitlocker is enabled, suspend Bitlocker again Example: manage-bde -protectors -disable C:

  4. Turn on test signing bcdedit /set testsigning on

  5. Reboot shutdown -r -t 0

  6. Copy the following to the DUT (Device Under Test: the computer you want to test the driver on):

    1. 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
    1. 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
  7. Install the Certificate on the DUT:

    1. Double click the certificate
    2. Click Install Certificate
    3. Store Location: Local Machine -> Next
    4. Place all certificates in the following Store -> Browse -> Trusted Root Certification Authorities -> Ok -> Next
    5. Repeat 2-4 for Store -> Browse -> Trusted Publishers -> Ok -> Next
    6. Finish
  8. Install the driver from Admin Command Prompt:

    1. In the package directory, run: pnputil.exe /add-driver echo_2.inf /install
  9. Create a software device from Admin Command Prompt:

    1. In the directory that devgen.exe was copied to, run: devgen.exe /add /hardwareid "root\ECHO_2"

Test

  • To capture prints:
    • Start DebugView
      1. Enable Capture Kernel
      2. Enable Enable Verbose Kernel Output
    • Alternatively, you can see prints in an active Windbg session.
      1. Attach WinDBG
      2. ed nt!Kd_DEFAULT_Mask 0xFFFFFFFF

Usage

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

Windows driver development

Windows Driver Kit (WDK)

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

Windows Driver Frameworks

The Windows Driver Frameworks (WDF) are a set of libraries that make it simple to write high-quality device drivers.

WDF driver development guide

Samples

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

Trademarks

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.