pub struct ObjectFile(/* private fields */);Expand description
An object file loaded in memory.
Please see the top-level documentation for more details.
Implementations§
Source§impl ObjectFile
impl ObjectFile
Sourcepub fn open_main_program() -> Result<Self>
pub fn open_main_program() -> Result<Self>
Load the object for the main program.
Sourcepub unsafe fn open_by_handle(handle: *const c_void) -> Result<Self>
pub unsafe fn open_by_handle(handle: *const c_void) -> Result<Self>
Sourcepub unsafe fn replace(
&self,
symbol_name: &str,
func_address: *const c_void,
) -> Result<Replacement>
pub unsafe fn replace( &self, symbol_name: &str, func_address: *const c_void, ) -> Result<Replacement>
Replace the address of a symbol in the PLT section, and returns a reference to the previous entry. When this reference is dropped, the entry is restored to the previous value.
The reference to the previous entry can be used to invoke the original function.
§Safety
The caller has to verify that the new address for the symbol is valid.
The function is not thread-safe.
§Example
use plthook::ObjectFile;
use std::process;
let pid = process::id();
extern "C" fn broken_getpid() -> libc::pid_t {
-1
}
let replacement = unsafe {
ObjectFile::open_main_program()
.unwrap()
.replace("getpid", broken_getpid as *const _)
.unwrap()
};
assert_eq!(process::id(), u32::MAX);
drop(replacement);
assert_eq!(process::id(), pid);Auto Trait Implementations§
impl Freeze for ObjectFile
impl RefUnwindSafe for ObjectFile
impl !Send for ObjectFile
impl !Sync for ObjectFile
impl Unpin for ObjectFile
impl UnwindSafe for ObjectFile
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