From 731035ce79505d19690c40faedcf1be1a9382d48 Mon Sep 17 00:00:00 2001 From: alterdekim Date: Sun, 15 Sep 2024 21:38:35 +0300 Subject: [PATCH] Changes to be committed: modified: src/lib.rs --- src/lib.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index d848ce7..94d3050 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,18 @@ +use std::os::raw::{c_char}; +use std::ffi::{CString, CStr}; + +#[no_mangle] +pub extern fn rust_greeting(to: *const c_char) -> *mut c_char { + let c_str = unsafe { CStr::from_ptr(to) }; + let recipient = match c_str.to_str() { + Err(_) => "there", + Ok(string) => string, + }; + + CString::new("Hello ".to_owned() + recipient).unwrap().into_raw() +} + + #[cfg(target_os="android")] #[allow(non_snake_case)] pub mod android { @@ -11,7 +26,7 @@ pub mod android { #[no_mangle] pub unsafe extern fn Java_com_alterdekim_frida_FridaVPN_greeting(env: JNIEnv, _: JClass, java_pattern: JString) -> jstring { // Our Java companion code might pass-in "world" as a string, hence the name. - let world = rust_greeting(env.get_string(java_pattern).expect("invalid pattern string").as_ptr()); + let world = rust_greeting(env.get_string(&java_pattern).expect("invalid pattern string").as_ptr()); // Retake pointer so that we can use it below and allow memory to be freed when it goes out of scope. let world_ptr = CString::from_raw(world); let output = env.new_string(world_ptr.to_str().unwrap()).expect("Couldn't create java string!");