This crates provides Rust bindings for the [plthook] library.
Please see the [API documentation] and the description in the [plthook] library for more details.
To print symbols in the current process:
```rust use plthook::ObjectFile;
fn main() { let object = ObjectFile::openmainprogram().unwrap();
for symbol in object.symbols() {
println!("{:?} {:?}", symbol.func_address, symbol.name);
}
} ```
To replace a symbol:
```rust use plthook::ObjectFile; use std::mem::{self, MaybeUninit}; use std::os::raw::{cchar, cint};
static mut ATOIFN: MaybeUninit
extern "C" fn negatoi(nptr: *const cchar) -> cint { let i = unsafe { (ATOIFN.assume_init())(nptr) }; -i }
fn main() { let object = ObjectFile::openmainprogram().expect("Failed to open main program");
unsafe {
let mut atoi_entry = object.replace("atoi", neg_atoi as *const _).unwrap();
ATOI_FN = MaybeUninit::new(mem::transmute(atoi_entry.original_address()));
atoi_entry.discard();
};
let i = unsafe { libc::atoi(b"100\0".as_ptr().cast()) };
assert_eq!(i, -100);
} ```