Skip to content

Commit 84ea34b

Browse files
committed
refactor: sysdemo 使用 driver-framework,重构错误处理
- sysdemo 移除重复代码,改用 driver-framework - 删除 constants.rs, device.rs, dispatch.rs, ffi.rs, logger.rs, utils.rs - 添加 IRP_MJ_CREATE/CLOSE 处理函数修复驱动加载问题 - provider.go 添加 Incorrect function 错误检测和处理 - 添加 sysdemo/build.ps1 构建脚本
1 parent f2e19d8 commit 84ea34b

13 files changed

Lines changed: 220 additions & 382 deletions

File tree

debugger/driver/provider.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,13 @@ func (p *Provider) Start() {
179179
mylog.Info("这通常是因为 Rust 驱动程序实现有问题")
180180
mylog.Info("请检查驱动程序的参数处理逻辑")
181181
mylog.Check(e)
182-
default:
182+
case e.Error() == "Incorrect function.":
183+
mylog.Info("错误,函数不正确")
184+
mylog.Info("这通常是因为 Rust 驱动程序缺少 IRP_MJ_CREATE 或 IRP_MJ_CLOSE 处理函数")
185+
mylog.Info("请检查驱动程序的 MajorFunction 是否正确设置")
183186
mylog.Check(e)
187+
default:
188+
mylog.Check(e) //Incorrect function. rust问题
184189
}
185190
} else {
186191
mylog.Success("驱动启动成功")

rust-driver/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust-driver/examples/sysdemo/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ wdk = "0.4"
2020
wdk-alloc = "0.4"
2121
wdk-panic = "0.4"
2222
wdk-sys = "0.5"
23+
driver-framework = { path = "../../driver-framework" }
2324

2425
[features]
2526
default = []
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Rust 驱动构建脚本 - sysdemo
2+
3+
$ErrorActionPreference = "Stop"
4+
5+
$SCRIPT_DIR = Split-Path -Parent $MyInvocation.MyCommand.Path
6+
Set-Location $SCRIPT_DIR
7+
$WDK_PATH = "E:\Program Files\Windows Kits\10"
8+
$EWDK_ISO_PATH = "D:\Admin\vs2022VC\EWDK_br_release_28000_251103-1709.iso"
9+
$EWDK_MOUNT_LETTER = "E:"
10+
$EWDK_BUILD_ENV = "$EWDK_MOUNT_LETTER\BuildEnv\SetupBuildEnv.cmd"
11+
12+
Write-Host "=== sysdemo 驱动构建脚本 ===" -ForegroundColor Cyan
13+
Write-Host ""
14+
Write-Host "脚本目录: $SCRIPT_DIR" -ForegroundColor Green
15+
Write-Host ""
16+
17+
# ============================================
18+
# 注册表配置
19+
# ============================================
20+
Write-Host "配置注册表路径..." -ForegroundColor Yellow
21+
22+
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows Kits\Installed Roots"
23+
$regValue = Get-ItemProperty -Path $regPath -Name "KitsRoot10" -ErrorAction SilentlyContinue
24+
25+
if ($null -eq $regValue) {
26+
New-ItemProperty -Path $regPath -Name "KitsRoot10" -Value "$WDK_PATH\\"" -PropertyType String -Force | Out-Null
27+
} else {
28+
Set-ItemProperty -Path $regPath -Name "KitsRoot10" -Value "$WDK_PATH\\"" -Force | Out-Null
29+
}
30+
31+
$regPathWow = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows Kits\Installed Roots"
32+
$regValueWow = Get-ItemProperty -Path $regPathWow -Name "KitsRoot10" -ErrorAction SilentlyContinue
33+
34+
if ($null -eq $regValueWow) {
35+
New-ItemProperty -Path $regPathWow -Name "KitsRoot10" -Value "$WDK_PATH\\"" -PropertyType String -Force | Out-Null
36+
} else {
37+
Set-ItemProperty -Path $regPathWow -Name "KitsRoot10" -Value "$WDK_PATH\\"" -Force | Out-Null
38+
}
39+
40+
Write-Host "注册表配置完成" -ForegroundColor Green
41+
Write-Host ""
42+
43+
# ============================================
44+
# 设置 EWDK 构建环境
45+
# ============================================
46+
Write-Host "设置 EWDK 构建环境..." -ForegroundColor Yellow
47+
48+
if (-not (Test-Path $EWDK_MOUNT_LETTER)) {
49+
Mount-DiskImage -ImagePath $EWDK_ISO_PATH -StorageType ISO -ErrorAction SilentlyContinue
50+
}
51+
52+
& $EWDK_BUILD_ENV | Out-Null
53+
54+
$WDK_VERSION = "10.0.28000.0"
55+
$WDK_BIN = "$WDK_PATH\bin\$WDK_VERSION"
56+
$MSVC_BIN = "E:\Program Files\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64"
57+
58+
$env:WDKContentRoot = $WDK_PATH
59+
$env:PATH = "$WDK_BIN\x64;$MSVC_BIN;$env:PATH"
60+
61+
Write-Host ""
62+
63+
# ============================================
64+
# 配置构建环境
65+
# ============================================
66+
Write-Host "配置构建环境..." -ForegroundColor Yellow
67+
68+
$env:LIB = "$WDK_PATH\Lib\$WDK_VERSION\um\x64;$WDK_PATH\Lib\$WDK_VERSION\ucrt\x64;E:\Program Files\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\lib\x64"
69+
$env:RUSTFLAGS = "-C target-feature=+crt-static"
70+
$env:CARGO_CFG_TARGET_FEATURE = "cmpxchg16b,crt-static,fxsr,sse,sse2,sse3"
71+
72+
Write-Host ""
73+
74+
# ============================================
75+
# 编译项目
76+
# ============================================
77+
Write-Host "=== 编译 sysdemo ===" -ForegroundColor Cyan
78+
79+
cargo build --release --target x86_64-pc-windows-msvc
80+
81+
if ($LASTEXITCODE -eq 0) {
82+
Write-Host "sysdemo 编译成功!" -ForegroundColor Green
83+
84+
$workspaceTarget = "d:\ux\examples\hypedbg\rust-driver\target\x86_64-pc-windows-msvc\release"
85+
$dllPath = "$workspaceTarget\sysdemo.dll"
86+
$sysPath = "$workspaceTarget\sysdemo.sys"
87+
$localSysPath = "$SCRIPT_DIR\sysdemo.sys"
88+
89+
if (Test-Path $dllPath) {
90+
if (Test-Path $sysPath) {
91+
Remove-Item -Path $sysPath -Force -ErrorAction SilentlyContinue
92+
}
93+
Rename-Item -Path $dllPath -NewName "sysdemo.sys" -Force
94+
Write-Host "重命名 sysdemo.dll 为 sysdemo.sys" -ForegroundColor Yellow
95+
96+
if (Test-Path $localSysPath) {
97+
Remove-Item -Path $localSysPath -Force -ErrorAction SilentlyContinue
98+
}
99+
Copy-Item -Path $sysPath -Destination $localSysPath -Force
100+
Write-Host "复制 sysdemo.sys 到本地目录" -ForegroundColor Yellow
101+
}
102+
103+
Write-Host ""
104+
Write-Host "=== 构建完成 ===" -ForegroundColor Green
105+
Write-Host "请等待驱动签名后再进行测试..." -ForegroundColor Yellow
106+
} else {
107+
Write-Error "sysdemo 编译失败"
108+
exit 1
109+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func main() {
2727
}
2828

2929
func run () {
30-
p := driver.New("D:\\ux\\examples\\hypedbg\\rust-driver\\examples\\sysdemo\\target\\x86_64-pc-windows-msvc\\release\\sysdemo.sys", "sysDemo", "\\\\.\\sysDemo")
30+
p := driver.New(`D:\ux\examples\hypedbg\rust-driver\examples\sysdemo\sysdemo.sys`, "sysDemo", "\\\\.\\sysDemo")
3131

3232
p.Install()
3333
p.Start()

rust-driver/examples/sysdemo/src/constants.rs

Lines changed: 0 additions & 4 deletions
This file was deleted.

rust-driver/examples/sysdemo/src/device.rs

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)