Struct ELF

Source
pub struct ELF<T: SizeT> {
    pub ident: Ident,
    pub e_type: Type,
    pub machine: Machine,
    pub entry_point: T,
    pub segments: Vec<Segment<T>>,
    pub sections: Vec<Section<T>>,
    pub flags: u32,
    pub section_header_string_table_index: u16,
}
Expand description

The ELF file itself. This what you will be using. Use Self::read() to read if from a file, Self::new() to construct it from scratch and Self::write() to write it to a file T generic can be u32 for ELF32 and u64 for ELF64

Fields§

§ident: Ident

An ident

§e_type: Type

Identifies object file type

§machine: Machine

Specifies target instruction set architecture

§entry_point: T

This is the memory address of the entry point from where the process starts executing. Should be 0 if no entry point

§segments: Vec<Segment<T>>

Segments/Program headers (Loaded when executed). Do not add them, offsets will probably mess up

§sections: Vec<Section<T>>

Sections (When linking turned into segment). Do not add them, offsets will probably mess up

§flags: u32

Flags, usually 0. Interpretation of this field depends on the target architecture

§section_header_string_table_index: u16

Contains index of the section header table entry that contains the section names

Implementations§

Source§

impl<T: SizeT> ELF<T>

Source

pub fn new( ident: Ident, e_type: Type, machine: impl Into<Machine>, has_entry_point: bool, segments: Vec<SegmentTemplate<T>>, sections: Vec<Section<T>>, ) -> Result<Self>

Constructs a new ELF from scratch. To make an Ident you will need to call Ident::new() This is a simplified constructor:

  • Assumes, that string table is the last section (if exists)
  • Sets flags to 0
  • If has_entry_point is true, entry point will be set to the start of the first segment
  • Places segments continuously into memory, starting from address machine.text_region_address() + (T::ELF_HEADER_SIZE + T::SEGMENT_HEADER_SIZE * segments.len() + T::SECTION_HEADER_SIZE * sections.len()) % 0x1000 For more flexability you can do:
use orecc_elf::*;
dbg!(
    ELF::<u64> {
        ident: Ident::default(),
        e_type: Type::Exec,
        machine: Machine::X86_64,
        entry_point: 0xDEADBEEF,
        segments: Vec::new(),
        sections: Vec::new(),
        flags: 0,
        section_header_string_table_index: 0,
    }
);
Source

pub fn write<W: Write + Seek>(&self, file: &mut W) -> Result<()>

Write an ELF to a file

Source

pub fn read<R: Read + Seek>(file: &mut R) -> Result<Self>

Read an ELF from a file

Source

pub fn read_remainder<R: Read>(file: &mut R, ident: Ident) -> Result<Self>

Read an ELF from a file when you already read Ident

Trait Implementations§

Source§

impl<T: Clone + SizeT> Clone for ELF<T>

Source§

fn clone(&self) -> ELF<T>

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<T: Debug + SizeT> Debug for ELF<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: Hash + SizeT> Hash for ELF<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: Ord + SizeT> Ord for ELF<T>

Source§

fn cmp(&self, other: &ELF<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq + SizeT> PartialEq for ELF<T>

Source§

fn eq(&self, other: &ELF<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd + SizeT> PartialOrd for ELF<T>

Source§

fn partial_cmp(&self, other: &ELF<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: Eq + SizeT> Eq for ELF<T>

Source§

impl<T: SizeT> StructuralPartialEq for ELF<T>

Auto Trait Implementations§

§

impl<T> Freeze for ELF<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for ELF<T>
where T: RefUnwindSafe,

§

impl<T> Send for ELF<T>
where T: Send,

§

impl<T> Sync for ELF<T>
where T: Sync,

§

impl<T> Unpin for ELF<T>
where T: Unpin,

§

impl<T> UnwindSafe for ELF<T>
where T: UnwindSafe,

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.