|
1 | | -use log::{debug, error}; |
2 | | -use windows::Win32::{ |
3 | | - Foundation::{GetLastError, WIN32_ERROR}, |
4 | | - System::Memory::{VirtualProtect, PAGE_EXECUTE_READWRITE, PAGE_PROTECTION_FLAGS}, |
5 | | -}; |
6 | | - |
7 | | -const PATCH_ADDRESS: u32 = 0x00532FF3; |
8 | | - |
9 | | -#[no_mangle] |
10 | | -pub unsafe extern "C" fn start() -> u32 { |
11 | | - let _ = log::set_logger(&win_dbg_logger::DEBUGGER_LOGGER); |
12 | | - log::set_max_level(log::LevelFilter::Trace); |
13 | | - let patch_ptr: *mut u8 = PATCH_ADDRESS as _; |
14 | | - |
15 | | - let mut old_flags: PAGE_PROTECTION_FLAGS = windows::Win32::System::Memory::PAGE_PROTECTION_FLAGS(0); |
16 | | - if !VirtualProtect(patch_ptr as _, 5, PAGE_EXECUTE_READWRITE, &mut old_flags).as_bool() { |
17 | | - let error: WIN32_ERROR = GetLastError(); |
18 | | - error!("VirtualProtect PAGE_EXECUTE_READWRITE failed: {:?}", error); |
19 | | - return 1; |
20 | | - } |
21 | | - |
22 | | - debug!("Patching comparison at {:#x}", PATCH_ADDRESS); |
23 | | - *patch_ptr = 0x04; |
24 | | - |
25 | | - if !VirtualProtect(patch_ptr as _, 5, old_flags, &mut old_flags).as_bool() { |
26 | | - let error: WIN32_ERROR = GetLastError(); |
27 | | - error!("VirtualProtect restore failed: {:?}", error); |
28 | | - return 2; |
29 | | - } |
30 | | - |
31 | | - 0 |
32 | | -} |
| 1 | +use hooklet::windows::x86::replace_slice_rwx; |
| 2 | +use log::{debug, error}; |
| 3 | + |
| 4 | +const SUBTRACTION_PATCH_ADDRESS: u32 = 0x00532FF3; |
| 5 | +const WHALEOIL_PATCH_ADDRESS: u32 = 0x00533013; |
| 6 | + |
| 7 | +#[no_mangle] |
| 8 | +pub unsafe extern "C" fn start() -> u32 { |
| 9 | + let _ = log::set_logger(&win_dbg_logger::DEBUGGER_LOGGER); |
| 10 | + log::set_max_level(log::LevelFilter::Trace); |
| 11 | + |
| 12 | + debug!("Patching `sub` immediate value at {:#x}", SUBTRACTION_PATCH_ADDRESS); |
| 13 | + let subtraction_patch = [4]; |
| 14 | + match replace_slice_rwx(SUBTRACTION_PATCH_ADDRESS, &subtraction_patch) { |
| 15 | + Ok(_) => {} |
| 16 | + Err(e) => { |
| 17 | + error!("Failed to deploy patch: {:?}", e); |
| 18 | + return 1; |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + debug!("Patching whaleoil `or` immediate value at {:#x}", SUBTRACTION_PATCH_ADDRESS); |
| 23 | + let whaleoil_patch = 0x20002u32.to_le_bytes(); |
| 24 | + match replace_slice_rwx(WHALEOIL_PATCH_ADDRESS, &whaleoil_patch) { |
| 25 | + Ok(_) => {} |
| 26 | + Err(e) => { |
| 27 | + error!("Failed to deploy patch: {:?}", e); |
| 28 | + return 2; |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + 0 |
| 33 | +} |
0 commit comments