Changes to be committed:
modified: src/lib.rs
This commit is contained in:
parent
7b18b0589c
commit
731035ce79
17
src/lib.rs
17
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")]
|
#[cfg(target_os="android")]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub mod android {
|
pub mod android {
|
||||||
@ -11,7 +26,7 @@ pub mod android {
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern fn Java_com_alterdekim_frida_FridaVPN_greeting(env: JNIEnv, _: JClass, java_pattern: JString) -> jstring {
|
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.
|
// 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.
|
// 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 world_ptr = CString::from_raw(world);
|
||||||
let output = env.new_string(world_ptr.to_str().unwrap()).expect("Couldn't create java string!");
|
let output = env.new_string(world_ptr.to_str().unwrap()).expect("Couldn't create java string!");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user