From 94c216aff3188619e6bdc0de297c8ff70dfa1eed Mon Sep 17 00:00:00 2001 From: alterdekim Date: Mon, 7 Oct 2024 22:18:46 +0300 Subject: [PATCH] modified: src/client.rs --- src/client.rs | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/client.rs b/src/client.rs index 972b9df..abc7c29 100644 --- a/src/client.rs +++ b/src/client.rs @@ -25,13 +25,13 @@ use robusta_jni::jni::JNIEnv; use crate::jni::FridaLib; pub async fn client_mode(client_config: ClientConfiguration, fd: i32, env: &JNIEnv<'_>) { - FridaLib::traceFromNative(env, "Starting client...".to_string()); + ltx.send("Starting client...".as_bytes()); let sock = UdpSocket::bind("0.0.0.0:25565").await.unwrap(); sock.connect(&client_config.server.endpoint).await.unwrap(); - FridaLib::traceFromNative(env, format!("FD: {:?}", &fd)); - FridaLib::traceFromNative(env, "So exhausting".to_string()); + ltx.send(format!("FD: {:?}", &fd).as_bytes()); + ltx.send("So exhausting".as_bytes()); let mut dev = unsafe { File::from_raw_fd(fd) }; let mut dev1 = dev.try_clone().unwrap(); let mut dev_reader = BufReader::new(dev); @@ -40,14 +40,21 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32, env: &JNIE let sock_rec = Arc::new(sock); let sock_snd = sock_rec.clone(); + let (ltx, lrx) = unbounded::>(); let (tx, rx) = unbounded::>(); let (dx, mx) = unbounded::>(); let cipher_shared: Arc>> = Arc::new(Mutex::new(None)); + tokio::spawn(async move { + while let Ok(bytes) = lrx.recv() { + FridaLib::traceFromNative(env, String::from_utf8_lossy(bytes).to_string()); + } + }); + tokio::spawn(async move { while let Ok(bytes) = rx.recv() { - FridaLib::traceFromNative(env, "Write to tun.".to_string()); + ltx.send("Write to tun.".as_bytes()); dev_writer.write_all(&bytes).unwrap(); } }); @@ -55,7 +62,7 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32, env: &JNIE tokio::spawn(async move { let mut buf = vec![0; 1400]; // mtu while let Ok(n) = dev_reader.read(&mut buf) { - FridaLib::traceFromNative(env, "Read from tun.".to_string()); + ltx.send("Read from tun.".as_bytes()); dx.send(buf[..n].to_vec()).unwrap(); } }); @@ -68,7 +75,7 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32, env: &JNIE loop { if let Ok(l) = sock_rec.recv(&mut buf).await { - FridaLib::traceFromNative(env, "Read from socket".to_string()); + ltx.send("Read from socket".as_bytes()); let mut s_cipher = cipher_shared_clone.lock().await; match buf.first() { Some(h) => { @@ -93,17 +100,17 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32, env: &JNIE let nonce = Nonce::clone_from_slice(&wrapped_packet.nonce); match aes.decrypt(&nonce, &wrapped_packet.data[..]) { Ok(decrypted) => { let _ = tx.send(decrypted); }, - Err(error) => { FridaLib::traceFromNative(env, format!("Decryption error! {:?}", error)); } + Err(error) => { ltx.send(format!("Decryption error! {:?}", error)); } } } else { - FridaLib::traceFromNative(env, "There is no static_secret".to_string()); + ltx.send("There is no static_secret".as_bytes()); } }, // payload - 2 => { FridaLib::traceFromNative(env, "Got keepalive packet".to_string()); }, - _ => { FridaLib::traceFromNative(env, "Unexpected header value.".to_string()); } + 2 => { ltx.send("Got keepalive packet".as_bytes()); }, + _ => { ltx.send("Unexpected header value.".as_bytes()); } } }, - None => { FridaLib::traceFromNative(env, "There is no header.".to_string()); } + None => { ltx.send("There is no header.".as_bytes()); } } drop(s_cipher); } @@ -132,13 +139,13 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32, env: &JNIE if let Ok(ciphered_d) = ciphered_data { let vpn_packet = UDPVpnPacket{ data: ciphered_d, nonce: nonce.to_vec()}; let serialized_data = vpn_packet.serialize(); - FridaLib::traceFromNative(env, "Write to socket".to_string()); + ltx.send("Write to socket".as_bytes()); sock_snd.send(&serialized_data).await.unwrap(); } else { - FridaLib::traceFromNative(env, "Socket encryption failed.".to_string()); + ltx.send("Socket encryption failed.".as_bytes()); } } else { - FridaLib::traceFromNative(env, "There is no shared_secret in main loop".to_string()); + ltx.send("There is no shared_secret in main loop".as_bytes()); } } }