frida / frida-rust

Frida Rust bindings
Other
187 stars 53 forks source link

Failed to Attach on usb device #162

Open chihaamin opened 1 month ago

chihaamin commented 1 month ago

use frida::{Frida, ScriptHandler, ScriptOption, ScriptRuntime, SpawnOptions}; use lazy_static::lazy_static;

lazy_static! { static ref FRIDA: Frida = unsafe { Frida::obtain() }; }

fn main() { let device_manager = frida::DeviceManager::obtain(&FRIDA); let mut usb = device_manager .get_device_by_type(frida::DeviceType::USB) .unwrap();

let mut pid: u32 = 0;
// let mut so = SpawnOptions::new();
// let pid = usb.spawn("testApp", &mut so).unwrap(); -> cause inf loop
for proc in usb.enumerate_processes() {
    if proc.get_name() == String::from("testApp") {
        println!("{} {}", proc.get_name(), proc.get_pid());
        pid = proc.get_pid()
    }
}
let session = usb.attach(pid); -> doesn't attach
match session {
    Ok(_s) => {}
    Err(e) => println!("{}", e),
}

}

struct Handler;

impl Handler { fn new() -> Self { Self } }

impl ScriptHandler for Handler { fn on_message(&mut self, message: &str) { println!("{:?}", message); } }

// output testApp 6873 Failed to attach

s1341 commented 1 month ago

Not sure it matters, but is it an android or iOS device?

chihaamin commented 1 month ago

android

s1341 commented 1 month ago

does regular frida-tools work on this computer/device?

chihaamin commented 1 month ago

Yes on windows everything works fine but when I use it for usb or using tcpip it doesn't work , when I spawn a process it get spawned in the android but the pid doesn't get returned and it get stuck in an infinite loop I tried to spawn the process then grab the pid of it : for proc in usb.enumerate_processes() { if proc.get_name() == String::from("testApp") { println!("{} {}", proc.get_name(), proc.get_pid()); pid = proc.get_pid() } } it doesn't attach to it

s1341 commented 1 month ago

can you confirm that adb works on this computer/device combination?