news 2026/4/3 4:43:46

Windows驱动开发之HelloWorld

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Windows驱动开发之HelloWorld

Windows驱动开发之HelloWorld
1)Windows驱动开发介绍
Windows驱动开发衔接应用层与内核层,核心区分ring3(用户态,MFC,Win32等应用程序运行层,权限受限且受系统严格管控)与ring0(内核态,驱动程序运行层,拥有系统最高权限,可直接访问硬件与内存)。不同于上层应用聚焦业务功能实现,驱动开发需直面硬件交互,内存管理,中断处理等底层核心逻辑,是打通软件指令与硬件执行的关键技术桥梁。


2)NT/WDM/WDF/KWDF/UWDF常见的驱动开发介绍
NT:基础型内核模式驱动框架,面向核心系统功能开发;
WDM:支持热插拔机制,适配即插即用设备的驱动开发标准;
WDF/KWDF/UWDF:
WDF(WindowsDriverFoundation)为驱动开发提供封装框架,简化底层操作,开发者仅需调用封装接口即可完成核心逻辑开发;但安全领域的驱动开发需尽量贴近底层实现,而非单纯依赖框架封装。其核心采用事件驱动机制,通过回调函数响应设备事件,类似上层开发中专注业务逻辑的开发模式。
KWDF:面向内核模式的WDF子框架,适配内核态驱动开发;
UWDF:面向用户模式的WDF子框架,适用于摄像头,USB等外设驱动开发,需掌握COM组件相关知识。


3)程序开发流程
1.VS2022开发去驱动开发的组件:VisualStudioInstaller,找到需要安装的64latestspectre和WindowsDriverkit安装就行。
2.安装驱动开发SDK:打开这个地址下载SDK安装包https://learn.microsoft.com/en-us/windows/apps/windows-sdk/downloads
3.安装驱动开发WDK:这个地址下载WDK安装包https://learn.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk
4.VS2022新建一个项目:使用VS2022新建一个EmptyWDMDriver项目,项目建好,添加一个main.c文件就行。
5.使用工具:DebugView,KmdManager,或者自己写驱动加载器。


4)代码示例
/*
Create device object
admin run winobj.exe -> Device -> Name find my device
winobj check device symbol name
https://learn.microsoft.com/zh-cn/sysinternals/downloads/winobj

1)Fist sys
vs2022->propertys->c/c++->General->Treat Warnings As Errors -> No(/WX-)
vmware win10 cmd

Show error
windows blocked the installtaion of a digitally unsigned driver
bcdedit /set testsigning on
or
gpedit.msc
Administrative Templates -> System -> Driver Installation -> Code signing for device drivers->Ignore

DebugView.zip


2) debug windows cmd -> msconfig and copy boot use "bcdedit /copy {current} /d debug"
bcdedit /copy {current} /d debug
bcdedit /displayorder {389da118-6d83-11ee-9f7b-94002af10242} /addlast
bcdedit /dbgsettings SERIAL DEBUGPORT:1 BAUDRATE:115200
bcdedit /bootdebug {389da118-6d83-11ee-9f7b-94002af10242} ON
bcdedit /timeout 30
shutdown /r /t 0


debug sys win10
bcdedit /dbgsettings none
bcdedit /set {current} debug no
bcdedit /copy {current} /d "Myos"
bcdedit /debug on
bcdedit /dbgsettings serial debugport 1 baudrate 115200
bcdedit /set {dbgsettings} port 1
bcdedit /set {current} debug yes
bcdedit /set testsigning on
bcdedit /set nointegritychecks on
bcdedit /enum {current} /v
bcdedit /set “{current}” bootmenupolicy Legacy

msconfig -> boot Myos set Debug an set serial,port,baudrate
shutdown /r /t 0


vmware add Serial port
\\.\pipe\com_1
This end is the **server**
The other end is an application

vs2022 Device Configuration
win10
DESKTOP-D56RR44


or network error
bcdedit /debug on
bcdedit /dbgsettings net hostip:vs2022devip port:50000
bcdedit /dbgsettings net hostip:192.168.0.101 port:50000
43s86sbw2q9n.1npb68a31q4t2.2ig4ylv5tvk1w.lcgcr6ivajdf

bcdedit /dbgsettings
bcdedit /set {default} debug yes
shutdown /r /t 0
bcdedit /dbgsettings

vs2022
or
windbg
C:\Program Files (x86)\Windows Kits\10\Debuggers\x64 desktop windbg.exe - Shortcut
windbg.exe-Shortcut properties

Target input
have symbols
"C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\windbg.exe" -y SRV*E:\symbol*http://msdl.microsoft.com/download/symbols -b -k com:port=//./pipe/com_1,baud=115200,pipe
no symbols
"C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\windbg.exe" -b -k com:port=//./pipe/com_1,baud=115200,pipe
input g

Environment Variables
_NT_SYMBOL_PATH
SRV*E:\symbol* https://msdl.microsoft.com/download/symbols


windows sdk wdk
https://learn.microsoft.com/en-us/windows-hardware/drivers/other-wdk-downloads#step-2-install-the-wdk
Released with WDK and related downloads
Windows 11, Version 24H2 WDK 10.0.26100.3323 (released March 14, 2025)
Windows 11, Version 24H2 WDK 10.0.26100.2454 (released November 27, 2024)
Windows 11, Version 24H2 WDK 10.0.26100.2161 (released November 4, 2024)
Windows 11, Version 24H2 WDK 10.0.26100.1882 (released October 14, 2024)
Windows 11, Version 24H2 WDK 10.0.26100.1591 (released September 18, 2024)
Windows 11, Version 24H2 WDK 10.0.26100.1 (released May 2024)
Windows 11, Version 23H2 WDK 10.0.22621.2428 (released October 24, 2023)
Windows 11, version 22H2 WDK for Windows 11, version 22H2 (10.0.22621.382, released May 24, 2022)
Windows 11, version 21H2 WDK for Windows 11, version 21H2
Windows Server 2022 WDK for Windows Server 2022
Windows 10, version 2004 WDK for Windows 10, version 2004
Windows 10, version 1903 WDK for Windows 10, version 1903
Windows 10, version 1809
Windows Server 2019 WDK for Windows 10, version 1809
Windows 10, version 1607
Windows Server 2016 WDK for Windows 10, version 1607
Windows 8.1 Update WDK 8.1 Update (English only) - permanently unavailable
WDK 8.1 Update Test Pack (English only) - permanently unavailable
WDK 8.1 Samples

Note: You can use any WDK from Windows 10, version 1607 through Windows 11, version 21H2 to build drivers for Windows 8.1.
Windows 8 WDK 8 Samples

regedit
Computer\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BaseDriver
/* Example 1: Windows Service Startup Type (The Start value under the registry path
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\[Service Name])
0: Boot Start (Initiated by the system loader, only for core drivers)
1: System Start (Initiated by the session manager, for critical system services)
2: Automatic Start (Runs automatically after the system boots up)
3: Manual Start (Triggered by the user or other services)
4: Disabled (The service cannot be started)
*/


#include<ntddk.h>
VOIDDriverUnload(PDRIVER_OBJECTdriver);

#definePAGEDCODEcode_seg("PAGE")
NTSTATUSDriverEntry(INPDRIVER_OBJECTpDriverObject,
INPUNICODE_STRINGpRegistryPath)
{
//DbgBreakPoint();
KdBreakPoint();
DbgPrint("Hello,wewdkdirver\r\n");
KdPrint(("Hello,wewdkdirverbyKdPrint\r\n"));

DbgPrint("pRegistryPath:%wZ\r\n",pRegistryPath);

pDriverObject->DriverUnload=DriverUnload;
returnSTATUS_SUCCESS;
}

//Unloadfunction
VOIDDriverUnload(PDRIVER_OBJECTDriverObject)
{

DbgPrint("Ourdriverisunloading\r\n");
KdPrint(("OurdriverisunloadingbyKdPrint\r\n"));

}

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/2 3:56:27

计算机Java毕设实战-基于SpringBoot+Vue实现的校友录管理系统基于SpringBoot框架的”校联云桥”校友管理系统的设计与实现【完整源码+LW+部署说明+演示视频,全bao一条龙等】

博主介绍&#xff1a;✌️码农一枚 &#xff0c;专注于大学生项目实战开发、讲解和毕业&#x1f6a2;文撰写修改等。全栈领域优质创作者&#xff0c;博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java、小程序技术领域和毕业项目实战 ✌️技术范围&#xff1a;&am…

作者头像 李华
网站建设 2026/3/30 18:58:23

Swift 类型转换

Swift 类型转换 引言 Swift 是一种强大的编程语言,广泛应用于 iOS、macOS、watchOS 和 tvOS 等平台。在 Swift 中,类型转换是处理不同数据类型间关系的重要手段。本文将详细介绍 Swift 中的类型转换,包括类型检查、隐式转换、显式转换以及类型转换的最佳实践。 类型检查 …

作者头像 李华
网站建设 2026/3/28 13:32:24

Ionic 创建 APP:全面指南

Ionic 创建 APP:全面指南 引言 随着移动应用市场的不断增长,越来越多的开发者选择使用跨平台框架来创建应用程序。Ionic 是一个流行的开源框架,它允许开发者使用 HTML、CSS 和 JavaScript 来构建高性能的移动和网页应用。本文将为您提供使用 Ionic 创建 APP 的全面指南,从…

作者头像 李华
网站建设 2026/4/1 22:46:56

Node.js用perf_hooks轻松测性能

&#x1f493; 博客主页&#xff1a;瑕疵的CSDN主页 &#x1f4dd; Gitee主页&#xff1a;瑕疵的gitee主页 ⏩ 文章专栏&#xff1a;《热点资讯》 Node.js性能测量革命&#xff1a;用perf_hooks轻松实现精准性能分析目录Node.js性能测量革命&#xff1a;用perf_hooks轻松实现精…

作者头像 李华
网站建设 2026/3/29 14:05:40

Java毕设项目:基于SpringBoot和Vue的新闻发布管理系统的设计与实现(源码+文档,讲解、调试运行,定制等)

博主介绍&#xff1a;✌️码农一枚 &#xff0c;专注于大学生项目实战开发、讲解和毕业&#x1f6a2;文撰写修改等。全栈领域优质创作者&#xff0c;博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java、小程序技术领域和毕业项目实战 ✌️技术范围&#xff1a;&am…

作者头像 李华
网站建设 2026/4/1 21:35:07

融合多维特征的传统与深度学习AES系统对比研究

融合多维特征的传统与深度学习AES系统对比研究 摘要 作文自动评分(Automated Essay Scoring,AES)作为教育自然语言处理的重要应用领域,旨在通过计算模型对作文质量进行自动化评估。本研究设计并实现了一个融合多维特征的AES系统,同时构建了基于特征工程的机器学习模型和…

作者头像 李华