modified: Cargo.toml
Some checks failed
gitea/Frida-android-native/pipeline/head There was a failure building this commit

modified:   src/main.rs
	new file:   src/mobile.rs
This commit is contained in:
Michael Wain 2024-10-05 02:45:34 +03:00
parent 483612e013
commit 53a3cb2f02
3 changed files with 67 additions and 1 deletions

View File

@ -8,6 +8,9 @@ keywords = ["tun", "network", "tunnel", "vpn"]
categories = ["network-programming", "asynchronous"]
readme = "README.md"
[lib]
crate-type = ["cdylib"]
[dependencies]
clap = "2.33"
aes-gcm = "0.10.3"

View File

@ -1,3 +1,10 @@
#![cfg(target_os = "android")]
use jni::{
objects::{JClass, JString},
sys::{jboolean, jchar, jint},
JNIEnv,
};
use std::{fs, net::{Ipv4Addr}, str};
use clap::{App, Arg, ArgMatches};
use env_logger::Builder;
@ -8,7 +15,31 @@ use fast32::base32::RFC4648;
mod config;
mod client;
mod udp;
mod mobile;
#[no_mangle]
pub unsafe extern "C" fn Java_com_alterdekim_frida_FridaLib_run(
mut env: JNIEnv,
_clazz: JClass,
config_b32: JString,
tun_fd: jint,
close_fd_on_drop: jboolean,
) -> jint {
let config = get_java_string(&mut env, &config_b32).unwrap();
let close_fd_on_drop = close_fd_on_drop != 0;
mobile::mobile_run(config, close_fd_on_drop, tun_fd)
}
#[no_mangle]
pub unsafe extern "C" fn Java_com_alterdekim_frida_FridaLib_stop(_env: JNIEnv, _: JClass) -> jint {
mobile::mobile_stop()
}
fn get_java_string(env: &mut JNIEnv, string: &JString) -> Result<String, Error> {
Ok(env.get_string(string)?.into())
}
/*
#[tokio::main]
async fn main() {
// Initialize the logger with 'info' as the default level
@ -39,4 +70,4 @@ async fn main() {
let config: ClientConfiguration = serde_yaml::from_slice(RFC4648.decode(cfg_raw.as_bytes()).unwrap().as_slice()).expect("Bad client config file structure");
client::client_mode(config, matches.value_of("fd").unwrap().parse().unwrap()).await;
}
}*/

32
src/mobile.rs Normal file
View File

@ -0,0 +1,32 @@
use std::os::raw::c_int;
use log::{error, info, warn};
use crate::config::{ ServerConfiguration, ClientConfiguration, ObfsProtocol, ServerPeer };
use fast32::base32::RFC4648;
pub fn mobile_run(cfg_raw: String, close_fd_on_drop: bool, tun_fd: jint) -> c_int {
let config: ClientConfiguration = serde_yaml::from_slice(RFC4648.decode(cfg_raw.as_bytes()).unwrap().as_slice()).expect("Bad client config file structure");
let block = client::client_mode(config, tun_fd);
/*let block = async move {
let mut config = tun2::Configuration::default();
config.raw_fd(tun_fd);
config.close_fd_on_drop(close_fd_on_drop);
let device = tun2::create_as_async(&config).map_err(std::io::Error::from)?;
let join_handle = tokio::spawn(run(device, shutdown_token));
join_handle.await.map_err(std::io::Error::from)?
};*/
}
pub fn mobile_stop() -> c_int {
if let Ok(mut lock) = TUN_QUIT.lock() {
if let Some(shutdown_token) = lock.take() {
shutdown_token.cancel();
return 0;
}
}
-1
}