-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse_sym.rs
46 lines (36 loc) · 1.25 KB
/
parse_sym.rs
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
use std::ptr::null;
type PthreadCreateType = extern "C" fn(
native: *mut libc::pthread_t,
attr: *const libc::pthread_attr_t,
f: extern "C" fn(*mut libc::c_void) -> *mut libc::c_void,
value: *mut libc::c_void,
) -> libc::c_int;
static mut PTHREAD_CREATE_ADDR: *const libc::c_void = null();
extern "C" fn my_pthread_create(
native: *mut libc::pthread_t,
attr: *const libc::pthread_attr_t,
f: extern "C" fn(*mut libc::c_void) -> *mut libc::c_void,
value: *mut libc::c_void,
) -> libc::c_int {
println!("before pthread_create");
let pthread_create =
unsafe { std::mem::transmute::<_, PthreadCreateType>(PTHREAD_CREATE_ADDR) };
let ret = pthread_create(native, attr, f, value);
println!("after pthread_create");
ret
}
fn main() {
std::thread::spawn(|| println!("not hooked"))
.join()
.unwrap();
println!();
let real_pthread_create_address = plthook::inject(
my_pthread_create as *const libc::c_void,
plthook::Target {
function_name: "pthread_create".to_owned(),
mmap: plthook::TargetMmap::Main,
},
);
unsafe { PTHREAD_CREATE_ADDR = real_pthread_create_address };
std::thread::spawn(|| println!("hooked")).join().unwrap();
}