-
-
Notifications
You must be signed in to change notification settings - Fork 473
Expand file tree
/
Copy pathlib.rs
More file actions
30 lines (26 loc) · 830 Bytes
/
lib.rs
File metadata and controls
30 lines (26 loc) · 830 Bytes
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
//! A simple wrapper that can be inserted into a program to turn `exit` calls to `abort`, which `LibAFL` will be able to catch.
//! If you are on `MacOS`, use the env variables `DYLD_INSERT_LIBRARIES="path/to/target/release/libdeexit.dylib" tool`
//! On Linux, use `LD_PRELOAD="path/to/target/release/libdeexit.so" tool`.
unsafe extern "C" {
fn abort();
}
/// Hooked `exit` function
#[unsafe(no_mangle)]
pub extern "C" fn exit(status: i32) {
println!("DeExit: The target called exit with status code {status}");
unsafe {
abort();
}
}
#[cfg(target_os = "macos")]
use ctor::ctor;
#[cfg(target_os = "macos")]
#[ctor]
fn init() {
unsafe {
fishhook::register(vec![fishhook::Rebinding {
name: "exit".to_string(),
function: exit as *const () as usize,
}]);
}
}