Struct DynamicSectionAccessor

Source
pub struct DynamicSectionAccessor<'a> { /* private fields */ }
Expand description

A section data accessor intended to dynamic tables

For example:

use std::fs::File;
use std::io;
use std::io::{BufReader, Error};

use elfio::Elfio;

fn main() -> io::Result<()> {
    let elf_file = File::open("tests/files/hello_32")?;
    let mut reader = BufReader::new(elf_file);

    let mut elf = Elfio::new();

    elf.load(&mut reader)?;

    let section = match elf.get_section_by_name(&".dynamic") {
        Some(s) => s,
        None => return Err(Error::new(io::ErrorKind::Other, "section not found")),
    };

    let dyns = elfio::DynamicSectionAccessor::new(&elf, section);

    assert_eq!(dyns.get_entries_num(), 20);

    // Dynamic section at offset 0x4a0 contains 20 entries:
    //   Tag        Type                         Name/Value
    //  0x00000001 (NEEDED)                     Shared library: [libc.so.6]
    //  0x0000000c (INIT)                       0x804824c
    //  0x0000000d (FINI)                       0x8048458
    //  0x6ffffef5 (GNU_HASH)                   0x8048148
    let dynamic = dyns.get_entry(3).unwrap();
    assert_eq!(dynamic.tag, 0x6ffffef5);
    assert_eq!(dynamic.value, 0x8048148);

    Ok(())
}

Implementations§

Source§

impl<'a> DynamicSectionAccessor<'a>

Source

pub fn new( elfio: &'a Elfio, section: &'a dyn ElfSectionTrait, ) -> DynamicSectionAccessor<'a>

Creates a new instance of the relocation table accessor

Source

pub fn get_entries_num(&self) -> ElfXword

Returns number of symbols

Source

pub fn get_entry(&self, index: ElfXword) -> Option<Dynamic>

Get a relocation entry by its index

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.