Skip to content

Commit 99193fe

Browse files
authored
Fix hook Module related examples (#224)
- Module doesn't use obtain anymore. Use load instead.
1 parent e98b64f commit 99193fe

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

examples/gum/hook_instruction/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ fn init() {
1818
static CELL: OnceLock<Gum> = OnceLock::new();
1919
let gum = CELL.get_or_init(|| Gum::obtain());
2020
let mut interceptor = Interceptor::obtain(gum);
21-
let module = Module::obtain(gum);
22-
let open = module.find_export_by_name(None, "open").unwrap();
21+
let module = Module::load(gum, "libc.so.6");
22+
let open = module.find_export_by_name("open").unwrap();
2323
let mut listener = OpenProbeListener;
2424
interceptor.attach_instruction(open, &mut listener).unwrap();
2525
}

examples/gum/hook_open/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@
33
This is an example on how to hook "open" libc function using frida-rust.
44

55
### Linux
6+
67
To test this on Linux, run a binary that calls "open" with this library LD_PRELOAD-ed:
7-
`LD_PRELOAD=hook_openlib.so cat /tmp/test"
8+
9+
```sh
10+
LD_PRELOAD=../../../target/release/libhook_open.so cat /tmp/test
11+
```
812

913
### MacOS
14+
1015
Find a binary that supports `DYLD_INSERT_LIBRARIES` and call it
11-
`DYLD_INSERT_LIBRARIES=hook_openlib.so somebinary"
16+
17+
```sh
18+
DYLD_INSERT_LIBRARIES=hook_openlib.so somebinary"
19+
```

examples/gum/hook_open/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ unsafe extern "C" fn open_detour(name: *const c_char, flags: c_int) -> c_int {
3131
fn init() {
3232
static CELL: OnceLock<Gum> = OnceLock::new();
3333
let gum = CELL.get_or_init(|| Gum::obtain());
34-
let module = Module::obtain(gum);
34+
let module = Module::load(gum, "libc.so.6");
3535
let mut interceptor = Interceptor::obtain(gum);
36-
let open = module.find_export_by_name(None, "open").unwrap();
36+
let open = module.find_export_by_name("open").unwrap();
3737
unsafe {
3838
*ORIGINAL_OPEN.lock().unwrap().get_mut() = Some(std::mem::transmute::<
3939
*mut libc::c_void,

0 commit comments

Comments
 (0)