frida: make hooks thread local (#2429)
* frida: make hooks thread local * Fmt * clippy
This commit is contained in:
parent
f6151f4507
commit
695184169e
@ -11,6 +11,7 @@ use core::{
|
|||||||
ptr::addr_of_mut,
|
ptr::addr_of_mut,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
|
cell::Cell,
|
||||||
ffi::{c_char, c_void},
|
ffi::{c_char, c_void},
|
||||||
ptr::write_volatile,
|
ptr::write_volatile,
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
@ -93,6 +94,10 @@ pub const ASAN_SAVE_REGISTER_NAMES: [&str; ASAN_SAVE_REGISTER_COUNT] = [
|
|||||||
"actual rip",
|
"actual rip",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
thread_local! {
|
||||||
|
static ASAN_IN_HOOK: Cell<bool> = const { Cell::new(false) };
|
||||||
|
}
|
||||||
|
|
||||||
/// The count of registers that need to be saved by the asan runtime
|
/// The count of registers that need to be saved by the asan runtime
|
||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
pub const ASAN_SAVE_REGISTER_COUNT: usize = 32;
|
pub const ASAN_SAVE_REGISTER_COUNT: usize = 32;
|
||||||
@ -551,18 +556,13 @@ impl AsanRuntime {
|
|||||||
//is this necessary? The stalked return address will always be the real return address
|
//is this necessary? The stalked return address will always be the real return address
|
||||||
// let real_address = this.real_address_for_stalked(invocation.return_addr());
|
// let real_address = this.real_address_for_stalked(invocation.return_addr());
|
||||||
let original = [<$lib_ident:snake:upper _ $name:snake:upper _PTR>].get().unwrap();
|
let original = [<$lib_ident:snake:upper _ $name:snake:upper _PTR>].get().unwrap();
|
||||||
if this.hooks_enabled {
|
if !ASAN_IN_HOOK.get() && this.hooks_enabled {
|
||||||
let previous_hook_state = this.hooks_enabled;
|
ASAN_IN_HOOK.set(true);
|
||||||
this.hooks_enabled = false;
|
|
||||||
let ret = this.[<hook_ $name>](*original, $($param),*);
|
let ret = this.[<hook_ $name>](*original, $($param),*);
|
||||||
this.hooks_enabled = previous_hook_state;
|
ASAN_IN_HOOK.set(false);
|
||||||
ret
|
ret
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
let previous_hook_state = this.hooks_enabled;
|
|
||||||
this.hooks_enabled = false;
|
|
||||||
let ret = (original)($($param),*);
|
let ret = (original)($($param),*);
|
||||||
this.hooks_enabled = previous_hook_state;
|
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -599,17 +599,13 @@ impl AsanRuntime {
|
|||||||
let this = &mut *(invocation.replacement_data().unwrap().0 as *mut AsanRuntime);
|
let this = &mut *(invocation.replacement_data().unwrap().0 as *mut AsanRuntime);
|
||||||
let original = [<$name:snake:upper _PTR>].get().unwrap();
|
let original = [<$name:snake:upper _PTR>].get().unwrap();
|
||||||
|
|
||||||
if this.hooks_enabled && this.[<hook_check_ $name>]($($param),*){
|
if !ASAN_IN_HOOK.get() && this.hooks_enabled && this.[<hook_check_ $name>]($($param),*){
|
||||||
let previous_hook_state = this.hooks_enabled;
|
ASAN_IN_HOOK.set(true);
|
||||||
this.hooks_enabled = false;
|
|
||||||
let ret = this.[<hook_ $name>](*original, $($param),*);
|
let ret = this.[<hook_ $name>](*original, $($param),*);
|
||||||
this.hooks_enabled = previous_hook_state;
|
ASAN_IN_HOOK.set(false);
|
||||||
ret
|
ret
|
||||||
} else {
|
} else {
|
||||||
let previous_hook_state = this.hooks_enabled;
|
|
||||||
this.hooks_enabled = false;
|
|
||||||
let ret = (original)($($param),*);
|
let ret = (original)($($param),*);
|
||||||
this.hooks_enabled = previous_hook_state;
|
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -642,17 +638,13 @@ impl AsanRuntime {
|
|||||||
let this = &mut *(invocation.replacement_data().unwrap().0 as *mut AsanRuntime);
|
let this = &mut *(invocation.replacement_data().unwrap().0 as *mut AsanRuntime);
|
||||||
let original = [<$lib_ident:snake:upper _ $name:snake:upper _PTR>].get().unwrap();
|
let original = [<$lib_ident:snake:upper _ $name:snake:upper _PTR>].get().unwrap();
|
||||||
|
|
||||||
if this.hooks_enabled && this.[<hook_check_ $name>]($($param),*){
|
if !ASAN_IN_HOOK.get() && this.hooks_enabled && this.[<hook_check_ $name>]($($param),*){
|
||||||
let previous_hook_state = this.hooks_enabled;
|
ASAN_IN_HOOK.set(true);
|
||||||
this.hooks_enabled = false;
|
|
||||||
let ret = this.[<hook_ $name>](*original, $($param),*);
|
let ret = this.[<hook_ $name>](*original, $($param),*);
|
||||||
this.hooks_enabled = previous_hook_state;
|
ASAN_IN_HOOK.set(false);
|
||||||
ret
|
ret
|
||||||
} else {
|
} else {
|
||||||
let previous_hook_state = this.hooks_enabled;
|
|
||||||
this.hooks_enabled = false;
|
|
||||||
let ret = (original)($($param),*);
|
let ret = (original)($($param),*);
|
||||||
this.hooks_enabled = previous_hook_state;
|
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user