ElfParser

Struct ElfParser 

Source
pub struct ElfParser<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> ElfParser<'a>

Source

pub fn new(data: &'a [u8]) -> Result<Self>

Examples found in repository?
examples/basic.rs (line 9)
3fn main() -> elflib::Result<()> {
4    // let mut content = std::fs::read("/lib/modules/6.2.0-34-generic/kernel/net/nfc/nfc.ko").unwrap();
5    // let mut content = std::fs::read("/usr/bin/ls").unwrap();
6    let mut content =
7        std::fs::read("./test_binaries/build/mips64-linux-gnuabi64-gcc-main").unwrap();
8
9    let parser = ElfParser::new(&mut content)?;
10    let sections = parser.section_headers()?;
11    for section_res in sections {
12        let section = section_res?;
13        match section.data()? {
14            elflib::SectionData::RelocationSection(rel_section) => {
15                for rel_entry_res in rel_section.entries {
16                    let rel_entry = rel_entry_res?;
17                    println!("{:?}", rel_entry);
18                }
19            }
20            elflib::SectionData::SymbolTable(symbol_entries) => {
21                for symbol_res in symbol_entries {
22                    let symbol = symbol_res?;
23                    println!("{:?}", symbol.name());
24                }
25            }
26            _ => {}
27        }
28    }
29    Ok(())
30}
Source

pub fn data(&self) -> &'a [u8]

Source

pub fn file_info(&self) -> ElfFileInfo

Source

pub fn header(&self) -> Result<ElfHeader>

Source

pub fn program_headers(&self) -> Result<ProgramHeaders<'a>>

Source

pub fn section_headers(&self) -> Result<SectionHeaders<'a>>

Examples found in repository?
examples/basic.rs (line 10)
3fn main() -> elflib::Result<()> {
4    // let mut content = std::fs::read("/lib/modules/6.2.0-34-generic/kernel/net/nfc/nfc.ko").unwrap();
5    // let mut content = std::fs::read("/usr/bin/ls").unwrap();
6    let mut content =
7        std::fs::read("./test_binaries/build/mips64-linux-gnuabi64-gcc-main").unwrap();
8
9    let parser = ElfParser::new(&mut content)?;
10    let sections = parser.section_headers()?;
11    for section_res in sections {
12        let section = section_res?;
13        match section.data()? {
14            elflib::SectionData::RelocationSection(rel_section) => {
15                for rel_entry_res in rel_section.entries {
16                    let rel_entry = rel_entry_res?;
17                    println!("{:?}", rel_entry);
18                }
19            }
20            elflib::SectionData::SymbolTable(symbol_entries) => {
21                for symbol_res in symbol_entries {
22                    let symbol = symbol_res?;
23                    println!("{:?}", symbol.name());
24                }
25            }
26            _ => {}
27        }
28    }
29    Ok(())
30}
Source

pub fn section_names_string_table(&self) -> Result<StringTable<'a>>

Trait Implementations§

Source§

impl<'a> Clone for ElfParser<'a>

Source§

fn clone(&self) -> ElfParser<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for ElfParser<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for ElfParser<'a>

§

impl<'a> RefUnwindSafe for ElfParser<'a>

§

impl<'a> Send for ElfParser<'a>

§

impl<'a> Sync for ElfParser<'a>

§

impl<'a> Unpin for ElfParser<'a>

§

impl<'a> UnwindSafe for ElfParser<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.