diff --git a/Cargo.lock b/Cargo.lock index aac3692..17dd16a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -226,6 +226,8 @@ dependencies = [ "frida", "goblin", "lazy_static", + "serde", + "serde_json", "winapi", ] @@ -854,6 +856,20 @@ name = "serde" version = "1.0.163" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.163" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.16", +] [[package]] name = "serde_json" diff --git a/Cargo.toml b/Cargo.toml index 7afa1a9..7f75422 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,10 +14,14 @@ path = "src/main.rs" # frida = { version = "0.4.0", features = ["auto-download"] } frida = { git = "https://github.com/dzervas/frida-rust", features = ["auto-download"] } lazy_static = "1.4.0" -ctor = "0.2.0" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" [target.'cfg(windows)'.dependencies] winapi = { version = "0.3.9", features = ["winnt", "libloaderapi"] } +[target.'cfg(unix)'.dependencies] +ctor = "0.2.0" + [build-dependencies] goblin = "0.6.1" diff --git a/src/injector.rs b/src/injector.rs index 497502f..26f754f 100644 --- a/src/injector.rs +++ b/src/injector.rs @@ -1,4 +1,5 @@ use frida::{DeviceManager, Frida, ScriptHandler, ScriptOption, ScriptRuntime}; +use serde::Deserialize; use lazy_static::lazy_static; lazy_static! { @@ -8,7 +9,7 @@ lazy_static! { #[no_mangle] pub fn attach(pid: u32) { let frida_code = env!("FRIDA_CODE").to_string(); - println!("[*] Injecting into PID: {}", pid); + println!("[+] Injecting into PID: {}", pid); std::thread::spawn(move || { let device_manager = DeviceManager::obtain(&FRIDA); @@ -23,7 +24,7 @@ pub fn attach(pid: u32) { println!("[*] Attached"); let mut script_option = ScriptOption::new() - .set_name("frida-deepfreeze-rs") + // .set_name("frida-deepfreeze-rs") .set_runtime(ScriptRuntime::QJS); println!("[*] Script {}", frida_code); let script = session @@ -36,7 +37,7 @@ pub fn attach(pid: u32) { println!("[*] Script loaded"); } } else { - println!("[!] No device found!"); + eprintln!("[!] No device found!"); }; }); } @@ -47,10 +48,52 @@ pub fn attach_self() { attach(0); } +#[derive(Debug, Deserialize)] +struct LogEntry { + #[serde(rename = "type")] + log_type: LogType, + level: LogLevel, + payload: String, +} + +#[derive(Debug, Deserialize)] +enum LogType { + #[serde(rename = "log")] + Log, +} + +#[derive(Debug, Deserialize)] +enum LogLevel { + #[serde(rename = "debug")] + Debug, + #[serde(rename = "info")] + Info, + #[serde(rename = "warning")] + Warning, + #[serde(rename = "error")] + Error, +} + struct Handler; impl ScriptHandler for Handler { fn on_message(&mut self, message: &str) { - eprintln!("[<] {message}"); + if let Ok(log_entry) = serde_json::from_str::(message) { + match log_entry.log_type { + LogType::Log => { + match log_entry.level { + LogLevel::Debug => eprint!("[-] "), + LogLevel::Info => eprint!("[i] "), + LogLevel::Warning => eprint!("[!] "), + LogLevel::Error => eprint!("[X] "), + } + } + } + + eprintln!("{}", log_entry.payload); + return; + } + + eprintln!("{message}"); } }