Skip to content

Commit

Permalink
make injection more fail proof
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady committed Dec 16, 2023
1 parent 0474707 commit 53c5615
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions src-tauri/src/injector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,7 @@ pub async fn run_samp(
match process {
Ok(p) => {
// let target_process = .unwrap();
match OwnedProcess::from_pid(p.id()) {
Ok(p) => {
// create a new syringe for the target process
let syringe = Syringe::for_process(p);

// inject the payload into the target process
match syringe.inject(dll_path) {
Ok(_) => Ok(()),
Err(e) => {
info!("[injector.rs] Dll injection failed: {}", e.to_string());
Err(format!("Injecting dll failed: {}", e.to_string()).to_owned())
}
}
}
Err(e) => {
info!("[injector.rs] Process creation failed: {}", e.to_string());
Err(format!("Finding GTASA process failed: {}", e.to_string()).to_owned())
}
}
inject_dll(p.id(), dll_path, 0)
}
Err(e) => {
info!("[injector.rs] Process creation failed: {}", e.to_string());
Expand All @@ -120,3 +102,33 @@ pub async fn run_samp(
}
}
}

#[cfg(target_os = "windows")]
pub fn inject_dll(child: u32, dll_path: &str, times: u32) -> Result<(), String> {
match OwnedProcess::from_pid(child) {
Ok(p) => {
// create a new syringe for the target process
let syringe = Syringe::for_process(p);

// inject the payload into the target process
match syringe.inject(dll_path) {
Ok(_) => Ok(()),
Err(e) => {
let ten_millis = std::time::Duration::from_millis(500);
std::thread::sleep(ten_millis);

if times == 10 {
info!("[injector.rs] Dll injection failed: {}", e.to_string());
Err(format!("Injecting dll failed: {}", e.to_string()).to_owned())
} else {
inject_dll(child, dll_path, times + 1)
}
}
}
}
Err(e) => {
info!("[injector.rs] Process creation failed: {}", e.to_string());
Err(format!("Finding GTASA process failed: {}", e.to_string()).to_owned())
}
}
}

0 comments on commit 53c5615

Please sign in to comment.