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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion frida/src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licence: wxWindows Library Licence, Version 3.1
*/

use frida_sys::{FridaScriptOptions, _FridaScript};
use frida_sys::{FridaScriptOptions, _FridaScript, g_bytes_new, g_bytes_unref};
use std::marker::PhantomData;
use std::{
ffi::{c_char, c_void, CStr, CString},
Expand Down Expand Up @@ -104,6 +104,25 @@ impl<'a> Script<'a> {

Ok(())
}

/// Post a JSON-encoded message to the script with optional binary data
///
/// NOTE: `message` must be valid JSON otherwise the script will throw a SyntaxError
pub fn post<S: AsRef<str>>(&self, message: S, data: Option<&[u8]>) -> Result<()> {
let message = CString::new(message.as_ref()).map_err(|_| Error::CStringFailed)?;

unsafe {
let g_data = if let Some(data) = data {
g_bytes_new(data.as_ptr() as _, data.len() as _)
} else {
std::ptr::null_mut()
};
frida_sys::frida_script_post(self.script_ptr as _, message.as_ptr() as _, g_data);
g_bytes_unref(g_data);
}

Ok(())
}
}

impl<'a> Drop for Script<'a> {
Expand Down
Loading