frida / frida-rust

Frida Rust bindings
Other
176 stars 46 forks source link

Injector crash the process on windows #142

Closed Aursen closed 3 weeks ago

Aursen commented 3 weeks ago

Hi, I'm trying to hook the 'connect' method on windows but when I attach the injector, the process crash. I don't know how to have the log to debug it.

Here the following code of the dll:

use frida_gum::{
    interceptor::{Interceptor, InvocationListener},
    Gum, Module,
};
use std::{ffi::c_void, sync::LazyLock};

static GUM: LazyLock<Gum> = LazyLock::new(|| unsafe { Gum::obtain() });

pub struct ConnectListener;

impl InvocationListener for ConnectListener {
    fn on_enter(&mut self, context: frida_gum::interceptor::InvocationContext) {
        println!("[HOOK INJECTED] ENTER");
    }

    fn on_leave(&mut self, context: frida_gum::interceptor::InvocationContext) {
        println!("[HOOK INJECTED] LEAVED");
    }
}

#[no_mangle]
extern "C" fn hook(_user_data: *const c_void) {
    let mut interceptor = Interceptor::obtain(&GUM);
    let connect = Module::find_export_by_name(None, "connect").unwrap();

    let mut listener = ConnectListener;

    println!("HOOK PTR: {:x}", connect);
    interceptor.attach(connect, &mut listener); // Crash at this moment
}

Edit: In JS everything is fine and the connect var is well defined

Aursen commented 3 weeks ago

It seems the timing of the injection is not good. I'm closing it right now