pub struct Elf<'elf> { /* private fields */ }
Expand description
A handle to an ELF file.
Implementations
sourceimpl<'elf> Elf<'elf>
impl<'elf> Elf<'elf>
sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Elf<'static>>
pub fn open<P: AsRef<Path>>(path: P) -> Result<Elf<'static>>
Open an Elf
from a path.
Examples
let exe = std::env::current_exe().unwrap();
let elf = libelf::Elf::open(exe).unwrap();
sourcepub fn from_fd<FD: AsRawFd>(fd: &'elf FD) -> Result<Elf<'elf>>
pub fn from_fd<FD: AsRawFd>(fd: &'elf FD) -> Result<Elf<'elf>>
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();
sourcepub fn from_bytes(bytes: &'elf [u8]) -> Result<Elf<'elf>>
pub fn from_bytes(bytes: &'elf [u8]) -> Result<Elf<'elf>>
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();
sourcepub unsafe fn from_raw(elf: *mut Elf) -> Elf<'elf>
pub unsafe fn from_raw(elf: *mut Elf) -> Elf<'elf>
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.
Trait Implementations
Auto Trait Implementations
impl<'elf> !RefUnwindSafe for Elf<'elf>
impl<'elf> !Send for Elf<'elf>
impl<'elf> !Sync for Elf<'elf>
impl<'elf> Unpin for Elf<'elf>
impl<'elf> !UnwindSafe for Elf<'elf>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more