hk4e-patch/src/marshal.rs

16 lines
525 B
Rust
Raw Normal View History

2024-04-10 19:35:01 +00:00
use std::ffi::CStr;
2024-08-29 22:30:44 +00:00
use windows::{core::PCSTR, Win32::System::LibraryLoader::GetModuleHandleA};
2024-04-10 19:35:01 +00:00
2024-08-29 22:30:44 +00:00
const PTR_TO_STRING_ANSI: usize = 0xF33F640;
2024-04-10 19:35:01 +00:00
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 {
2024-08-29 22:30:44 +00:00
GetModuleHandleA(PCSTR::null()).unwrap().0 as usize
2024-04-10 19:35:01 +00:00
}