diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index cb47ea94..5a2af045 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2763,6 +2763,7 @@ dependencies = [ "tauri-build", "tauri-plugin-upload", "tokio", + "winapi", "winreg 0.52.0", ] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 8eb664b7..2b43ffb0 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -36,6 +36,7 @@ actix-web = "4.4.1" actix-rt = "2.9.0" actix-cors = "0.7.0" clap = "4.5.7" +winapi = "0.3.9" [target.'cfg(target_os = "windows")'.dependencies] dll-syringe = "0.15.2" diff --git a/src-tauri/src/injector.rs b/src-tauri/src/injector.rs index 66107a45..cbb825ce 100644 --- a/src-tauri/src/injector.rs +++ b/src-tauri/src/injector.rs @@ -108,8 +108,61 @@ pub async fn run_samp( #[cfg(target_os = "windows")] pub fn inject_dll(child: u32, dll_path: &str, times: u32) -> Result<(), String> { + use winapi::{ + shared::minwindef::{FALSE, HMODULE}, + um::{ + processthreadsapi::OpenProcess, + psapi::{EnumProcessModulesEx, GetModuleFileNameExA}, + winnt::PROCESS_ALL_ACCESS, + }, + }; + match OwnedProcess::from_pid(child) { Ok(p) => { + unsafe { + let handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, child); + let mut module_handles: [HMODULE; 1024] = [0 as *mut _; 1024]; + let mut found = 0; + + EnumProcessModulesEx( + handle, + module_handles.as_mut_ptr(), + module_handles.len() as _, + &mut found, + 0x03, + ); + + let mut bytes = [0i8; 1024]; + + if found == 0 { + let ten_millis = std::time::Duration::from_millis(500); + std::thread::sleep(ten_millis); + return inject_dll(child, dll_path, times); + } + + let mut found_vorbis = false; + for i in 0..(found / 4) { + if GetModuleFileNameExA( + handle, + module_handles[i as usize], + bytes.as_mut_ptr(), + 1024, + ) != 0 + { + let string = std::ffi::CStr::from_ptr(bytes.as_ptr()); + if string.to_string_lossy().to_string().contains("vorbis") { + found_vorbis = true; + } + } + } + + if !found_vorbis { + let ten_millis = std::time::Duration::from_millis(500); + std::thread::sleep(ten_millis); + return inject_dll(child, dll_path, times); + } + } + // create a new syringe for the target process let syringe = Syringe::for_process(p); @@ -117,7 +170,7 @@ pub fn inject_dll(child: u32, dll_path: &str, times: u32) -> Result<(), String> match syringe.inject(dll_path) { Ok(_) => Ok(()), Err(e) => { - let ten_millis = std::time::Duration::from_millis(500); + let ten_millis = std::time::Duration::from_millis(1000); std::thread::sleep(ten_millis); if times == 10 {