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>
impl<T: SizeT> ELF<T>
Sourcepub 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>
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,
}
);