Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat (script): Add post method to Script #134

Merged
merged 1 commit into from
Jun 3, 2024

Conversation

charleywright
Copy link
Contributor

@charleywright charleywright commented May 23, 2024

This PR adds support for sending data to scripts which can be read using the recv function as detailed in the frida docs. Until RPC support is implemented (#105) this can be used to achieve a similar effect.

EDIT: RPC appears to be implemented using messages, see the python implementation here which could make this PR a requirement for an RPC implementation

@s1341
Copy link
Contributor

s1341 commented Jun 3, 2024

Can you please rebase on main?

@charleywright
Copy link
Contributor Author

Done

@s1341
Copy link
Contributor

s1341 commented Jun 3, 2024

Thanks!

@s1341 s1341 merged commit e325343 into frida:main Jun 3, 2024
15 checks passed
@Xoffio
Copy link
Contributor

Xoffio commented Aug 31, 2024

Hi @charleywright,
Could you add an example?

I have been trying the post function but I can't get it to work..

I have something like this:

        // .....
        let session = device.attach(pid).unwrap();

            let script_source = r#"
                var globalVar = 0;

                recv('input', function(message) {
                    console.log("--->", message);
                    if (message.payload === 'increment') {
                        globalVar += 1;
                        console.log("- gv: ", globalVar);
                        send('incremented: ' + globalVar);
                    } else if (message.payload === 'getvalue') {
                        send('globalVar value: ' + globalVar);
                        console.log("- gv: ", globalVar);
                    }
                });
            "#;
            let mut script_option = frida::ScriptOption::new()
                .set_name("example")
                .set_runtime(frida::ScriptRuntime::QJS);
            let script = session
                .create_script(script_source, &mut script_option)
                .unwrap();

            script.handle_message(&mut Handler).unwrap();

            script.load().unwrap();
            println!("[*] Script loaded.");

            // Post messages to the script
            script.post("input", Some("increment".as_bytes())).unwrap();
            script.post("input", Some("getvalue".as_bytes())).unwrap();

            script.unload().unwrap();
            println!("[*] Script unloaded");
           //....

But it doesn't show the changes.. I also tried adding .wait() to recv but the program seems to hang and then fail.

I can also add an example if I can get some guidance.
Really appreciate the time. Thanks!

@Xoffio
Copy link
Contributor

Xoffio commented Sep 1, 2024

Never mind, I have a working example. I will create a pull request with it.

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