hk4e-patch/src/marshal.rs
2024-10-31 02:05:41 +03:00

15 lines
525 B
Rust

use std::ffi::CStr;
use windows::{core::PCSTR, Win32::System::LibraryLoader::GetModuleHandleA};
const PTR_TO_STRING_ANSI: usize = 0xF85E020;
type MarshalPtrToStringAnsi = unsafe extern "fastcall" fn(*const u8) -> *const u8;
pub unsafe fn ptr_to_string_ansi(content: &CStr) -> *const u8 {
let func = std::mem::transmute::<usize, MarshalPtrToStringAnsi>(base() + PTR_TO_STRING_ANSI);
func(content.to_bytes_with_nul().as_ptr())
}
unsafe fn base() -> usize {
GetModuleHandleA(PCSTR::null()).unwrap().0 as usize
}