fix bsod analyse (half)

This commit is contained in:
Julian Freeman
2025-11-26 19:10:50 -04:00
parent 4fe4150069
commit ea3bdd80e0
4 changed files with 201 additions and 280 deletions

267
src-tauri/Cargo.lock generated
View File

@@ -280,24 +280,6 @@ dependencies = [
"piper", "piper",
] ]
[[package]]
name = "breakpad-symbols"
version = "0.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b002797414ffc34425bdf5b21a9e50d102013292625749eeba0a59923176ab05"
dependencies = [
"async-trait",
"cachemap2",
"circular",
"debugid",
"futures-util",
"minidump-common",
"nom",
"range-map",
"thiserror 1.0.69",
"tracing",
]
[[package]] [[package]]
name = "brotli" name = "brotli"
version = "8.0.2" version = "8.0.2"
@@ -346,12 +328,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "cachemap2"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7bba2f68a9fefca870fed897de7c655f9d5c1eaf1cd9517db96c9a3861f648b"
[[package]] [[package]]
name = "cairo-rs" name = "cairo-rs"
version = "0.18.5" version = "0.18.5"
@@ -482,12 +458,6 @@ dependencies = [
"windows-link 0.2.1", "windows-link 0.2.1",
] ]
[[package]]
name = "circular"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0fc239e0f6cb375d2402d48afb92f76f5404fd1df208a41930ec81eda078bea"
[[package]] [[package]]
name = "combine" name = "combine"
version = "4.6.7" version = "4.6.7"
@@ -615,31 +585,6 @@ version = "0.8.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
[[package]]
name = "crossterm"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df"
dependencies = [
"bitflags 2.10.0",
"crossterm_winapi",
"libc",
"mio 0.8.11",
"parking_lot",
"signal-hook",
"signal-hook-mio",
"winapi",
]
[[package]]
name = "crossterm_winapi"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b"
dependencies = [
"winapi",
]
[[package]] [[package]]
name = "crypto-common" name = "crypto-common"
version = "0.1.7" version = "0.1.7"
@@ -677,6 +622,27 @@ dependencies = [
"syn 2.0.111", "syn 2.0.111",
] ]
[[package]]
name = "csv"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52cd9d68cf7efc6ddfaaee42e7288d3a99d613d4b50f76ce9827ae0c6e14f938"
dependencies = [
"csv-core",
"itoa",
"ryu",
"serde_core",
]
[[package]]
name = "csv-core"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "704a3c26996a80471189265814dbc2c257598b96b8a7feae2d31ace646bb9782"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "ctor" name = "ctor"
version = "0.2.9" version = "0.2.9"
@@ -906,6 +872,15 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "encoding_rs_io"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cc3c5651fb62ab8aa3103998dade57efdd028544bd300516baa31840c252a83"
dependencies = [
"encoding_rs",
]
[[package]] [[package]]
name = "endi" name = "endi"
version = "1.1.0" version = "1.1.0"
@@ -2107,48 +2082,6 @@ dependencies = [
"smart-default", "smart-default",
] ]
[[package]]
name = "minidump-processor"
version = "0.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76b49bde7c0ae9a7142c540c27c7fc29db2288fd9614f11a9ce57badeb74af43"
dependencies = [
"async-trait",
"breakpad-symbols",
"debugid",
"futures-util",
"memmap2",
"minidump",
"minidump-common",
"minidump-unwind",
"scroll",
"serde",
"serde_json",
"thiserror 1.0.69",
"tracing",
"yaxpeax-x86",
]
[[package]]
name = "minidump-unwind"
version = "0.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63aef4cd2e018881680b152296ae28e674242823faa1767b417b6669a1896cdc"
dependencies = [
"async-trait",
"breakpad-symbols",
"minidump",
"minidump-common",
"scroll",
"tracing",
]
[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.8.9" version = "0.8.9"
@@ -2159,18 +2092,6 @@ dependencies = [
"simd-adler32", "simd-adler32",
] ]
[[package]]
name = "mio"
version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c"
dependencies = [
"libc",
"log",
"wasi 0.11.1+wasi-snapshot-preview1",
"windows-sys 0.48.0",
]
[[package]] [[package]]
name = "mio" name = "mio"
version = "1.1.0" version = "1.1.0"
@@ -2258,16 +2179,6 @@ version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
[[package]]
name = "nom"
version = "7.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
dependencies = [
"memchr",
"minimal-lexical",
]
[[package]] [[package]]
name = "ntapi" name = "ntapi"
version = "0.4.1" version = "0.4.1"
@@ -3569,27 +3480,6 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "signal-hook"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d881a16cf4426aa584979d30bd82cb33429027e42122b169753d6ef1085ed6e2"
dependencies = [
"libc",
"signal-hook-registry",
]
[[package]]
name = "signal-hook-mio"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b75a19a7a740b25bc7944bdee6172368f988763b744e3d4dfe753f6b4ece40cc"
dependencies = [
"libc",
"mio 0.8.11",
"signal-hook",
]
[[package]] [[package]]
name = "signal-hook-registry" name = "signal-hook-registry"
version = "1.4.7" version = "1.4.7"
@@ -3827,8 +3717,10 @@ name = "system-doctor"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"chrono", "chrono",
"csv",
"encoding_rs",
"encoding_rs_io",
"minidump", "minidump",
"minidump-processor",
"serde", "serde",
"serde_json", "serde_json",
"sysinfo", "sysinfo",
@@ -4263,7 +4155,7 @@ checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408"
dependencies = [ dependencies = [
"bytes", "bytes",
"libc", "libc",
"mio 1.1.0", "mio",
"parking_lot", "parking_lot",
"pin-project-lite", "pin-project-lite",
"signal-hook-registry", "signal-hook-registry",
@@ -5131,15 +5023,6 @@ dependencies = [
"windows-targets 0.42.2", "windows-targets 0.42.2",
] ]
[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets 0.48.5",
]
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.59.0" version = "0.59.0"
@@ -5182,21 +5065,6 @@ dependencies = [
"windows_x86_64_msvc 0.42.2", "windows_x86_64_msvc 0.42.2",
] ]
[[package]]
name = "windows-targets"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [
"windows_aarch64_gnullvm 0.48.5",
"windows_aarch64_msvc 0.48.5",
"windows_i686_gnu 0.48.5",
"windows_i686_msvc 0.48.5",
"windows_x86_64_gnu 0.48.5",
"windows_x86_64_gnullvm 0.48.5",
"windows_x86_64_msvc 0.48.5",
]
[[package]] [[package]]
name = "windows-targets" name = "windows-targets"
version = "0.52.6" version = "0.52.6"
@@ -5254,12 +5122,6 @@ version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]] [[package]]
name = "windows_aarch64_gnullvm" name = "windows_aarch64_gnullvm"
version = "0.52.6" version = "0.52.6"
@@ -5278,12 +5140,6 @@ version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]] [[package]]
name = "windows_aarch64_msvc" name = "windows_aarch64_msvc"
version = "0.52.6" version = "0.52.6"
@@ -5302,12 +5158,6 @@ version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
[[package]]
name = "windows_i686_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]] [[package]]
name = "windows_i686_gnu" name = "windows_i686_gnu"
version = "0.52.6" version = "0.52.6"
@@ -5338,12 +5188,6 @@ version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
[[package]]
name = "windows_i686_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]] [[package]]
name = "windows_i686_msvc" name = "windows_i686_msvc"
version = "0.52.6" version = "0.52.6"
@@ -5362,12 +5206,6 @@ version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]] [[package]]
name = "windows_x86_64_gnu" name = "windows_x86_64_gnu"
version = "0.52.6" version = "0.52.6"
@@ -5386,12 +5224,6 @@ version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]] [[package]]
name = "windows_x86_64_gnullvm" name = "windows_x86_64_gnullvm"
version = "0.52.6" version = "0.52.6"
@@ -5410,12 +5242,6 @@ version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]] [[package]]
name = "windows_x86_64_msvc" name = "windows_x86_64_msvc"
version = "0.52.6" version = "0.52.6"
@@ -5549,31 +5375,6 @@ dependencies = [
"pkg-config", "pkg-config",
] ]
[[package]]
name = "yaxpeax-arch"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f005c964432a1f9ee04598e094a3eb5f7568f6b33e89a2762d7bef6fbe8b255"
dependencies = [
"crossterm",
"num-traits",
"serde",
"serde_derive",
]
[[package]]
name = "yaxpeax-x86"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9107477944697db42c41326f82d4c65b769b32512cdad1e086f36f0e0f25ff45"
dependencies = [
"cfg-if",
"num-traits",
"serde",
"serde_derive",
"yaxpeax-arch",
]
[[package]] [[package]]
name = "yoke" name = "yoke"
version = "0.8.1" version = "0.8.1"

View File

@@ -27,7 +27,11 @@ wmi = "0.13"
chrono = { version = "0.4", features = ["serde"] } chrono = { version = "0.4", features = ["serde"] }
tokio = { version = "1", features = ["full"] } tokio = { version = "1", features = ["full"] }
minidump = "0.19" minidump = "0.19"
minidump-processor = "0.19" # [新增] 用于解析 BlueScreenView 导出的 CSV
csv = "1.3"
# [新增] 用于处理可能的文件编码问题
encoding_rs = "0.8"
encoding_rs_io = "0.1"
[features] [features]
# this feature is used for production builds or when `devPath` points to the filesystem # this feature is used for production builds or when `devPath` points to the filesystem

View File

@@ -9,7 +9,8 @@ use sysinfo::{System, Disks};
use wmi::{COMLibrary, WMIConnection}; use wmi::{COMLibrary, WMIConnection};
use std::fs; use std::fs;
use std::path::Path; use std::path::Path;
use std::io::Read; // [新增] 用于读取文件头 use std::io::Read;
use std::process::Command;
use tauri::Emitter; use tauri::Emitter;
use chrono::{Duration, FixedOffset, Local, NaiveDate, TimeZone, DateTime}; use chrono::{Duration, FixedOffset, Local, NaiveDate, TimeZone, DateTime};
use minidump::{Minidump, MinidumpException, MinidumpSystemInfo}; use minidump::{Minidump, MinidumpException, MinidumpSystemInfo};
@@ -154,7 +155,7 @@ fn translate_bugcheck_u32(code: u32) -> (String, String) {
), ),
0x00000124 => ( 0x00000124 => (
"WHEA_UNCORRECTABLE_ERROR (0x124)".to_string(), "WHEA_UNCORRECTABLE_ERROR (0x124)".to_string(),
"硬件发生无法纠正的物理错误。这是纯硬件故障。通常是 CPU 电压不足、超频失败、过热,或者主板/PCIe设备(如 NVMe 硬盘)故障。" "硬件发生无法纠正的物理错误。这是纯硬件故障。通常是 CPU 电压不足、超频失败、过热,或者主板/PCIe设备故障。"
.to_string(), .to_string(),
), ),
0x00000116 => ( 0x00000116 => (
@@ -184,13 +185,21 @@ fn translate_bugcheck_u32(code: u32) -> (String, String) {
), ),
_ => ( _ => (
format!("未知错误代码: 0x{:X}", code), format!("未知错误代码: 0x{:X}", code),
"请尝试在搜索引擎中搜索此错误代码。通用建议:更新驱动、检查内存、扫描病毒。".to_string(), "建议手动搜索此错误代码。通用建议:更新驱动、检查内存、扫描病毒。".to_string(),
), ),
} }
} }
// [公共逻辑] 泛型函数,适配文件和内存 fn translate_bugcheck_str(code_str: &str) -> (String, String) {
fn analyze_dump_data<T>(dump: Minidump<T>) -> Result<BsodAnalysisReport, String> let clean_code = code_str.trim().replace("0x", "");
if let Ok(code) = u32::from_str_radix(&clean_code, 16) {
return translate_bugcheck_u32(code);
}
(format!("错误代码: {}", code_str), "无法识别的错误代码,建议手动搜索。".to_string())
}
// [公共逻辑] Rust 原生分析
fn analyze_dump_data_native<T>(dump: Minidump<T>) -> Result<BsodAnalysisReport, String>
where T: Deref<Target = [u8]> where T: Deref<Target = [u8]>
{ {
let (exception_code, exception_address) = match dump.get_stream::<MinidumpException>() { let (exception_code, exception_address) = match dump.get_stream::<MinidumpException>() {
@@ -206,44 +215,106 @@ where T: Deref<Target = [u8]>
Err(_) => "Unknown OS".to_string(), Err(_) => "Unknown OS".to_string(),
}; };
let (reason_str, recommend) = if exception_code != 0 { if exception_code == 0 {
translate_bugcheck_u32(exception_code) return Err("未找到异常记录".to_string());
} else { }
("未找到异常记录".to_string(), "该文件有效但未包含标准异常流。可能是手动生成的 Dump 或被截断。".to_string())
}; let (reason_str, recommend) = translate_bugcheck_u32(exception_code);
Ok(BsodAnalysisReport { Ok(BsodAnalysisReport {
crash_reason: reason_str, crash_reason: reason_str,
crash_address: format!("0x{:X}", exception_address), crash_address: format!("0x{:X}", exception_address),
bug_check_code: format!("0x{:X} ({})", exception_code, sys_info_str), bug_check_code: format!("0x{:X} ({})", exception_code, sys_info_str),
crashing_thread: None, crashing_thread: None,
human_analysis: "根据错误代码自动匹配的分析结果".to_string(), human_analysis: "通过 Rust 原生库分析得出".to_string(),
recommendation: recommend, recommendation: recommend,
}) })
} }
// [新增] 辅助函数:检查文件头签名 // [修复] BlueScreenView 外部调用分析 (使用 CSV crate 解析)
fn check_dump_signature(sig: &[u8]) -> Result<(), String> { fn analyze_with_bluescreenview(dump_path: &Path) -> Result<BsodAnalysisReport, String> {
if sig.len() < 4 { let bsv_exe = "BlueScreenView.exe";
return Err("文件太小,无效的 Dump 文件。".to_string());
let mut temp_csv_path = std::env::temp_dir();
temp_csv_path.push(format!("bsod_report_{}.csv", chrono::Utc::now().timestamp_millis()));
let status = Command::new(bsv_exe)
.arg("/LoadFrom")
.arg(dump_path.to_string_lossy().to_string())
.arg("/scomma")
.arg(temp_csv_path.to_string_lossy().to_string())
.status();
if status.is_err() {
return Err("未找到 BlueScreenView.exe无法分析内核转储文件。请将 BlueScreenView.exe 放入程序目录。".to_string());
} }
// 1. 检查标准 Minidump (MDMP) // 读取字节并转为 String (lossy 模式,防止 GBK/ANSI 乱码导致 panic)
if sig.starts_with(b"MDMP") { let content_bytes = fs::read(&temp_csv_path).map_err(|_| "BlueScreenView 分析未生成有效数据。".to_string())?;
return Ok(()); let _ = fs::remove_file(temp_csv_path);
let content = String::from_utf8_lossy(&content_bytes);
// 使用 csv crate 解析
let mut rdr = csv::ReaderBuilder::new()
.has_headers(false) // 命令行模式可能没有表头,或者我们手动处理
.from_reader(content.as_bytes());
for result in rdr.records() {
if let Ok(record) = result {
// BlueScreenView 的列索引通常是:
// 0: Dump File
// 1: Crash Time
// 2: Bug Check String
// 3: Bug Check Code
// ...
// 8: Caused By Driver (关键列)
// ...
// 15: Crash Address (可能位置)
// 我们至少需要前9列才能提供有意义的信息
if record.len() >= 9 {
// 跳过可能的表头行
if &record[0] == "Dump File" { continue; }
let bug_check_string = &record[2];
let bug_check_code = &record[3];
let caused_by_driver = &record[8]; // Index 8 是最常见的 Caused By Driver 位置
// 尝试获取崩溃地址,如果不够长就填 N/A
let crash_addr = if record.len() > 15 { &record[15] } else { "N/A" };
let (human, recommend) = translate_bugcheck_str(bug_check_code);
// 优先使用 Bug Check String如果为空则使用翻译结果
let final_reason = if !bug_check_string.is_empty() { bug_check_string.to_string() } else { human };
return Ok(BsodAnalysisReport {
crash_reason: final_reason,
crash_address: crash_addr.to_string(),
bug_check_code: bug_check_code.to_string(),
crashing_thread: Some(format!("Driver: {}", caused_by_driver)),
human_analysis: format!("BlueScreenView 分析结果:崩溃可能由驱动程序 [{}] 引起。", caused_by_driver),
recommendation: recommend,
});
}
}
} }
// 2. 检查 Kernel Dump (PAGE / PAGEDU64) Err("BlueScreenView 输出为空或未能解析到有效列(文件可能已损坏)。".to_string())
// 即使文件很小,只要头是 PAGE它就是 Kernel Dump 格式minidump crate 无法解析
if sig.starts_with(b"PAGE") {
return Err("不支持的文件格式:检测到 '内核转储' (PAGEDU64/PAGE)。".to_string());
} }
Err(format!( // 辅助函数:检查文件头签名并返回类型
"文件签名错误!期望 'MDMP', 实际收到: {:02X?} ('{}')。\n这可能不是一个有效的蓝屏文件。", enum DumpType {
&sig[0..4], Minidump,
String::from_utf8_lossy(&sig[0..4]).replace('\0', "") KernelDump, // PAGEDU64 / PAGE
)) Unknown,
}
fn check_dump_signature(sig: &[u8]) -> DumpType {
if sig.len() < 4 { return DumpType::Unknown; }
if sig.starts_with(b"MDMP") { return DumpType::Minidump; }
if sig.starts_with(b"PAGE") { return DumpType::KernelDump; }
DumpType::Unknown
} }
// --- 命令:列出 Minidump 文件 --- // --- 命令:列出 Minidump 文件 ---
@@ -286,34 +357,79 @@ async fn list_minidumps() -> Result<Vec<BsodFileItem>, String> {
async fn analyze_minidump(filepath: String) -> Result<BsodAnalysisReport, String> { async fn analyze_minidump(filepath: String) -> Result<BsodAnalysisReport, String> {
let path = Path::new(&filepath); let path = Path::new(&filepath);
// [优化] 先读取头部进行校验,避免 minidump 库报晦涩错误
let mut file = fs::File::open(path).map_err(|e| format!("无法打开文件: {}", e))?; let mut file = fs::File::open(path).map_err(|e| format!("无法打开文件: {}", e))?;
let mut header = [0u8; 4]; let mut header = [0u8; 4];
if let Ok(_) = file.read_exact(&mut header) {
check_dump_signature(&header)?; let dump_type = if let Ok(_) = file.read_exact(&mut header) {
check_dump_signature(&header)
} else {
DumpType::Unknown
};
match dump_type {
DumpType::Minidump => {
if let Ok(dump) = Minidump::read_path(path) {
if let Ok(report) = analyze_dump_data_native(dump) {
return Ok(report);
}
}
analyze_with_bluescreenview(path)
},
DumpType::KernelDump => {
analyze_with_bluescreenview(path)
},
DumpType::Unknown => Err("无效的文件签名。不是有效的 Windows Dump 文件。".to_string())
}
} }
// 重新读取完整文件 (minidump crate 需要完整路径重新打开) // [修复] 命令:分析二进制内容的 Minidump
let dump = Minidump::read_path(path).map_err(|e| format!("解析错误: {}", e))?;
analyze_dump_data(dump)
}
// --- 命令:分析二进制内容的 Minidump ---
#[tauri::command] #[tauri::command]
async fn analyze_minidump_bytes(file_content: Vec<u8>) -> Result<BsodAnalysisReport, String> { async fn analyze_minidump_bytes(file_content: Vec<u8>) -> Result<BsodAnalysisReport, String> {
// [优化] 头部校验 if file_content.is_empty() {
check_dump_signature(&file_content)?; return Err("导入的文件内容为空".to_string());
}
let dump = Minidump::read(file_content).map_err(|e| format!("解析器拒绝处理: {}", e))?; let dump_type = check_dump_signature(&file_content);
analyze_dump_data(dump)
match dump_type {
DumpType::Minidump => {
// [修复] 先将 Minidump::read 错误转为 String确保链式调用类型一致
let native_result = Minidump::read(file_content.clone())
.map_err(|e| e.to_string())
.and_then(|dump| analyze_dump_data_native(dump));
if let Ok(report) = native_result {
return Ok(report);
}
// 失败回退到 BSV
},
DumpType::KernelDump => {
// 直接回退
},
DumpType::Unknown => return Err("无效的文件签名。请确认这是 .dmp 文件。".to_string())
}
// --- 回退流程:写入临时文件调用 BlueScreenView ---
let mut temp_dump_path = std::env::temp_dir();
temp_dump_path.push(format!("temp_dump_{}.dmp", chrono::Utc::now().timestamp_millis()));
// 既然上面判断文件有效,这里大概率可以写入
if let Err(_) = fs::write(&temp_dump_path, &file_content) {
return Err("无法写入临时文件进行分析".to_string());
}
let bsv_result = analyze_with_bluescreenview(&temp_dump_path);
let _ = fs::remove_file(temp_dump_path);
bsv_result
} }
// --- 现有命令run_diagnosis (保持不变) --- // --- 现有命令run_diagnosis (保持不变) ---
#[tauri::command] #[tauri::command]
async fn run_diagnosis(window: tauri::Window) -> Result<(), String> { async fn run_diagnosis(window: tauri::Window) -> Result<(), String> {
std::thread::spawn(move || { std::thread::spawn(move || {
// ... (保持原有逻辑不变) ... // ... (保持原有逻辑不变,占位符) ...
// 占位符
{ {
let mut sys = System::new(); let mut sys = System::new();
sys.refresh_memory(); sys.refresh_memory();

View File

@@ -13,8 +13,8 @@
"windows": [ "windows": [
{ {
"title": "system-doctor", "title": "system-doctor",
"width": 800, "width": 1200,
"height": 600 "height": 800
} }
], ],
"security": { "security": {