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

This commit is contained in:
Michael Wain 2024-10-07 22:18:46 +03:00
parent f68e7f2eb2
commit 94c216aff3

View File

@ -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::<Vec<u8>>();
let (tx, rx) = unbounded::<Vec<u8>>();
let (dx, mx) = unbounded::<Vec<u8>>();
let cipher_shared: Arc<Mutex<Option<x25519_dalek::SharedSecret>>> = 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());
}
}
}