现充|junyu33

Setting up Windows driver development environment

Under the pressure of the University Innovation Program, I started learning environment setup for Windows driver development. All I can say is:

Prerequisite

Steps

Install VS2022

Ensure Desktop development with C++ and MSVC v143 - VS 2022 C++ x64/x86 build tools (Latest) are ticked.

Install Windows 11 SDK & WDK for 22H2

Use default settings, proceed with installation.

Install Windows 10 on Your VM

Quite easy.

Install WDK for VM

The average download speed is 200KB/s, even though the proxy/VPN is turned on. Time for touching fish.

Run the WDK Test Target Setup

Easy, search for WDK Test Target Setup x64-x64_en-us.msi. Copy and paste.

Ensure Host & Guest Can Ping Each Other

If you are using VMware, it is recommended to use NAT mode. In this setup, the host IP corresponds to the vmnet8 adapter when running ipconfig, while the guest IP is the sole IPv4 address displayed when running ipconfig within the guest system. Typically, both will reside within the same network segment (i.e., the first three sets of digits will match).

Write & Build Your First Driver

Create a project

Follow steps from MSDN directly.

https://learn.microsoft.com/en-us/windows-hardware/drivers/gettingstarted/writing-a-very-small-kmdf--driver#create-and-build-a-driver

write a sample code

Driver.c

// https://bbs.kanxue.com/thread-254041.htm
#include <ntddk.h>
#include "Header.h"

VOID DriverUnload(PDRIVER_OBJECT driver)
{
    DbgPrint("first: Our driver is unloading…\r\n");
}

NTSTATUS DriverEntry(PDRIVER_OBJECT driver, PUNICODE_STRING reg_path)
{
#if DBG
    int_3();
#endif

    DbgPrint("first: Hello world!\r\n");

    driver->DriverUnload = DriverUnload;

    return STATUS_SUCCESS;
}

fun.asm

.CODE

int_3 PROC
	int 3
	ret
int_3 ENDP

END

Header.h

#pragma once
void int_3(void);

Build Project

Before compiling the program, you also need to set the project properties:

https://bbs.kanxue.com/thread-254041.htm

Provision Test Computer

Navigate to: Extensions > Driver > Test > Configure Devices > Add a new device

Enter the IP address of your test computer as the host name and select Provision device and choose debugger settings

On the next page, choose Network. The Host IP should be the IP address of the host computer (vmnet8).

Wait for the provisioning process to complete. Note that the TAEF service may fail to install; this can be safely ignored.

Install the Driver

Just follow the MSDN guide:

https://learn.microsoft.com/en-us/windows-hardware/drivers/gettingstarted/writing-a-very-small-kmdf--driver#install-the-driver

Debug the driver

Here are two ways:

Using WinDbg/WinDbg Preview (More Steps)

Using VS2022 (Not Always Reliable)

References