Struct Elf

Source
pub struct Elf { /* private fields */ }
Expand description

Represents a parsed ELF (Executable and Linkable Format) file.

The ELF format is a common standard file format for executable files, object code, shared libraries, and core dumps.

Implementations§

Source§

impl Elf

Source

pub fn load<P: AsRef<Path>>(path: P) -> ParseElfResult<Elf>

Loads an ELF file from disk and parses it

§Errors

Returns ‘Err’ if the file can not be loaded or if parsing fails, with a description of the failure

§Examples
let elf = Elf::load("examples/example-binary").unwrap();
Source

pub fn parse<R: Read + Seek>(reader: &mut R) -> ParseElfResult<Elf>

Parses an ELF file from a reader source

‘reader’ can be anything that implements both ‘Read’ and ‘Seek’

§Errors

Returns ‘Err’ if parsing fails, with a description of what caused the failure

§Examples
let mut buf = std::io::BufReader::new(file);
let elf = Elf::parse(&mut buf).unwrap();
Source

pub fn try_get_section(&self, section_name: &str) -> Option<&Section>

Tries to retrieve a section by name, returns ‘None’ if the section does not exist

§Examples
 
let elf = Elf::load("examples/example-binary").unwrap();
let text = elf.try_get_section(".text").unwrap();
 
assert_eq!(SectionFlags::AllocExecute, text.header().flags());
Source

pub fn header(&self) -> &ElfHeader

Returns the ELF files header

Source

pub fn sections(&self) -> SectionIter<'_>

Returns an Iterator that iterates over references of sections contained in this Elf file

Source

pub fn segments(&self) -> SegmentIter<'_>

Returns an Iterator that iterates over references of program headers contained in this Elf file

Trait Implementations§

Source§

impl Debug for Elf

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Elf

§

impl RefUnwindSafe for Elf

§

impl Send for Elf

§

impl Sync for Elf

§

impl Unpin for Elf

§

impl UnwindSafe for Elf

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.