pub struct Replacement { /* private fields */ }
Expand description
A replacement of an entry in the PLT section.
The address in the PLT entry is restored when this value is dropped.
Implementations§
Source§impl Replacement
impl Replacement
Sourcepub fn original_address(&self) -> *const c_void
pub fn original_address(&self) -> *const c_void
Returns the original address of the PLT entry.
This address can be used to invoke the function replaced by
ObjectFile::replace
.
§Example
use plthook::ObjectFile;
use std::mem;
extern "C" fn broken_getpid() -> libc::pid_t {
-1
}
let program = ObjectFile::open_main_program().unwrap();
let pid = unsafe { libc::getpid() };
assert_ne!(pid, -1);
// Replace getpid with our broken function.
let replacement = unsafe {
program.replace("getpid", broken_getpid as *const _).unwrap()
};
let libc_getpid: extern "C" fn() -> libc::pid_t = unsafe {
mem::transmute(replacement.original_address())
};
assert_eq!(unsafe { libc::getpid() }, -1);
assert_eq!(unsafe { (libc_getpid)() }, pid);
drop(replacement);
assert_eq!(unsafe { libc::getpid() }, pid);
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Replacement
impl RefUnwindSafe for Replacement
impl !Send for Replacement
impl !Sync for Replacement
impl Unpin for Replacement
impl UnwindSafe for Replacement
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more