现充|junyu33

windows 驱动开发环境搭建

在大创的压力下,开始学习 windows 驱动开发的环境配置。只能说:

Prerequisite

Steps

install vs2022

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

install win11 SDK&WDK for 22H2

Use default, just install.

install win10 on your vm

Quite easy.

install WDK for vm

The avg download speed is 200KB/s, although the proxy/VPN is turned on, time for touching fish.

run the WDK Test Target Setup

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

ensure host&guest can ping each other

If you use vmware, I suggest using NAT so the host IP is the item of vmnet8 when running ipconfig, the guest IP is the only one IPv4 when running ipconfig. Usually the network segment is the same (i.e. the first three numbers).

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

Extensions > Driver > Test > Configure Devices > Add a new device

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

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

Wait for provisioning. Maybe the TAEF service will fail to install, just ignore it.

install the driver

Just follow the MSDN

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 works)

References