Skip to content

Commit

Permalink
inject samp sooner if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady committed Aug 18, 2024
1 parent bd2646f commit 7c608ff
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 43 deletions.
101 changes: 58 additions & 43 deletions src-tauri/src/injector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ pub async fn run_samp(
match process {
Ok(p) => {
// let target_process = .unwrap();
match inject_dll(p.id(), dll_path, 0) {
Ok(_) => inject_dll(p.id(), omp_file, 0),
match inject_dll(p.id(), dll_path, 0, false) {
Ok(_) => inject_dll(p.id(), omp_file, 0, false),
Err(e) => {
return Err(e);
}
Expand All @@ -114,7 +114,12 @@ pub async fn run_samp(
}

#[cfg(target_os = "windows")]
pub fn inject_dll(child: u32, dll_path: &str, times: u32) -> Result<(), String> {
pub fn inject_dll(
child: u32,
dll_path: &str,
times: u32,
waiting_for_vorbis: bool,
) -> Result<(), String> {
use winapi::{
shared::minwindef::{FALSE, HMODULE},
um::{
Expand All @@ -126,47 +131,49 @@ pub fn inject_dll(child: u32, dll_path: &str, times: u32) -> Result<(), String>

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);
}
if waiting_for_vorbis {
unsafe {
let handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, child);
let mut module_handles: [HMODULE; 1024] = [0 as *mut _; 1024];
let mut found = 0;

let mut found_vorbis = false;
for i in 0..(found / 4) {
if GetModuleFileNameExA(
EnumProcessModulesEx(
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;
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, true);
}

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);
if !found_vorbis {
let ten_millis = std::time::Duration::from_millis(500);
std::thread::sleep(ten_millis);
return inject_dll(child, dll_path, times, true);
}
}
}

Expand All @@ -177,18 +184,26 @@ 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(1000);
let ten_millis = std::time::Duration::from_millis(500);
std::thread::sleep(ten_millis);

if times == 10 {
if times == 5 {
info!(
"[injector.rs] Dll {} injection failed: {}",
"[injector.rs] Initial DLL {} injection failed: {}",
dll_path,
e.to_string()
);

if !waiting_for_vorbis {
return inject_dll(child, dll_path, 0, true);
}
Err(format!("Injecting dll failed: {}", e.to_string()))
} else {
inject_dll(child, dll_path, times + 1)
if !waiting_for_vorbis {
inject_dll(child, dll_path, times + 1, false)
} else {
inject_dll(child, dll_path, times + 1, true)
}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::sync::Mutex;
use gumdrop::Options;
use injector::run_samp;
use log::{error, info, LevelFilter};
// use std::io::Read;
use tauri::Manager;
use tauri::PhysicalSize;

Expand Down Expand Up @@ -46,6 +47,12 @@ async fn get_uri_scheme_value() -> String {

#[tokio::main]
async fn main() {
// let mut f = std::fs::File::open("D:\\Projects\\open.mp\\Launcher-tauri\\omp-launcher\\omp-client.dll").unwrap();
// let mut contents = Vec::<u8>::new();
// f.read_to_end(&mut contents).unwrap();
// let digest = md5::compute(contents.as_slice());
// println!("{:x}", digest);

tauri_plugin_deep_link::prepare("com.open.mp");
simple_logging::log_to_file("omp-launcher.log", LevelFilter::Info).unwrap();

Expand Down

0 comments on commit 7c608ff

Please sign in to comment.