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.

Load an object from a file.

Load a dynamic loaded shared object.

handle is the address of the shared object. This value can be obtained by a function like dlopen.

Safety

This constructor is unsafe because we don’t check that the handle is a valid address.

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);

Returns an iterator to get all symbols in the PLT section.

Example

use plthook::ObjectFile;

let object = ObjectFile::open_main_program()?;
for symbol in object.symbols() {
    println!("{:?} {:?}", symbol.func_address, symbol.name);
}

Trait Implementations

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.