Skip to content

list_exports func added and initial RPC code.#147

Merged
s1341 merged 8 commits into
frida:mainfrom
Xoffio:xo-rpc-1
Sep 8, 2024
Merged

list_exports func added and initial RPC code.#147
s1341 merged 8 commits into
frida:mainfrom
Xoffio:xo-rpc-1

Conversation

@Xoffio

@Xoffio Xoffio commented Sep 2, 2024

Copy link
Copy Markdown
Contributor
  • Implemented the function list_exports. Included an example demonstrating how to use it.
  • Updated the example console_log to align with the recent changes made to the on_message function.
  • Adjusted types in device.rs and variant.rs: After adding serde to cargo, I encountered compilation issues with frida_sys::FALSE. I set the types to resolve these issues.

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

@s1341

s1341 commented Sep 3, 2024

Copy link
Copy Markdown
Contributor

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

Comment thread examples/core/list_exports/src/main.rs Outdated
Comment thread examples/core/list_exports/src/main.rs Outdated
Comment thread frida/src/script.rs Outdated
Comment thread frida/src/script.rs Outdated
Comment thread frida/src/script.rs Outdated
@s1341

s1341 commented Sep 5, 2024

Copy link
Copy Markdown
Contributor

Please fix CI.

@hsorbo

hsorbo commented Sep 5, 2024

Copy link
Copy Markdown
Member

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

Xoffio commented Sep 5, 2024

Copy link
Copy Markdown
Contributor Author

@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 -> 117003b. Let me know if that is good. Thanks

@Xoffio

Xoffio commented Sep 5, 2024

Copy link
Copy Markdown
Contributor Author

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 s1341 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the few nitpicks, then it is ready to merge i think.

where
'b: 'a,
{
pub fn obtain<'b: 'a>(_gum: &'b Gum) -> Interceptor<'b> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the 'a lifetime here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'b: 'a ensures that the lifetime of the input is at least as long as 'a. I had to put that because 117003b broke the no_std test

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I didn't realize 'a was on the Interceptor.

Comment thread frida-gum/src/stalker.rs
Comment thread frida/src/script.rs Outdated
Comment thread frida/src/script.rs Outdated
Comment thread frida/src/script.rs Outdated
Comment thread frida/src/script.rs Outdated
@s1341

s1341 commented Sep 8, 2024

Copy link
Copy Markdown
Contributor

Ready to merge?

@Xoffio

Xoffio commented Sep 8, 2024

Copy link
Copy Markdown
Contributor Author

Yes, thank you @s1341!

@s1341 s1341 merged commit fea112a into frida:main Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants