Struct libelf::Elf

source · []
pub struct Elf<'elf> { /* private fields */ }
Expand description

A handle to an ELF file.

Implementations

Open an Elf from a path.

Examples
let exe = std::env::current_exe().unwrap();
let elf = libelf::Elf::open(exe).unwrap();

Create an Elf from an open file.

Examples
let exe = std::env::current_exe().unwrap();
let f = std::fs::File::open(exe).unwrap();
let elf = libelf::Elf::from_fd(&f).unwrap();

Create an Elf from a byte slice.

Examples
use std::io::Read;
let exe = std::env::current_exe().unwrap();
let mut buf = vec![];
std::fs::File::open(exe).unwrap()
    .read_to_end(&mut buf).unwrap();

let elf = libelf::Elf::from_bytes(&buf).unwrap();
// elfutils doesn't mind an empty ELF!
let empty = libelf::Elf::from_bytes(&[]).unwrap();

Create an Elf from a raw FFI pointer.

Safety

This function is unsafe because there is no guarantee that the given pointer is a valid libelf handle, nor whether the lifetime inferred is appropriate. This does not take ownership of the underlying object, so the caller must ensure it outlives the returned Elf wrapper.

Get a raw FFI pointer

Examples
let ptr = elf.as_ptr();
assert!(!ptr.is_null());
let base = unsafe { libelf::raw::elf_getbase(ptr) };
assert!(base >= 0);

Trait Implementations

Formats the value using the given formatter. Read more

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.