1use std::path::PathBuf;
2
3use crate::types::Architecture;
4
5pub type Result<T> = std::result::Result<T, Error>;
6
7#[derive(Debug, thiserror::Error)]
8pub enum Error {
9 #[error("I/O error: {0}")]
10 Io(#[from] std::io::Error),
11
12 #[error("Failed to open file '{path}': {source}")]
13 FileOpen { path: PathBuf, source: std::io::Error },
14
15 #[error("Failed to parse PE/COFF file: {0}")]
16 PeParse(String),
17
18 #[error("Export directory not found")]
19 NoExportDirectory,
20
21 #[error("Export table is corrupted or invalid")]
22 InvalidExportTable,
23
24 #[error("Expected {expected} exports, found {actual}")]
25 ExportCountMismatch { expected: usize, actual: usize },
26
27 #[error("Missing required export(s): {0}")]
28 MissingExport(String),
29
30 #[error("Export name mismatch: expected '{expected}', found '{actual}'")]
31 NameMismatch { expected: String, actual: String },
32
33 #[error("Export ordinal mismatch: name '{name}', expected ordinal {expected}, found {actual}")]
34 OrdinalMismatch { name: String, expected: u32, actual: u32 },
35
36 #[error("Not a valid DLL/EXE file")]
37 InvalidFileFormat,
38
39 #[error("Architecture mismatch: expected {expected}, found {actual}")]
40 ArchMismatch {
41 expected: Architecture,
42 actual: Architecture,
43 },
44
45 #[error("Not a DLL file")]
46 NotADll,
47
48 #[error("Windows registry error: {0}")]
49 Registry(String),
50
51 #[error("Export not found: {0}")]
52 ExportNotFound(String),
53
54 #[error("No exports found in DLL")]
55 NoExports,
56
57 #[error("UTF-8 decoding error: {0}")]
58 Utf8(#[from] std::string::FromUtf8Error),
59
60 #[error("NUL character found in export name")]
61 NulInName,
62
63 #[cfg(feature = "serde")]
64 #[error("JSON serialization error: {0}")]
65 Json(#[from] serde_json::Error),
66}