Skip to content

Commit

Permalink
only inject when vorbis is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady committed Jul 12, 2024
1 parent b622539 commit 3e3b31b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
55 changes: 54 additions & 1 deletion src-tauri/src/injector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,69 @@ 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);

// 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);
let ten_millis = std::time::Duration::from_millis(1000);
std::thread::sleep(ten_millis);

if times == 10 {
Expand Down

0 comments on commit 3e3b31b

Please sign in to comment.