Add ability to spawn or attach by process name

Signed-off-by: Dimitris Zervas <dzervas@dzervas.gr>
This commit is contained in:
Dimitris Zervas
2024-04-15 21:49:55 +03:00
parent b6a48d5155
commit ff5a7f152f
5 changed files with 174 additions and 49 deletions

View File

@ -3,7 +3,8 @@
compile_error!("No injection method is selected - please enable either dotnet (windows-only) and/or frida feature");
#[cfg(feature = "frida")]
use crate::frida_handler::attach_pid as frida_attach_pid;
use crate::frida_handler::attach_with as frida_attach_with;
use crate::frida_handler::AttachMode;
#[no_mangle]
pub extern "C" fn attach(pid: u32) {
@ -11,9 +12,26 @@ pub extern "C" fn attach(pid: u32) {
{
let frida_code = env!("FRIDA_CODE").replace("\\n", "\n");
#[cfg(windows)]
std::thread::spawn(move || frida_attach_pid(&frida_code, pid));
std::thread::spawn(move || frida_attach_pid(&frida_code, AttachMode::Pid(pid)));
#[cfg(not(windows))]
frida_attach_pid(&frida_code, pid);
frida_attach_with(&frida_code, AttachMode::Pid(pid));
}
}
#[no_mangle]
pub extern "C" fn attach_name(name: *const u8, len: usize) {
let name_str = unsafe {
let buf = std::slice::from_raw_parts(name, len);
std::str::from_utf8(buf).expect("Invalid UTF-8 in process name")
};
#[cfg(feature = "frida")]
{
let frida_code = env!("FRIDA_CODE").replace("\\n", "\n");
#[cfg(windows)]
std::thread::spawn(move || frida_attach_with(&frida_code, AttachMode::Name(name_str.to_string())));
#[cfg(not(windows))]
frida_attach_with(&frida_code, AttachMode::Name(name_str.to_string()));
}
}
@ -22,3 +40,22 @@ pub extern "C" fn attach_self() {
println!("[*] Attaching to self");
attach(0);
}
#[no_mangle]
pub extern "C" fn spawn(name: *const u8, len: usize) {
let name_str = unsafe {
let buf = std::slice::from_raw_parts(name, len);
std::str::from_utf8(buf).expect("Invalid UTF-8 in spawn name")
};
println!("[*] Spawning: {name_str}");
#[cfg(feature = "frida")]
{
let frida_code = env!("FRIDA_CODE").replace("\\n", "\n");
#[cfg(windows)]
std::thread::spawn(move || frida_attach_with(&frida_code, AttachMode::Spawn(name_str.to_string())));
#[cfg(not(windows))]
frida_attach_with(&frida_code, AttachMode::Spawn(name_str.to_string()));
}
}