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
53
54
55
56
57
58
59
60
61
62
use std::error::Error as StdError;
use std::fmt;
pub type Result<T> = ::std::result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
SameAddress,
InvalidCode,
NoPatchArea,
NotExecutable,
NotInitialized,
AlreadyInitialized,
OutOfMemory,
UnsupportedInstruction,
RegionFailure(region::Error),
}
impl StdError for Error {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
if let Error::RegionFailure(error) = self {
Some(error)
} else {
None
}
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::SameAddress => write!(f, "Target and detour address is the same"),
Error::InvalidCode => write!(f, "Address contains invalid assembly"),
Error::NoPatchArea => write!(f, "Cannot find an inline patch area"),
Error::NotExecutable => write!(f, "Address is not executable"),
Error::NotInitialized => write!(f, "Detour is not initialized"),
Error::AlreadyInitialized => write!(f, "Detour is already initialized"),
Error::OutOfMemory => write!(f, "Cannot allocate memory"),
Error::UnsupportedInstruction => write!(f, "Address contains an unsupported instruction"),
Error::RegionFailure(ref error) => write!(f, "{}", error),
}
}
}
impl From<region::Error> for Error {
fn from(error: region::Error) -> Self {
Error::RegionFailure(error)
}
}