Struct ElfParser

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

An 32-bit/64-bit ELF parser.

Implementations§

Source§

impl ElfParser

Source

pub fn parse_elf_file<'a>( &'a self, b: &'a [u8], ) -> Result<ElfFile, ElfParserError<&'a [u8]>>

parses the entire of the given ELF file.

Examples found in repository?
examples/demo.rs (line 16)
3fn main() {
4    let args: Vec<String> = args().collect();
5    if args.len() != 2 {
6        panic!("usage: demo <elf-filepath>")
7    }
8
9    let mut f = File::open(&args[1]).expect("failed to open elf-file");
10
11    let mut buf = Vec::with_capacity(4096);
12    let _ = f.read_to_end(&mut buf).expect("failed to read elf-file");
13
14    let parser = pelf::parser::ElfParserConfig::new().build();
15    let elf = parser
16        .parse_elf_file(&buf)
17        .expect("failed to parse elf-file");
18
19    match elf {
20        pelf::file::ElfFile::Elf64(elf64) => {
21            dump_elf64_file(elf64);
22        }
23        _ => unimplemented!(),
24    }
25}
Source

pub fn parse_raw_elf_file<'a>( &'a self, b: &'a [u8], ) -> Result<RawElfFile, ElfParserError<&'a [u8]>>

parses the entire of the given ELF file. that may return the “raw” representation of the ELF file.

Examples found in repository?
examples/raw-demo.rs (line 16)
3fn main() {
4    let args: Vec<String> = args().collect();
5    if args.len() != 2 {
6        panic!("usage: demo <elf-filepath>")
7    }
8
9    let mut f = File::open(&args[1]).expect("failed to open elf-file");
10
11    let mut buf = Vec::with_capacity(4096);
12    let _ = f.read_to_end(&mut buf).expect("failed to read elf-file");
13
14    let parser = pelf::parser::ElfParserConfig::new().build();
15    let elf = parser
16        .parse_raw_elf_file(&buf)
17        .expect("failed to parse elf-file");
18
19    match elf {
20        pelf::file::RawElfFile::Elf64(elf64) => {
21            dump_elf64_file(elf64);
22        }
23        _ => unimplemented!(),
24    }
25}

Trait Implementations§

Source§

impl Default for ElfParser

Source§

fn default() -> ElfParser

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.