modified: src/main.rs
Some checks failed
gitea/Frida-android-native/pipeline/head There was a failure building this commit
Some checks failed
gitea/Frida-android-native/pipeline/head There was a failure building this commit
new file: src/simple_log.rs
This commit is contained in:
parent
e5a2949172
commit
ef5339f595
12
src/main.rs
12
src/main.rs
@ -11,12 +11,13 @@ use env_logger::Builder;
|
||||
use log::{error, LevelFilter};
|
||||
use crate::config::{ ServerConfiguration, ClientConfiguration, ObfsProtocol, ServerPeer };
|
||||
use fast32::base32::RFC4648;
|
||||
use crossbeam_channel::unbounded;
|
||||
|
||||
mod config;
|
||||
mod client;
|
||||
mod udp;
|
||||
mod mobile;
|
||||
|
||||
mod simple_log;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn Java_com_alterdekim_frida_FridaLib_run(
|
||||
@ -26,11 +27,20 @@ pub unsafe extern "C" fn Java_com_alterdekim_frida_FridaLib_run(
|
||||
tun_fd: jint,
|
||||
close_fd_on_drop: jboolean,
|
||||
) -> jint {
|
||||
simple_log::init_logger();
|
||||
let config = env.get_string(config_b32).unwrap().into();
|
||||
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_fetchLogs(
|
||||
mut env: JNIEnv,
|
||||
_clazz: JClass
|
||||
) -> JString {
|
||||
String::from_utf8_lossy(simple_log::fetch_logs())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn Java_com_alterdekim_frida_FridaLib_stop(_env: JNIEnv, _: JClass) -> jint {
|
||||
mobile::mobile_stop()
|
||||
|
56
src/simple_log.rs
Normal file
56
src/simple_log.rs
Normal file
@ -0,0 +1,56 @@
|
||||
struct ll {
|
||||
pub tx: Sender<Vec<u8>>,
|
||||
pub rx: Receiver<Vec<u8>>
|
||||
}
|
||||
|
||||
static l2: ll;
|
||||
|
||||
pub fn init_logger() {
|
||||
let (tx, rx) = unbounded::<Vec<u8>>();
|
||||
l2 = ll{tx, rx};
|
||||
}
|
||||
|
||||
pub fn fetch_logs() -> Vec<u8> {
|
||||
if let Ok(bytes) = l2.rx.recv() {
|
||||
bytes
|
||||
}
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
pub fn push_log(data: Vec<u8>) {
|
||||
l2.tx.send(data);
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
pub struct SimpleLogger {}
|
||||
|
||||
impl log::Log for SimpleLogger {
|
||||
fn enabled(&self, metadata: &log::Metadata) -> bool {
|
||||
metadata.level() <= log::Level::Trace
|
||||
}
|
||||
|
||||
fn log(&self, record: &log::Record) {
|
||||
if self.enabled(record.metadata()) {
|
||||
let current_crate_name = env!("CARGO_CRATE_NAME");
|
||||
if record.module_path().unwrap_or("").starts_with(current_crate_name) {
|
||||
self.do_log(record);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn flush(&self) {}
|
||||
}
|
||||
|
||||
impl SimpleLogger {
|
||||
fn do_log(&self, record: &log::Record) {
|
||||
let timestamp: chrono::DateTime<chrono::Local> = chrono::Local::now();
|
||||
let msg = format!(
|
||||
"[{} {:<5} {}] - {}",
|
||||
timestamp.format("%Y-%m-%d %H:%M:%S"),
|
||||
record.level(),
|
||||
record.module_path().unwrap_or(""),
|
||||
record.args()
|
||||
);
|
||||
simple_log::push_log(msg.to_vec());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user