Skip to content

Commit

Permalink
fix Frida
Browse files Browse the repository at this point in the history
  • Loading branch information
domenukk committed Nov 7, 2024
1 parent fc2739f commit 2f80bb1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
4 changes: 3 additions & 1 deletion libafl_bolts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1276,8 +1276,10 @@ mod tests {
use std::{io::stdout, os::fd::AsRawFd};

unsafe { LIBAFL_RAWFD_LOGGER.fd = stdout().as_raw_fd() };

let libafl_rawfd_logger_fd = &raw const LIBAFL_RAWFD_LOGGER;
unsafe {
log::set_logger(&*&raw const LIBAFL_RAWFD_LOGGER).unwrap();
log::set_logger(&*libafl_rawfd_logger_fd).unwrap();
}
log::set_max_level(log::LevelFilter::Debug);
log::info!("Test");
Expand Down
8 changes: 4 additions & 4 deletions libafl_frida/src/cmplog_rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,15 @@ impl CmpLogRuntime {
; stp x26, x27, [sp, #-0x10]!
; stp x28, x29, [sp, #-0x10]!
; stp x30, xzr, [sp, #-0x10]!
; .dword 0xd53b4218u32 as i32 // mrs x24, nzcv
; .u32 0xd53b4218_u32 // mrs x24, nzcv
// jump to rust based population of the lists
; mov x2, x0
; adr x3, >done
; ldr x4, >populate_lists
; ldr x0, >self_addr
; blr x4
// restore the reg state before returning to the caller
; .dword 0xd51b4218u32 as i32 // msr nzcv, x24
; .u32 0xd51b4218_u32 // msr nzcv, x24
; ldp x30, xzr, [sp], #0x10
; ldp x28, x29, [sp], #0x10
; ldp x26, x27, [sp], #0x10
Expand All @@ -244,9 +244,9 @@ impl CmpLogRuntime {
; ldp x2, x3, [sp], #0x10
; b >done
; self_addr:
; .qword core::ptr::from_mut(self) as *mut c_void as i64
; .u64 core::ptr::from_mut(self) as *mut c_void as u64
; populate_lists:
; .qword CmpLogRuntime::populate_lists as *mut c_void as i64
; .u64 CmpLogRuntime::populate_lists as *mut c_void as u64
; done:
);};
}
Expand Down
15 changes: 12 additions & 3 deletions libafl_frida/src/pthread_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,17 @@ impl PreviousHook {
unsafe impl Sync for PreviousHook {}

// TODO: This could use a RwLock as well
/// The previous hook
static mut PREVIOUS_HOOK: PreviousHook = PreviousHook(std::ptr::null());

/// The currently set hook
static CURRENT_HOOK: RwLock<Option<PthreadIntrospectionHook>> = RwLock::new(None);

/// Get the pointer to the previous hook, mut
fn previous_hook_ptr_mut() -> *mut PreviousHook {
&raw mut PREVIOUS_HOOK
}

extern "C" fn pthread_introspection_hook(
event: libc::c_uint,
thread: libc::pthread_t,
Expand All @@ -76,7 +83,7 @@ extern "C" fn pthread_introspection_hook(
if let Some(ref hook) = *CURRENT_HOOK.read().unwrap() {
hook(event.try_into().unwrap(), thread, addr, size);
}
unsafe { PREVIOUS_HOOK.dispatch(event, thread, addr, size) };
unsafe { (*previous_hook_ptr_mut()).dispatch(event, thread, addr, size) };
}

/// Closure type for `pthread_introspection` hooks.
Expand Down Expand Up @@ -159,7 +166,7 @@ where
// Allow because we're sure this isn't from a different code generation unit.
if !(prev).is_null() && prev != pthread_introspection_hook as _ {
unsafe {
PREVIOUS_HOOK.set(prev as *const pthread_introspection_hook_t);
(*previous_hook_ptr_mut()).set(prev as *const pthread_introspection_hook_t);
}
}
}
Expand All @@ -176,7 +183,9 @@ where
/// # Safety
/// Potential data race when if called at the same time as `install` or `reset` from another thread
pub unsafe fn reset() {
unsafe { PREVIOUS_HOOK.reset() };
unsafe {
(*previous_hook_ptr_mut()).reset();
};
}

/// The following tests fail if they are not run sequentially.
Expand Down

0 comments on commit 2f80bb1

Please sign in to comment.