Struct libelf::Elf [] [src]

pub struct Elf<'elf> { /* fields omitted */ }

A handle to an ELF file.

Methods

impl<'elf> Elf<'elf>
[src]

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

impl<'elf> Debug for Elf<'elf>
[src]

Formats the value using the given formatter.

impl<'elf> Drop for Elf<'elf>
[src]

A method called when the value goes out of scope. Read more