inline_hooks_config/common/
mod.rs1#![allow(dead_code)]
5
6use dobby_rs_framework::framework::ModuleHandle;
7use dobby_rs_framework::prelude::{LogOptions, init_logging};
8use dobby_rs_framework::{Error, Result};
9use std::ffi::CString;
10
11#[inline(never)]
15pub fn target_add(x: i32) -> i32 {
16 x + 1
17}
18
19#[inline(never)]
20pub fn target_mul(x: i32) -> i32 {
21 x * 2
22}
23
24#[inline(never)]
25pub fn target_sub(x: i32) -> i32 {
26 x - 1
27}
28
29pub fn init_example_logging() {
32 let _ = init_logging(LogOptions::default());
33}
34
35#[cfg(windows)]
39pub const DEMO_LIB: &str = "kernel32.dll";
40#[cfg(target_os = "linux")]
41pub const DEMO_LIB: &str = "libc.so.6";
42#[cfg(target_os = "macos")]
43pub const DEMO_LIB: &str = "/usr/lib/libSystem.B.dylib";
44
45#[cfg(target_os = "linux")]
48pub const LIBC_IMAGE: &str = "libc.so.6";
49#[cfg(target_os = "macos")]
50pub const LIBC_IMAGE: &str = "/usr/lib/libSystem.B.dylib";
51
52pub fn resolve_and_print(m: &ModuleHandle, symbol: &str) -> Result<()> {
55 let c = CString::new(symbol).map_err(|_| Error::InvalidInput)?;
56 let p = m.resolve(c.as_c_str()).ok_or(Error::SymbolNotFound)?;
57 println!("module.resolve({symbol}) = {p:p}");
58 Ok(())
59}
60
61pub mod detours {
64 #[cfg(unix)]
65 pub mod unix {
66 use core::ffi::{c_char, c_int};
67
68 pub type PutsFn = unsafe extern "C" fn(*const c_char) -> c_int;
69
70 #[inline(never)]
71 pub unsafe extern "C" fn detour_puts(s: *const c_char) -> c_int {
72 let original: PutsFn = dobby_rs_framework::dobby_original!(detour_puts, PutsFn);
73 unsafe { original(s) }
74 }
75 }
76
77 #[cfg(windows)]
78 pub mod windows {
79 pub type GetTickCountFn = unsafe extern "system" fn() -> u32;
80 pub type GetCurrentProcessIdFn = unsafe extern "system" fn() -> u32;
81
82 #[inline(never)]
83 pub unsafe extern "system" fn detour_get_tick_count() -> u32 {
84 let original: GetTickCountFn =
85 dobby_rs_framework::dobby_original!(detour_get_tick_count, GetTickCountFn);
86 (unsafe { original() }) + 1
87 }
88
89 #[inline(never)]
90 pub unsafe extern "system" fn detour_get_current_process_id() -> u32 {
91 let original: GetCurrentProcessIdFn = dobby_rs_framework::dobby_original!(
92 detour_get_current_process_id,
93 GetCurrentProcessIdFn
94 );
95 unsafe { original() }
96 }
97 }
98}