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
/*
 * Copyright © 2021 Keegan Saunders
 *
 * Licence: wxWindows Library Licence, Version 3.1
 */
use core::fmt;

/// Custom `Error` for Frida
pub enum Error {
    /// Bad signature during Interceptor operation
    InterceptorBadSignature,

    /// Function is already replaced during Interceptor operation
    InterceptorAlreadyReplaced,

    /// Policy violation
    PolicyViolation,

    /// Other Interceptor error
    InterceptorError,

    /// Memory access error
    MemoryAccessError,

    WrongType,
}

impl fmt::Display for Error {
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Error::InterceptorBadSignature => write!(fmt, "Bad signature"),
            Error::InterceptorAlreadyReplaced => write!(fmt, "Function already replaced"),
            Error::PolicyViolation => write!(fmt, "Policy violation"),
            Error::InterceptorError => write!(fmt, "Interceptor error"),
            Error::MemoryAccessError => write!(fmt, "Memory access error"),
            Error::WrongType => write!(fmt, "Wrong type"),
        }
    }
}

impl fmt::Debug for Error {
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(fmt, "{self:}")
    }
}

#[allow(unused)]
pub type GumResult<T> = Result<T, Error>;