1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::error::Error;
use std::fmt::{self, Display};
pub type BinResult<R> = Result<R, BinError>;
#[derive(Debug)]
pub enum ErrorKind {
ParseError,
BinaryError,
RuleEngineError,
KernelCheckError,
FileError,
DumpError,
}
#[derive(Debug)]
pub struct BinError {
pub kind: ErrorKind,
pub msg: String,
}
impl Display for BinError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(f, "\"{:?}: {}\"", self.kind, self.msg)
}
}
impl From<std::io::Error> for BinError {
fn from(error: std::io::Error) -> Self {
Self {
kind: ErrorKind::FileError,
msg: error.to_string(),
}
}
}
impl From<goblin::error::Error> for BinError {
fn from(error: goblin::error::Error) -> Self {
Self {
kind: ErrorKind::BinaryError,
msg: error.to_string(),
}
}
}
impl Error for BinError {}