From aff482f581822a855ee39194eb440dac03ea658c Mon Sep 17 00:00:00 2001 From: Charley Wright Date: Wed, 22 May 2024 15:41:42 +0100 Subject: [PATCH] feat (script): Add post method to Script --- frida/src/script.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/frida/src/script.rs b/frida/src/script.rs index 08f6dd8..8eaa679 100644 --- a/frida/src/script.rs +++ b/frida/src/script.rs @@ -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}, @@ -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>(&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> {