Skip to main content

dobby_hook_core/
error.rs

1use core::fmt;
2
3pub type Result<T> = core::result::Result<T, Error>;
4
5#[derive(Debug)]
6pub enum Error {
7    UnsupportedPlatform,
8    NullPointer,
9    InvalidInput,
10    AlreadyHooked,
11    HookNotFound,
12    SymbolNotFound,
13    DecodeFailed,
14    RelocationFailed,
15    EncodeFailed,
16    PatchTooSmall,
17    Unix(i32),
18    Win32(u32),
19}
20
21impl fmt::Display for Error {
22    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23        match self {
24            Error::UnsupportedPlatform => write!(f, "unsupported platform"),
25            Error::NullPointer => write!(f, "null pointer"),
26            Error::InvalidInput => write!(f, "invalid input"),
27            Error::AlreadyHooked => write!(f, "target already hooked"),
28            Error::HookNotFound => write!(f, "hook not found"),
29            Error::SymbolNotFound => write!(f, "symbol not found"),
30            Error::DecodeFailed => write!(f, "instruction decode failed"),
31            Error::RelocationFailed => write!(f, "instruction relocation failed"),
32            Error::EncodeFailed => write!(f, "instruction encode failed"),
33            Error::PatchTooSmall => write!(f, "patch region too small"),
34            Error::Unix(code) => write!(f, "unix error: {code}"),
35            Error::Win32(code) => write!(f, "win32 error: {code}"),
36        }
37    }
38}
39
40impl std::error::Error for Error {}