-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathaarch64_linux_android.rs
More file actions
57 lines (48 loc) · 1.6 KB
/
aarch64_linux_android.rs
File metadata and controls
57 lines (48 loc) · 1.6 KB
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
use std::ffi::{CString, c_void};
use std::ptr::null_mut;
use std::sync::atomic::{AtomicPtr, Ordering};
use crate::flamingo_c_api::{self, flamingo_make_name};
/// A function hook specific to `ARMv8` Android
#[derive(Debug)]
pub struct Hook {
original: AtomicPtr<c_void>,
}
impl Hook {
/// Creates a new, unitialized hook
pub const fn new() -> Self {
Self {
original: AtomicPtr::new(null_mut()),
}
}
/// Installes the hook by redirecting `target` to `hook`, returning true on
/// success
///
/// # Safety
/// `target` and `hook` must have the same signature and calling convention
pub unsafe fn install(&self, target: *const (), hook: *const ()) -> bool {
let mut original: *mut c_void = null_mut();
let name_metadata =
unsafe { flamingo_make_name(CString::new("unknown").unwrap().as_ptr()) };
unsafe {
flamingo_c_api::flamingo_install_hook_no_name(
hook as *mut c_void,
target as *mut u32,
&mut original,
)
};
self.original.store(original, Ordering::SeqCst);
true
}
/// Whether the hook is installed
pub fn is_installed(&self) -> bool {
!self.original.load(Ordering::SeqCst).is_null()
}
/// Returns the address of a trampoline function to the original target, if
/// installed
pub fn original(&self) -> Option<*const ()> {
match self.original.load(Ordering::SeqCst) {
null if null.is_null() => None,
original => Some(original as *const ()),
}
}
}