fix bsod analyse (half)
This commit is contained in:
267
src-tauri/Cargo.lock
generated
267
src-tauri/Cargo.lock
generated
@@ -280,24 +280,6 @@ dependencies = [
|
||||
"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]]
|
||||
name = "brotli"
|
||||
version = "8.0.2"
|
||||
@@ -346,12 +328,6 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cachemap2"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7bba2f68a9fefca870fed897de7c655f9d5c1eaf1cd9517db96c9a3861f648b"
|
||||
|
||||
[[package]]
|
||||
name = "cairo-rs"
|
||||
version = "0.18.5"
|
||||
@@ -482,12 +458,6 @@ dependencies = [
|
||||
"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]]
|
||||
name = "combine"
|
||||
version = "4.6.7"
|
||||
@@ -615,31 +585,6 @@ version = "0.8.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.7"
|
||||
@@ -677,6 +622,27 @@ dependencies = [
|
||||
"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]]
|
||||
name = "ctor"
|
||||
version = "0.2.9"
|
||||
@@ -906,6 +872,15 @@ dependencies = [
|
||||
"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]]
|
||||
name = "endi"
|
||||
version = "1.1.0"
|
||||
@@ -2107,48 +2082,6 @@ dependencies = [
|
||||
"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]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.8.9"
|
||||
@@ -2159,18 +2092,6 @@ dependencies = [
|
||||
"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]]
|
||||
name = "mio"
|
||||
version = "1.1.0"
|
||||
@@ -2258,16 +2179,6 @@ version = "0.1.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "ntapi"
|
||||
version = "0.4.1"
|
||||
@@ -3569,27 +3480,6 @@ version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "signal-hook-registry"
|
||||
version = "1.4.7"
|
||||
@@ -3827,8 +3717,10 @@ name = "system-doctor"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"csv",
|
||||
"encoding_rs",
|
||||
"encoding_rs_io",
|
||||
"minidump",
|
||||
"minidump-processor",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sysinfo",
|
||||
@@ -4263,7 +4155,7 @@ checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"libc",
|
||||
"mio 1.1.0",
|
||||
"mio",
|
||||
"parking_lot",
|
||||
"pin-project-lite",
|
||||
"signal-hook-registry",
|
||||
@@ -5131,15 +5023,6 @@ dependencies = [
|
||||
"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]]
|
||||
name = "windows-sys"
|
||||
version = "0.59.0"
|
||||
@@ -5182,21 +5065,6 @@ dependencies = [
|
||||
"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]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.6"
|
||||
@@ -5254,12 +5122,6 @@ version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.6"
|
||||
@@ -5278,12 +5140,6 @@ version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.6"
|
||||
@@ -5302,12 +5158,6 @@ version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.6"
|
||||
@@ -5338,12 +5188,6 @@ version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.6"
|
||||
@@ -5362,12 +5206,6 @@ version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.6"
|
||||
@@ -5386,12 +5224,6 @@ version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.6"
|
||||
@@ -5410,12 +5242,6 @@ version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.6"
|
||||
@@ -5549,31 +5375,6 @@ dependencies = [
|
||||
"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]]
|
||||
name = "yoke"
|
||||
version = "0.8.1"
|
||||
|
||||
@@ -27,7 +27,11 @@ wmi = "0.13"
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
minidump = "0.19"
|
||||
minidump-processor = "0.19"
|
||||
# [新增] 用于解析 BlueScreenView 导出的 CSV
|
||||
csv = "1.3"
|
||||
# [新增] 用于处理可能的文件编码问题
|
||||
encoding_rs = "0.8"
|
||||
encoding_rs_io = "0.1"
|
||||
|
||||
[features]
|
||||
# this feature is used for production builds or when `devPath` points to the filesystem
|
||||
|
||||
@@ -9,7 +9,8 @@ use sysinfo::{System, Disks};
|
||||
use wmi::{COMLibrary, WMIConnection};
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::io::Read; // [新增] 用于读取文件头
|
||||
use std::io::Read;
|
||||
use std::process::Command;
|
||||
use tauri::Emitter;
|
||||
use chrono::{Duration, FixedOffset, Local, NaiveDate, TimeZone, DateTime};
|
||||
use minidump::{Minidump, MinidumpException, MinidumpSystemInfo};
|
||||
@@ -154,7 +155,7 @@ fn translate_bugcheck_u32(code: u32) -> (String, String) {
|
||||
),
|
||||
0x00000124 => (
|
||||
"WHEA_UNCORRECTABLE_ERROR (0x124)".to_string(),
|
||||
"硬件发生无法纠正的物理错误。这是纯硬件故障。通常是 CPU 电压不足、超频失败、过热,或者主板/PCIe设备(如 NVMe 硬盘)故障。"
|
||||
"硬件发生无法纠正的物理错误。这是纯硬件故障。通常是 CPU 电压不足、超频失败、过热,或者主板/PCIe设备故障。"
|
||||
.to_string(),
|
||||
),
|
||||
0x00000116 => (
|
||||
@@ -184,13 +185,21 @@ fn translate_bugcheck_u32(code: u32) -> (String, String) {
|
||||
),
|
||||
_ => (
|
||||
format!("未知错误代码: 0x{:X}", code),
|
||||
"请尝试在搜索引擎中搜索此错误代码。通用建议:更新驱动、检查内存、扫描病毒。".to_string(),
|
||||
"建议手动搜索此错误代码。通用建议:更新驱动、检查内存、扫描病毒。".to_string(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// [公共逻辑] 泛型函数,适配文件和内存
|
||||
fn analyze_dump_data<T>(dump: Minidump<T>) -> Result<BsodAnalysisReport, String>
|
||||
fn translate_bugcheck_str(code_str: &str) -> (String, 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]>
|
||||
{
|
||||
let (exception_code, exception_address) = match dump.get_stream::<MinidumpException>() {
|
||||
@@ -206,44 +215,106 @@ where T: Deref<Target = [u8]>
|
||||
Err(_) => "Unknown OS".to_string(),
|
||||
};
|
||||
|
||||
let (reason_str, recommend) = if exception_code != 0 {
|
||||
translate_bugcheck_u32(exception_code)
|
||||
} else {
|
||||
("未找到异常记录".to_string(), "该文件有效但未包含标准异常流。可能是手动生成的 Dump 或被截断。".to_string())
|
||||
};
|
||||
if exception_code == 0 {
|
||||
return Err("未找到异常记录".to_string());
|
||||
}
|
||||
|
||||
let (reason_str, recommend) = translate_bugcheck_u32(exception_code);
|
||||
|
||||
Ok(BsodAnalysisReport {
|
||||
crash_reason: reason_str,
|
||||
crash_address: format!("0x{:X}", exception_address),
|
||||
bug_check_code: format!("0x{:X} ({})", exception_code, sys_info_str),
|
||||
crashing_thread: None,
|
||||
human_analysis: "根据错误代码自动匹配的分析结果。".to_string(),
|
||||
human_analysis: "通过 Rust 原生库分析得出。".to_string(),
|
||||
recommendation: recommend,
|
||||
})
|
||||
}
|
||||
|
||||
// [新增] 辅助函数:检查文件头签名
|
||||
fn check_dump_signature(sig: &[u8]) -> Result<(), String> {
|
||||
if sig.len() < 4 {
|
||||
return Err("文件太小,无效的 Dump 文件。".to_string());
|
||||
}
|
||||
// [修复] BlueScreenView 外部调用分析 (使用 CSV crate 解析)
|
||||
fn analyze_with_bluescreenview(dump_path: &Path) -> Result<BsodAnalysisReport, String> {
|
||||
let bsv_exe = "BlueScreenView.exe";
|
||||
|
||||
// 1. 检查标准 Minidump (MDMP)
|
||||
if sig.starts_with(b"MDMP") {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// 2. 检查 Kernel Dump (PAGE / PAGEDU64)
|
||||
// 即使文件很小,只要头是 PAGE,它就是 Kernel Dump 格式,minidump crate 无法解析
|
||||
if sig.starts_with(b"PAGE") {
|
||||
return Err("不支持的文件格式:检测到 '内核转储' (PAGEDU64/PAGE)。".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());
|
||||
}
|
||||
|
||||
Err(format!(
|
||||
"文件签名错误!期望 'MDMP', 实际收到: {:02X?} ('{}')。\n这可能不是一个有效的蓝屏文件。",
|
||||
&sig[0..4],
|
||||
String::from_utf8_lossy(&sig[0..4]).replace('\0', "")
|
||||
))
|
||||
// 读取字节并转为 String (lossy 模式,防止 GBK/ANSI 乱码导致 panic)
|
||||
let content_bytes = fs::read(&temp_csv_path).map_err(|_| "BlueScreenView 分析未生成有效数据。".to_string())?;
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Err("BlueScreenView 输出为空或未能解析到有效列(文件可能已损坏)。".to_string())
|
||||
}
|
||||
|
||||
// 辅助函数:检查文件头签名并返回类型
|
||||
enum DumpType {
|
||||
Minidump,
|
||||
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 文件 ---
|
||||
@@ -286,34 +357,79 @@ async fn list_minidumps() -> Result<Vec<BsodFileItem>, String> {
|
||||
async fn analyze_minidump(filepath: String) -> Result<BsodAnalysisReport, String> {
|
||||
let path = Path::new(&filepath);
|
||||
|
||||
// [优化] 先读取头部进行校验,避免 minidump 库报晦涩错误
|
||||
let mut file = fs::File::open(path).map_err(|e| format!("无法打开文件: {}", e))?;
|
||||
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
|
||||
};
|
||||
|
||||
// 重新读取完整文件 (minidump crate 需要完整路径重新打开)
|
||||
let dump = Minidump::read_path(path).map_err(|e| format!("解析错误: {}", e))?;
|
||||
analyze_dump_data(dump)
|
||||
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 ---
|
||||
// [修复] 命令:分析二进制内容的 Minidump
|
||||
#[tauri::command]
|
||||
async fn analyze_minidump_bytes(file_content: Vec<u8>) -> Result<BsodAnalysisReport, String> {
|
||||
// [优化] 头部校验
|
||||
check_dump_signature(&file_content)?;
|
||||
if file_content.is_empty() {
|
||||
return Err("导入的文件内容为空".to_string());
|
||||
}
|
||||
|
||||
let dump = Minidump::read(file_content).map_err(|e| format!("解析器拒绝处理: {}", e))?;
|
||||
analyze_dump_data(dump)
|
||||
let dump_type = check_dump_signature(&file_content);
|
||||
|
||||
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 (保持不变) ---
|
||||
#[tauri::command]
|
||||
async fn run_diagnosis(window: tauri::Window) -> Result<(), String> {
|
||||
std::thread::spawn(move || {
|
||||
// ... (保持原有逻辑不变) ...
|
||||
// 占位符
|
||||
// ... (保持原有逻辑不变,占位符) ...
|
||||
{
|
||||
let mut sys = System::new();
|
||||
sys.refresh_memory();
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
"windows": [
|
||||
{
|
||||
"title": "system-doctor",
|
||||
"width": 800,
|
||||
"height": 600
|
||||
"width": 1200,
|
||||
"height": 800
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
|
||||
Reference in New Issue
Block a user