frida / frida-rust

Frida Rust bindings
Other
188 stars 53 forks source link

"Failed to attach" when using the bindings in macOS #174

Open suidpit opened 3 weeks ago

suidpit commented 3 weeks ago

I have the following code:

use frida::Frida;
use frida::ScriptOption;
use lazy_static::lazy_static;

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

fn main() {
    let device_manager = frida::DeviceManager::obtain(&FRIDA);
    let local_device = device_manager.get_local_device().unwrap();
    let session = match local_device.attach(9166) {
        Ok(session) => session,
        Err(e) => {
            eprintln!("Failed to attach to process: {}", e);
            return;
        }
    };
    let mut script = session.create_script(
        "
        console.log(Process.enumerateRangesSync('rw-'))
    ", &mut ScriptOption::default(),
    ).unwrap();
    let handler = Handler;
    script.handle_message(handler).unwrap();
    script.load().unwrap();
    std::thread::sleep(std::time::Duration::from_secs(10));
}

struct Handler;

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

PID 9166 points to a process running in my system.

When running it, I get the following:

Failed to attach to process: Failed to attach

For reference, this is what happens when doing the same with the python bindings:

>>> import frida
>>> frida.get_local_device().attach(9166)
Session(pid=9166)
>>>

SIP is disabled, running on M1 Pro 14.5