Struct object::build::elf::Builder

source ·
pub struct Builder<'data> {
Show 15 fields pub endian: Endianness, pub is_64: bool, pub load_align: u64, pub header: Header, pub segments: Segments<'data>, pub sections: Sections<'data>, pub symbols: Symbols<'data>, pub dynamic_symbols: DynamicSymbols<'data>, pub version_base: Option<ByteString<'data>>, pub versions: Versions<'data>, pub version_files: VersionFiles<'data>, pub hash_bucket_count: u32, pub gnu_hash_bloom_shift: u32, pub gnu_hash_bloom_count: u32, pub gnu_hash_bucket_count: u32, /* private fields */
}
Expand description

A builder for reading, modifying, and then writing ELF files.

Public fields are available for modifying the values that will be written. Methods are available to add elements to tables, and elements can be deleted from tables by setting the delete field in the element.

Fields§

§endian: Endianness

The endianness.

Used to set the data encoding when writing the ELF file.

§is_64: bool

Whether file is 64-bit.

Use to set the file class when writing the ELF file.

§load_align: u64

The alignment of elf::PT_LOAD segments.

This is an informational field and is not used when writing the ELF file. It can optionally be used when calling Segments::add_load_segment.

It is determined heuristically when reading the ELF file. Currently, if all load segments have the same alignment, that alignment is used, otherwise it is set to 1.

§header: Header

The file header.

§segments: Segments<'data>

The segment table.

§sections: Sections<'data>

The section table.

§symbols: Symbols<'data>

The symbol table.

§dynamic_symbols: DynamicSymbols<'data>

The dynamic symbol table.

§version_base: Option<ByteString<'data>>

The base version for the GNU version definitions.

This will be written as a version definition with index 1.

§versions: Versions<'data>

The GNU version definitions and dependencies.

§version_files: VersionFiles<'data>

The filenames used in the GNU version definitions.

§hash_bucket_count: u32

The bucket count parameter for the hash table.

§gnu_hash_bloom_shift: u32

The bloom shift parameter for the GNU hash table.

§gnu_hash_bloom_count: u32

The bloom count parameter for the GNU hash table.

§gnu_hash_bucket_count: u32

The bucket count parameter for the GNU hash table.

Implementations§

source§

impl<'data> Builder<'data>

source

pub fn new(endian: Endianness, is_64: bool) -> Self

Create a new ELF builder.

source

pub fn read<R: ReadRef<'data>>(data: R) -> Result<Self>

Read the ELF file from file data.

source

pub fn read32<R: ReadRef<'data>>(data: R) -> Result<Self>

Read a 32-bit ELF file from file data.

source

pub fn read64<R: ReadRef<'data>>(data: R) -> Result<Self>

Read a 64-bit ELF file from file data.

source

pub fn write(self, buffer: &mut dyn WritableBuffer) -> Result<()>

Write the ELF file to the buffer.

source

pub fn delete_orphans(&mut self)

Delete segments, symbols, relocations, and dynamics that refer to deleted items.

This calls delete_orphan_segments, delete_orphan_symbols, delete_orphan_relocations, and delete_orphan_dynamics.

source

pub fn delete_orphan_segments(&mut self)

Set the delete flag for segments that only refer to deleted sections.

source

pub fn delete_orphan_symbols(&mut self)

Set the delete flag for symbols that refer to deleted sections.

source

pub fn delete_orphan_relocations(&mut self)

Delete relocations that refer to deleted symbols.

source

pub fn delete_orphan_dynamics(&mut self)

Delete dynamic entries that refer to deleted sections.

source

pub fn delete_unused_versions(&mut self)

Delete unused GNU version entries.

source

pub fn class(&self) -> Class

Return the ELF file class that will be written.

This can be useful for calculating sizes.

source

pub fn file_header_size(&self) -> usize

Calculate the size of the file header.

source

pub fn program_headers_size(&self) -> usize

Calculate the size of the program headers.

source

pub fn dynamic_symbol_size(&self) -> usize

Calculate the size of the dynamic symbol table.

To get an accurate result, you may need to first call Self::delete_orphan_symbols.

source

pub fn dynamic_string_size(&self) -> usize

Calculate the size of the dynamic string table.

This adds all of the currently used dynamic strings to a string table, calculates the size of the string table, and discards the string table.

To get an accurate result, you may need to first call Self::delete_orphan_symbols and Self::delete_unused_versions.

source

pub fn hash_size(&self) -> usize

Calculate the size of the hash table.

To get an accurate result, you may need to first call Self::delete_orphan_symbols.

source

pub fn gnu_hash_size(&self) -> usize

Calculate the size of the GNU hash table.

To get an accurate result, you may need to first call Self::delete_orphan_symbols.

source

pub fn gnu_versym_size(&self) -> usize

Calculate the size of the GNU symbol version section.

To get an accurate result, you may need to first call Self::delete_orphan_symbols and Self::delete_unused_versions.

source

pub fn gnu_verdef_size(&self) -> usize

Calculate the size of the GNU version definition section.

To get an accurate result, you may need to first call Self::delete_orphan_symbols and Self::delete_unused_versions.

source

pub fn gnu_verneed_size(&self) -> usize

Calculate the size of the GNU version dependency section.

To get an accurate result, you may need to first call Self::delete_orphan_symbols and Self::delete_unused_versions.

source

pub fn section_size(&self, section: &Section<'_>) -> usize

Calculate the memory size of a section.

Returns 0 for sections that are deleted or aren’t allocated.

To get an accurate result, you may need to first call Self::delete_orphan_symbols and Self::delete_unused_versions.

source

pub fn set_section_sizes(&mut self)

Set the sh_size field for every allocated section.

This is useful to call prior to doing memory layout.

To get an accurate result, you may need to first call Self::delete_orphan_symbols and Self::delete_unused_versions.

source

pub fn dynamic_section(&self) -> Option<SectionId>

Find the section containing the dynamic table.

This uses the PT_DYNAMIC program header to find the dynamic section.

source

pub fn dynamic_data(&self) -> Option<&[Dynamic<'data>]>

Find the dynamic table entries.

This uses the PT_DYNAMIC program header to find the dynamic section,

source

pub fn dynamic_data_mut(&mut self) -> Option<&mut Vec<Dynamic<'data>>>

Find the dynamic table entries.

This uses the PT_DYNAMIC program header to find the dynamic section,

source

pub fn interp_section(&self) -> Option<SectionId>

Find the section containing the interpreter path.

This uses the PT_INTERP program header to find the interp section.

source

pub fn interp_data(&self) -> Option<&[u8]>

Find the interpreter path.

This uses the PT_INTERP program header to find the interp section.

source

pub fn interp_data_mut(&mut self) -> Option<&mut Bytes<'data>>

Find the interpreter path.

This uses the PT_INTERP program header to find the interp section.

Trait Implementations§

source§

impl<'data> Debug for Builder<'data>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'data> Freeze for Builder<'data>

§

impl<'data> RefUnwindSafe for Builder<'data>

§

impl<'data> Send for Builder<'data>

§

impl<'data> Sync for Builder<'data>

§

impl<'data> Unpin for Builder<'data>

§

impl<'data> UnwindSafe for Builder<'data>

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>,

§

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>,

§

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.