From f33c8dbf43ee594b96d886323185a008d0c533a6 Mon Sep 17 00:00:00 2001 From: amelia <44528100+pozm@users.noreply.github.com> Date: Sat, 11 May 2024 22:02:16 +0100 Subject: [PATCH] fix filling bug --- Cargo.lock | 2 +- Cargo.toml | 2 +- gdkeinj/src/lib.rs | 25 +++++++++++++++++-------- src/lib.rs | 7 ++++++- src/main.rs | 2 +- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 26a1ba3..d8ef274 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -261,7 +261,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "gdke" -version = "0.2.0" +version = "0.2.2" dependencies = [ "anyhow", "dll-syringe", diff --git a/Cargo.toml b/Cargo.toml index 9f1d181..ced361b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ workspace = { members = ["gdkeinj"] } [package] name = "gdke" -version = "0.2.0" +version = "0.2.2" edition = "2021" [profile.release] diff --git a/gdkeinj/src/lib.rs b/gdkeinj/src/lib.rs index 7f99107..44c36b2 100644 --- a/gdkeinj/src/lib.rs +++ b/gdkeinj/src/lib.rs @@ -1,5 +1,10 @@ use std::{ - collections::HashMap, ffi::c_void, mem::size_of, net::UdpSocket, ptr::null, time::Duration, + collections::HashMap, + ffi::c_void, + mem::size_of, + net::UdpSocket, + ptr::{null, slice_from_raw_parts}, + time::Duration, }; use poggers::{ @@ -36,7 +41,7 @@ fn find_sig_addr(sig_type: usize) -> Result<*const c_void, SigErrors> { .scan(sig) .map_err(|_| SigErrors::NotFound)? .ok_or(SigErrors::NotFound)? as isize; - let ptr_to_fn = (addr as usize + 1) as *const u8; + let ptr_to_fn = (addr as usize + size_of::()) as *const u8; let mut addr_offset = [0; 4]; unsafe { std::ptr::copy(ptr_to_fn, addr_offset.as_mut_ptr(), 4) }; let by = i32::from_ne_bytes(addr_offset); @@ -69,22 +74,26 @@ pub fn main() { println!("err {err:?}"); std::thread::sleep(Duration::from_secs(100)); - sock.send(&[err as u8]).ok(); + // sock.send(&[err as u8]).ok(); return; } }; - println!("sending fnptr"); + println!("hooking fnptr"); let sock2 = sock.try_clone().unwrap(); unsafe { let open_and_parse = std::mem::transmute::(fn_ptr as isize); let opp = OpenAndParse .initialize(open_and_parse, move |_, _, key, _| { println!("hook has been called"); - let mut read_key = [0u8; 32]; let ptr_to_key = (key as usize + 8) as *const *const u8; - std::ptr::copy(*ptr_to_key, read_key.as_mut_ptr(), 32); - sock2.send(read_key.as_slice()).unwrap(); + println!("key ptr = {:p}", ptr_to_key); + #[cfg(debug_assertions)] + { + println!("[debug] waiting for input"); + std::io::stdin().read_line(&mut String::new()); + } + sock2.send(&*slice_from_raw_parts(*ptr_to_key, 32)).unwrap(); std::thread::sleep(Duration::from_secs(1000)) // panic!("good ridance.") }) @@ -92,5 +101,5 @@ pub fn main() { opp.enable().expect("failed to enable detour"); println!("detour enabled {}", opp.is_enabled()); } - sock.send(&(400195u32.to_ne_bytes())).ok(); + sock.send(&[0, 0, 0, 0]).ok(); } diff --git a/src/lib.rs b/src/lib.rs index 78d316d..a22d2e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -165,7 +165,12 @@ pub unsafe fn spawn_and_inject(proc: &str) -> anyhow::Result<[u8; 32]> { let mut error = [0u8; 4]; sock.recv(&mut error)?; println!("errors -> {error:?}"); - if error.is_empty() { + if error.iter().all(|x| *x != 0) { + #[cfg(debug_assertions)] + { + println!("[debug] waiting for input"); + std::io::stdin().read_line(&mut String::new()); + } return Err(SigErrors::from(error[0]).into()); } Ok(()) diff --git a/src/main.rs b/src/main.rs index 0329f95..530730d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ fn main() { spawn_and_inject(&std::env::args().nth(1).unwrap()).expect("failed to resolve key"); print!("key: "); for val in key { - print!("{:x}", val); + print!("{:0>2x}", val); } println!("\npress enter to close"); let _ = std::io::stdin().read_line(&mut String::new());