frida / frida-rust

Frida Rust bindings
Other
176 stars 46 forks source link

list_exports func added and initial RPC code. #147

Closed Xoffio closed 6 days ago

Xoffio commented 1 week ago

Please let me know if you have any notes. Once we get this approved I can move to finalize the RPC calls #105

s1341 commented 1 week ago

Thanks for this. In the future please try to do one PR per feature. It makes it easier to review.

s1341 commented 1 week ago

Please fix CI.

hsorbo commented 1 week ago

Here is a compact example using local and without the loop+thread-sleep (wasn't sure what it was showcasing). I noticed if we don't set the message handler it will deadlock. Is this expected behaviour? (I haven't used these bindings much)

use frida::{Frida, Message};
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 = local_device.attach(0).unwrap();
    let script_source = r#"
        rpc.exports = {
            a: function() {},
            b: function() {}
        };
    "#;
    let mut script_option = frida::ScriptOption::default();
    let mut script = session.create_script(script_source, &mut script_option).unwrap();
    script.handle_message(Handler).unwrap();
    script.load().unwrap();
    println!("{:?}", script.list_exports().unwrap());
    script.unload().unwrap();
    session.detach().unwrap();
}

struct Handler;

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

Also. To me it seems like pub fn list_exports(&mut self) -> Result<Option<Vec<String>>> could be simplified to pub fn list_exports(&mut self) -> Result<Vec<String>> (empty list if nothing found and no error)

Xoffio commented 1 week ago

@s1341 in the last commit (ee52266) I fix the no_std CI issue but that was not introduced by my code. It was introduced by -> 117003b97356342ae49c26161225b0354270462b. Let me know if that is good. Thanks

Xoffio commented 1 week ago

Here is a compact example using local and without the loop+thread-sleep (wasn't sure what it was showcasing).

Thank you @hsorbo I used some of your code. I put it in a loop to show that the communication is working as expected.

I noticed if we don't set the message handler it will deadlock. Is this expected behaviour? (I haven't used these bindings much)

I'm not 100% either. I saw in an example and a comment in the code, that that's how we have to do it , so I follow that.. If that is not intended then it have to be fix in a different PR.

Also. To me it seems like pub fn list_exports(&mut self) -> Result<Option<Vec<String>>> could be simplified to pub fn list_exports(&mut self) -> Result<Vec<String>> (empty list if nothing found and no error)

You are right. I updated the code. Thanks.

s1341 commented 1 week ago

Ready to merge?

Xoffio commented 1 week ago

Yes, thank you @s1341!