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>
impl<'data> Builder<'data>
sourcepub fn new(endian: Endianness, is_64: bool) -> Self
pub fn new(endian: Endianness, is_64: bool) -> Self
Create a new ELF builder.
sourcepub fn read32<R: ReadRef<'data>>(data: R) -> Result<Self>
pub fn read32<R: ReadRef<'data>>(data: R) -> Result<Self>
Read a 32-bit ELF file from file data.
sourcepub fn read64<R: ReadRef<'data>>(data: R) -> Result<Self>
pub fn read64<R: ReadRef<'data>>(data: R) -> Result<Self>
Read a 64-bit ELF file from file data.
sourcepub fn write(self, buffer: &mut dyn WritableBuffer) -> Result<()>
pub fn write(self, buffer: &mut dyn WritableBuffer) -> Result<()>
Write the ELF file to the buffer.
sourcepub fn delete_orphans(&mut self)
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
.
sourcepub fn delete_orphan_segments(&mut self)
pub fn delete_orphan_segments(&mut self)
Set the delete flag for segments that only refer to deleted sections.
sourcepub fn delete_orphan_symbols(&mut self)
pub fn delete_orphan_symbols(&mut self)
Set the delete flag for symbols that refer to deleted sections.
sourcepub fn delete_orphan_relocations(&mut self)
pub fn delete_orphan_relocations(&mut self)
Delete relocations that refer to deleted symbols.
sourcepub fn delete_orphan_dynamics(&mut self)
pub fn delete_orphan_dynamics(&mut self)
Delete dynamic entries that refer to deleted sections.
sourcepub fn delete_unused_versions(&mut self)
pub fn delete_unused_versions(&mut self)
Delete unused GNU version entries.
sourcepub fn class(&self) -> Class
pub fn class(&self) -> Class
Return the ELF file class that will be written.
This can be useful for calculating sizes.
sourcepub fn file_header_size(&self) -> usize
pub fn file_header_size(&self) -> usize
Calculate the size of the file header.
sourcepub fn program_headers_size(&self) -> usize
pub fn program_headers_size(&self) -> usize
Calculate the size of the program headers.
sourcepub fn dynamic_symbol_size(&self) -> usize
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
.
sourcepub fn dynamic_string_size(&self) -> usize
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
.
sourcepub fn hash_size(&self) -> usize
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
.
sourcepub fn gnu_hash_size(&self) -> usize
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
.
sourcepub fn gnu_versym_size(&self) -> usize
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
.
sourcepub fn gnu_verdef_size(&self) -> usize
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
.
sourcepub fn gnu_verneed_size(&self) -> usize
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
.
sourcepub fn section_size(&self, section: &Section<'_>) -> usize
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
.
sourcepub fn set_section_sizes(&mut self)
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
.
sourcepub fn dynamic_section(&self) -> Option<SectionId>
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.
sourcepub fn dynamic_data(&self) -> Option<&[Dynamic<'data>]>
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,
sourcepub fn dynamic_data_mut(&mut self) -> Option<&mut Vec<Dynamic<'data>>>
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,
sourcepub fn interp_section(&self) -> Option<SectionId>
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.
sourcepub fn interp_data(&self) -> Option<&[u8]>
pub fn interp_data(&self) -> Option<&[u8]>
Find the interpreter path.
This uses the PT_INTERP
program header to find the interp section.
sourcepub fn interp_data_mut(&mut self) -> Option<&mut Bytes<'data>>
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.