Struct plthook::ObjectFile [−][src]
pub struct ObjectFile { /* fields omitted */ }Expand description
An object file loaded in memory.
Please see the top-level documentation for more details.
Implementations
Load the object for the main program.
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 program = ObjectFile::open_main_program().unwrap(); let entry = unsafe { program.replace("getpid", broken_getpid as *const _).unwrap() }; assert_eq!(process::id(), u32::MAX); drop(entry); assert_eq!(process::id(), pid);