From 82a4ab5752ac4f63d38f5d2e5f74bd5286eea98d Mon Sep 17 00:00:00 2001 From: b1ueb1ues Date: Wed, 22 Oct 2025 15:51:38 +0800 Subject: [PATCH 1/3] update examples/gum to frida17 Module api --- examples/gum/debug_symbol/src/main.rs | 6 ++---- examples/gum/hook_instruction/src/lib.rs | 3 +-- examples/gum/hook_open/src/lib.rs | 3 +-- examples/gum/open/Cargo.toml | 2 +- examples/gum/open/src/lib.rs | 14 ++++++++------ examples/gum/script/src/main.rs | 5 +++-- examples/gum/script/src/script.js | 4 ++-- 7 files changed, 18 insertions(+), 19 deletions(-) diff --git a/examples/gum/debug_symbol/src/main.rs b/examples/gum/debug_symbol/src/main.rs index 9e71a476..f3ef1d3e 100644 --- a/examples/gum/debug_symbol/src/main.rs +++ b/examples/gum/debug_symbol/src/main.rs @@ -1,14 +1,12 @@ use frida_gum::DebugSymbol; use frida_gum::{Gum, Module}; -use std::iter::Once; use std::sync::OnceLock; fn main() { static CELL: OnceLock = OnceLock::new(); - let gum = CELL.get_or_init(|| Gum::obtain()); + let _gum = CELL.get_or_init(|| Gum::obtain()); - let module = Module::obtain(gum); - let symbol = module.find_export_by_name(None, "mmap").unwrap(); + let symbol = Module::find_global_export_by_name("mmap").unwrap(); let symbol_details = DebugSymbol::from_address(symbol).unwrap(); println!( "address={:#x?} module_name={:?} symbol_name={:?} file_name={:?} line_number={:?}", diff --git a/examples/gum/hook_instruction/src/lib.rs b/examples/gum/hook_instruction/src/lib.rs index 79ad01c4..00e07c5d 100644 --- a/examples/gum/hook_instruction/src/lib.rs +++ b/examples/gum/hook_instruction/src/lib.rs @@ -18,8 +18,7 @@ fn init() { static CELL: OnceLock = OnceLock::new(); let gum = CELL.get_or_init(|| Gum::obtain()); let mut interceptor = Interceptor::obtain(gum); - let module = Module::obtain(gum); - let open = module.find_export_by_name(None, "open").unwrap(); + let open = Module::find_global_export_by_name("open").unwrap(); let mut listener = OpenProbeListener; interceptor.attach_instruction(open, &mut listener).unwrap(); } diff --git a/examples/gum/hook_open/src/lib.rs b/examples/gum/hook_open/src/lib.rs index cead4d9c..50fbd425 100644 --- a/examples/gum/hook_open/src/lib.rs +++ b/examples/gum/hook_open/src/lib.rs @@ -31,9 +31,8 @@ unsafe extern "C" fn open_detour(name: *const c_char, flags: c_int) -> c_int { fn init() { static CELL: OnceLock = OnceLock::new(); let gum = CELL.get_or_init(|| Gum::obtain()); - let module = Module::obtain(gum); let mut interceptor = Interceptor::obtain(gum); - let open = module.find_export_by_name(None, "open").unwrap(); + let open = Module::find_global_export_by_name("open").unwrap(); unsafe { *ORIGINAL_OPEN.lock().unwrap().get_mut() = Some(std::mem::transmute::< *mut libc::c_void, diff --git a/examples/gum/open/Cargo.toml b/examples/gum/open/Cargo.toml index c31585cd..69d481fc 100644 --- a/examples/gum/open/Cargo.toml +++ b/examples/gum/open/Cargo.toml @@ -10,4 +10,4 @@ publish = false crate-type = ["cdylib"] [dependencies] -frida-gum = { path = "../../../frida-gum", features = ["invocation-listener"] } +frida-gum = { path = "../../../frida-gum", features = ["invocation-listener", "std"] } diff --git a/examples/gum/open/src/lib.rs b/examples/gum/open/src/lib.rs index c48fbeb7..b75471a9 100644 --- a/examples/gum/open/src/lib.rs +++ b/examples/gum/open/src/lib.rs @@ -3,7 +3,7 @@ use frida_gum as gum; use gum::{ interceptor::{Interceptor, InvocationContext, InvocationListener}, - Gum, Module, + Gum, Module, Process, }; use std::os::raw::{c_int, c_void}; use std::sync::OnceLock; @@ -29,16 +29,18 @@ extern "C" fn example_agent_main(_user_data: *const c_void, resident: *mut c_int let mut interceptor = Interceptor::obtain(gum); let mut listener = OpenListener {}; - - let module = Module::obtain(gum); - let modules = module.enumerate_modules(); + + let process = Process::obtain(gum); + let modules = process.enumerate_modules(); for module in modules { println!( "{}@{:#x}/{:#x}", - module.name, module.base_address, module.size + module.name(), + module.range().base_address(), + module.range().size() ); } - let open = module.find_export_by_name(None, "open").unwrap(); + let open = Module::find_global_export_by_name("open").unwrap(); interceptor.attach(open, &mut listener).unwrap(); } diff --git a/examples/gum/script/src/main.rs b/examples/gum/script/src/main.rs index db1d2c99..d5c198a8 100644 --- a/examples/gum/script/src/main.rs +++ b/examples/gum/script/src/main.rs @@ -27,8 +27,9 @@ pub fn main() { let payload = include_str!("script.js"); println!("payload: {}", payload); - - let backend = Backend::obtain_v8(&GUM); + + //let backend = Backend::obtain_v8(&GUM); // obtain_v8 cannot Script::load. `Err` value: Failed to create script + let backend = Backend::obtain_qjs(&GUM); // qjs works fine except failed to attach test2 on release mode let script = Script::load(&backend, "script.js", payload, Some(callback)).unwrap(); let t2 = test2(987); diff --git a/examples/gum/script/src/script.js b/examples/gum/script/src/script.js index de6c01c7..ed02614a 100644 --- a/examples/gum/script/src/script.js +++ b/examples/gum/script/src/script.js @@ -3,10 +3,10 @@ console.log("[*] Hello, world!"); /* Test a message containing some bytes */ send("message", [0x10, 0x20, 0x30, 0x40]); -const test1 = Module.getExportByName(null, "test1"); +const test1 = Module.getGlobalExportByName("test1"); console.log(`[*] test1: ${test1}`); -const test2 = Module.getExportByName(null, "test2"); +const test2 = Module.getGlobalExportByName("test2"); console.log(`[*] test2: ${test2}`); /* Call test1 from our script */ From 4c71161d55196e9a6b23d32307fc05a0d959a845 Mon Sep 17 00:00:00 2001 From: b1ueb1ues Date: Thu, 23 Oct 2025 10:16:34 +0800 Subject: [PATCH 2/3] taplo fmt --- examples/gum/open/Cargo.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/gum/open/Cargo.toml b/examples/gum/open/Cargo.toml index 69d481fc..162d31fc 100644 --- a/examples/gum/open/Cargo.toml +++ b/examples/gum/open/Cargo.toml @@ -10,4 +10,7 @@ publish = false crate-type = ["cdylib"] [dependencies] -frida-gum = { path = "../../../frida-gum", features = ["invocation-listener", "std"] } +frida-gum = { path = "../../../frida-gum", features = [ + "invocation-listener", + "std", +] } From 413a4a2b906263c07f3446b4618243ddf1dd2f53 Mon Sep 17 00:00:00 2001 From: b1ueb1ues Date: Thu, 23 Oct 2025 11:36:19 +0800 Subject: [PATCH 3/3] cargo fmt --- examples/gum/open/src/lib.rs | 2 +- examples/gum/script/src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gum/open/src/lib.rs b/examples/gum/open/src/lib.rs index b75471a9..9815276d 100644 --- a/examples/gum/open/src/lib.rs +++ b/examples/gum/open/src/lib.rs @@ -29,7 +29,7 @@ extern "C" fn example_agent_main(_user_data: *const c_void, resident: *mut c_int let mut interceptor = Interceptor::obtain(gum); let mut listener = OpenListener {}; - + let process = Process::obtain(gum); let modules = process.enumerate_modules(); for module in modules { diff --git a/examples/gum/script/src/main.rs b/examples/gum/script/src/main.rs index d5c198a8..cda14cff 100644 --- a/examples/gum/script/src/main.rs +++ b/examples/gum/script/src/main.rs @@ -27,7 +27,7 @@ pub fn main() { let payload = include_str!("script.js"); println!("payload: {}", payload); - + //let backend = Backend::obtain_v8(&GUM); // obtain_v8 cannot Script::load. `Err` value: Failed to create script let backend = Backend::obtain_qjs(&GUM); // qjs works fine except failed to attach test2 on release mode let script = Script::load(&backend, "script.js", payload, Some(callback)).unwrap();