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

modified:   src/main.rs
	modified:   src/mobile.rs
	modified:   src/simple_log.rs
This commit is contained in:
Michael Wain 2024-10-07 19:02:24 +03:00
parent db47c17b52
commit efa814c70a
4 changed files with 18 additions and 32 deletions

View File

@ -22,10 +22,11 @@ use crate::udp::{UDPVpnPacket, UDPVpnHandshake, UDPSerializable};
use network_interface::NetworkInterface; use network_interface::NetworkInterface;
use network_interface::NetworkInterfaceConfig; use network_interface::NetworkInterfaceConfig;
pub async fn client_mode(client_config: ClientConfiguration, fd: i32) { static MY_LOGGER: SimpleLogger = SimpleLogger::new();
if let Err(err) = log::set_boxed_logger(Box::<crate::simple_log::SimpleLogger>::default()) {
warn!("set logger error: {}", err); pub async fn client_mode(client_config: ClientConfiguration, fd: i32, env: &JNIEnv) {
} MY_LOGGER.set_env(env);
log::set_logger(&MY_LOGGER).unwrap();
info!("Starting client..."); info!("Starting client...");

View File

@ -75,13 +75,13 @@ mod jni {
close_fd_on_drop: bool) -> JniResult<i32> { close_fd_on_drop: bool) -> JniResult<i32> {
android_logger::init_once(Config::default().with_tag("RustFrida")); android_logger::init_once(Config::default().with_tag("RustFrida"));
FridaLib::traceFromNative(env, "Hello world".to_string()); //FridaLib::traceFromNative(env, "Hello world".to_string());
Ok(-2) Ok(mobile::mobile_run(config_b32, close_fd_on_drop, tun_fd, env))
} }
pub extern "jni" fn stop(self, env: &JNIEnv) -> JniResult<i32> { pub extern "jni" fn stop(self, env: &JNIEnv) -> JniResult<i32> {
Ok(-1) Ok(mobile::mobile_stop())
} }
pub extern "java" fn traceFromNative( pub extern "java" fn traceFromNative(
@ -90,14 +90,6 @@ mod jni {
) -> JniResult<()> { ) -> JniResult<()> {
} }
/*pub extern "java" fn threadTestNoClass(env: &JNIEnv, s: String) -> JniResult<i32> {}
pub extern "java" fn threadTestWithClass(
env: &JNIEnv,
class_ref: &GlobalRef,
s: String,
) -> JniResult<i32> {
}*/
} }
} }

View File

@ -6,9 +6,9 @@ use crate::client;
use jni::sys::jint; use jni::sys::jint;
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
pub fn mobile_run(cfg_raw: String, close_fd_on_drop: bool, tun_fd: jint) -> c_int { pub fn mobile_run(cfg_raw: String, close_fd_on_drop: bool, tun_fd: i32, env: &JNIEnv) -> 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 config: ClientConfiguration = serde_yaml::from_slice(RFC4648.decode(cfg_raw.as_bytes()).unwrap().as_slice()).expect("Bad client config file structure");
Runtime::new().unwrap().block_on(client::client_mode(config, tun_fd)); Runtime::new().unwrap().block_on(client::client_mode(config, tun_fd, env));
0 0
/*let block = async move { /*let block = async move {
let mut config = tun2::Configuration::default(); let mut config = tun2::Configuration::default();

View File

@ -2,21 +2,10 @@ use crossbeam_channel::unbounded;
use crossbeam_channel::{ Sender, Receiver }; use crossbeam_channel::{ Sender, Receiver };
use std::sync::LazyLock; use std::sync::LazyLock;
static bnd: LazyLock<(Sender<Vec<u8>>, Receiver<Vec<u8>>)> = LazyLock::new(|| unbounded::<Vec<u8>>());
pub fn fetch_logs() -> Vec<u8> {
if let Ok(bytes) = bnd.1.recv() {
return bytes;
}
Vec::new()
}
pub fn push_log(data: Vec<u8>) {
bnd.0.send(data);
}
#[derive(Debug, Clone, PartialEq, Eq, Default)] #[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct SimpleLogger {} pub struct SimpleLogger {
env: Option<&JNIEnv>
}
impl log::Log for SimpleLogger { impl log::Log for SimpleLogger {
fn enabled(&self, metadata: &log::Metadata) -> bool { fn enabled(&self, metadata: &log::Metadata) -> bool {
@ -45,6 +34,10 @@ impl SimpleLogger {
record.module_path().unwrap_or(""), record.module_path().unwrap_or(""),
record.args() record.args()
); );
push_log(msg.as_bytes().to_vec()); FridaLib::traceFromNative(self.env, msg);
}
fn set_env(&self, env: &JNIEnv) {
self.env = Some(env);
} }
} }