Craft Anything: understand how any software works, and craft your own.
Rust
List a remote Frida device without frida-ls-devices -H (#227)
muraa-pc6c8f356123f
diff --git a/crates/engine/src/tools/frida_tools.rs b/crates/engine/src/tools/frida_tools.rsindex 699fd0c8..30bc111e 100644--- a/crates/engine/src/tools/frida_tools.rs+++ b/crates/engine/src/tools/frida_tools.rs@@ -36,7 +36,7 @@ pub fn specs() -> Vec<ToolSpec> {spec("frida_devices_find","Frida devices",- "List devices Frida can see with `frida-ls-devices` (local, usb, remote). Pass remote to query a remote frida-server; its auth is forwarded to the CLI and never returned.",+ "List devices Frida can see with `frida-ls-devices` (local, usb, remote). Pass remote to get one entry for a remote address without contacting it, so its reachability and auth are unverified (`frida-ps -H` checks it); its auth is forwarded to the CLI and never returned.","See which devices the instrumentation tool can reach.",Frida,base,diff --git a/crates/engines/src/frida.rs b/crates/engines/src/frida.rsindex f691166f..73e3aac9 100644--- a/crates/engines/src/frida.rs+++ b/crates/engines/src/frida.rs@@ -159,16 +159,21 @@ impl Frida {/// `frida-ls-devices`, parsed.pub fn list_devices(&self, selector: Option<&Selector>) -> Result<Vec<FridaDevice>, ToolError> {- let prog = self.sibling("frida-ls-devices");- let mut args: Vec<OsString> = Vec::new();- if let Some(sel) = selector {- // Only a remote selector affects device listing; a device_id would be meaningless here.- if let Some(r) = &sel.remote {- validate_address(&r.address)?;- args.push(OsStr::new("-H").into());- args.push(OsStr::new(&r.address).into());- }+ // frida-ls-devices has no -H flag, so a remote address can't be listed with it; report the+ // remote as a single device instead, the way frida-ps/frida take -H. The entry is made up+ // from the address: nothing is contacted here, so a typo still "finds" a device.+ if let Some(sel) = selector+ && let Some(r) = &sel.remote+ {+ validate_address(&r.address)?;+ return Ok(vec![FridaDevice {+ device_id: r.address.clone(),+ kind: "remote".into(),+ name: format!("Remote ({}) (not contacted; frida-ps -H checks it)", r.address),+ }]);}+ let prog = self.sibling("frida-ls-devices");+ let args: Vec<OsString> = Vec::new();// On Windows this tool crashes without a real console, then hangs instead of exiting.#[cfg(windows)]{@@ -414,6 +419,33 @@ mod tests {assert_eq!(processes[0].pid, 12);}+ #[test]+ fn a_remote_selector_lists_one_uncontacted_device() {+ // The remote branch answers from the address alone: a path that cannot run proves no+ // program is started.+ let frida = Frida::new("/nonexistent/definitely/not/frida");+ let selector = Selector {+ device_id: None,+ remote: Some(Remote { address: "10.0.0.5:27042".into(), token: None, certificate: None, origin: None, keepalive_interval: None }),+ };+ let devices = frida.list_devices(Some(&selector)).unwrap();+ assert_eq!(devices.len(), 1);+ assert_eq!(devices[0].kind, "remote");+ assert_eq!(devices[0].device_id, "10.0.0.5:27042");+ assert!(devices[0].name.contains("not contacted"));+ }++ #[test]+ fn an_invalid_remote_address_is_refused() {+ let frida = Frida::new("/nonexistent/definitely/not/frida");+ let selector = Selector {+ device_id: None,+ remote: Some(Remote { address: "not an address!".into(), token: None, certificate: None, origin: None, keepalive_interval: None }),+ };+ let err = frida.list_devices(Some(&selector)).unwrap_err();+ assert_eq!(err.code, ErrorCode::BadInput);+ }+#[test]fn missing_frida_is_provider_unavailable() {let frida = Frida::new("/nonexistent/definitely/not/frida");diff --git a/docs/ROADMAP.md b/docs/ROADMAP.mdindex 3c331e9d..5127a879 100644--- a/docs/ROADMAP.md+++ b/docs/ROADMAP.md@@ -990,7 +990,7 @@ Owner: open · Status: done### R3.3 Frida sessions for realOwner: open · Status: todo- [ ] Replace the in-memory session bookkeeping with real attach, resume and detach-- [ ] `frida_devices_find` with `remote`: `frida-ls-devices` has no `-H`, so listing a remote's devices fails+- [x] `frida_devices_find` with `remote`: `frida-ls-devices` has no `-H`, so listing a remote's devices fails - return a single device entry for the remote instead of calling frida-ls-devices### R3.4 Decompilers for managed code (external engines)Owner: open · Status: in progress