pub struct Binary { /* private fields */ }
Expand description
This is the main interface to read and write ELF binary attributes.
Note that this structure implements the generic::Binary
trait from which other generic
functions are exposed
Implementations§
§impl Binary
impl Binary
pub fn parse_with_config(path: &str, config: &ParserConfig) -> Option<Self>
pub fn parse_with_config(path: &str, config: &ParserConfig) -> Option<Self>
Parse from a string file path and with a provided configuration
pub fn virtual_size(&self) -> u64
pub fn virtual_size(&self) -> u64
Return the size taken by the binary when loaded (virtual size)
pub fn interpreter(&self) -> String
pub fn interpreter(&self) -> String
Return the path to the ELF interpreter that is used to process the ELF information once loaded by the kernel
pub fn sections(&self) -> Sections<'_> ⓘ
pub fn sections(&self) -> Sections<'_> ⓘ
Return an iterator over the crate::elf::Section
of the binary
pub fn segments(&self) -> Segments<'_> ⓘ
pub fn segments(&self) -> Segments<'_> ⓘ
Return an iterator over the crate::elf::Segment
of the binary
pub fn dynamic_entries(&self) -> DynamicEntries<'_> ⓘ
pub fn dynamic_entries(&self) -> DynamicEntries<'_> ⓘ
Return an iterator over the crate::elf::DynamicEntries
of the binary
pub fn remove_dynamic_entries_by_tag(&mut self, tag: Tag)
pub fn remove_dynamic_entries_by_tag(&mut self, tag: Tag)
Remove all dynamic entries with the given tag
pub fn add_dynamic_entry(&mut self, entry: &dyn DynamicEntry) -> Entries<'_>
pub fn add_dynamic_entry(&mut self, entry: &dyn DynamicEntry) -> Entries<'_>
Add the given dynamic entry and return the new entry
pub fn dynamic_symbols(&self) -> DynamicSymbols<'_> ⓘ
pub fn dynamic_symbols(&self) -> DynamicSymbols<'_> ⓘ
Return an iterator over the dynamic crate::elf::Symbol
of the binary
pub fn exported_symbols(&self) -> ExportedSymbols<'_> ⓘ
pub fn exported_symbols(&self) -> ExportedSymbols<'_> ⓘ
Return an iterator over the exported crate::elf::Symbol
of the binary
pub fn imported_symbols(&self) -> ImportedSymbols<'_> ⓘ
pub fn imported_symbols(&self) -> ImportedSymbols<'_> ⓘ
Return an iterator over the imported crate::elf::Symbol
of the binary
pub fn symtab_symbols(&self) -> SymtabSymbols<'_> ⓘ
pub fn symtab_symbols(&self) -> SymtabSymbols<'_> ⓘ
Return an iterator over the symtab-debug crate::elf::Symbol
of the binary
pub fn symbols_version(&self) -> SymbolsVersion<'_> ⓘ
pub fn symbols_version(&self) -> SymbolsVersion<'_> ⓘ
Return an iterator over the crate::elf::SymbolVersion
of the binary
pub fn symbols_version_requirement(&self) -> SymbolsVersionRequirement<'_> ⓘ
pub fn symbols_version_requirement(&self) -> SymbolsVersionRequirement<'_> ⓘ
Return an iterator over the crate::elf::SymbolVersionRequirement
of the binary
pub fn symbols_version_definition(&self) -> SymbolsVersionDefinition<'_> ⓘ
pub fn symbols_version_definition(&self) -> SymbolsVersionDefinition<'_> ⓘ
Return an iterator over the crate::elf::SymbolVersionDefinition
of the binary
pub fn notes(&self) -> ItNotes<'_> ⓘ
pub fn notes(&self) -> ItNotes<'_> ⓘ
Return an iterator over the crate::elf::Notes
of the binary
pub fn pltgot_relocations(&self) -> PltGotRelocations<'_> ⓘ
pub fn pltgot_relocations(&self) -> PltGotRelocations<'_> ⓘ
Return an iterator over the .plt.got
crate::elf::Relocation
of the binary
pub fn dynamic_relocations(&self) -> DynamicRelocations<'_> ⓘ
pub fn dynamic_relocations(&self) -> DynamicRelocations<'_> ⓘ
Return an iterator over the regular crate::elf::Relocation
of the binary
pub fn object_relocations(&self) -> ObjectRelocations<'_> ⓘ
pub fn object_relocations(&self) -> ObjectRelocations<'_> ⓘ
Return an iterator over the object-file (.o
) crate::elf::Relocation
pub fn relocations(&self) -> Relocations<'_> ⓘ
pub fn relocations(&self) -> Relocations<'_> ⓘ
Return an iterator over all crate::elf::Relocation
of the binary
pub fn section_by_name(&self, name: &str) -> Option<Section<'_>>
pub fn section_by_name(&self, name: &str) -> Option<Section<'_>>
Try to find the ELF section with the given name
pub fn relocation_by_addr(&self, address: u64) -> Option<Relocation<'_>>
pub fn relocation_by_addr(&self, address: u64) -> Option<Relocation<'_>>
Try to find the ELF relocation that takes place at the given address
pub fn relocation_for_symbol(&self, sym_name: &str) -> Option<Relocation<'_>>
pub fn relocation_for_symbol(&self, sym_name: &str) -> Option<Relocation<'_>>
Try to find the .plt.got
relocation for the given symbol name
pub fn dynamic_symbol_by_name(&self, sym_name: &str) -> Option<Symbol<'_>>
pub fn dynamic_symbol_by_name(&self, sym_name: &str) -> Option<Symbol<'_>>
Try to find the symbol with the given name in the dynamic .dynsym
table
pub fn symtab_symbol_by_name(&self, sym_name: &str) -> Option<Symbol<'_>>
pub fn symtab_symbol_by_name(&self, sym_name: &str) -> Option<Symbol<'_>>
Try to find the symbol with the given name in the debug .symtab
table
pub fn get_library(&self, name: &str) -> Option<Library<'_>>
pub fn get_library(&self, name: &str) -> Option<Library<'_>>
Try to find the library (DT_NEEDED
) with the given name
pub fn section_from_offset(
&self,
offset: u64,
skip_nobits: bool
) -> Option<Section<'_>>
pub fn section_from_offset( &self, offset: u64, skip_nobits: bool ) -> Option<Section<'_>>
Try to find the section that encompasses the given offset. skip_nobits
can be used
to include (or not) the SHT_NOTBIT
sections
pub fn section_from_virtual_address(
&self,
address: u64,
skip_nobits: bool
) -> Option<Section<'_>>
pub fn section_from_virtual_address( &self, address: u64, skip_nobits: bool ) -> Option<Section<'_>>
Try to find the section that encompasses the given virtual address. skip_nobits
can be used
to include (or not) the SHT_NOTBIT
sections
pub fn segment_from_virtual_address(&self, address: u64) -> Option<Segment<'_>>
pub fn segment_from_virtual_address(&self, address: u64) -> Option<Segment<'_>>
Try to find the segment that encompasses the given virtual address
pub fn segment_from_offset(&self, offset: u64) -> Option<Segment<'_>>
pub fn segment_from_offset(&self, offset: u64) -> Option<Segment<'_>>
Try to find the segment that encompasses the given offset
pub fn content_from_virtual_address(&self, address: u64, size: u64) -> &[u8] ⓘ
pub fn content_from_virtual_address(&self, address: u64, size: u64) -> &[u8] ⓘ
Get a slice of the content at the given address.
pub fn virtual_address_to_offset(&self, address: u64) -> Result<u64, Error>
pub fn virtual_address_to_offset(&self, address: u64) -> Result<u64, Error>
Convert the given virtual address into an offset
pub fn get_relocated_dynamic_array(&self, tag: Tag) -> Vec<u64>
pub fn get_relocated_dynamic_array(&self, tag: Tag) -> Vec<u64>
Return the array defined by the given tag (e.g.
dynamic::Tag::INIT_ARRAY
) with relocations applied (if any)
pub fn is_targeting_android(&self) -> bool
pub fn is_targeting_android(&self) -> bool
True if the current binary is targeting Android
pub fn get_int_from_virtual_address<T>(&self, addr: u64) -> Result<T, Error>where
T: Num + FromPrimitive + ToPrimitive,
pub fn get_int_from_virtual_address<T>(&self, addr: u64) -> Result<T, Error>where T: Num + FromPrimitive + ToPrimitive,
Get the integer value at the given virtual address
pub fn write(&mut self, output: &Path)
pub fn write(&mut self, output: &Path)
Write back the current ELF binary into the file specified in parameter
pub fn write_with_config(&mut self, output: &Path, config: Config)
pub fn write_with_config(&mut self, output: &Path, config: Config)
Write back the current ELF binary into the file specified in parameter with the configuration provided in the second parameter.
pub fn add_library<'a>(&'a mut self, library: &str) -> Library<'a>
pub fn add_library<'a>(&'a mut self, library: &str) -> Library<'a>
Add a library as dependency
pub fn dynamic_entry_by_tag(&self, tag: Tag) -> Option<Entries<'_>>
pub fn dynamic_entry_by_tag(&self, tag: Tag) -> Option<Entries<'_>>
Try to find the dynamic entry associated with the given tag
pub fn segment_by_type(&self, seg_type: Type) -> Option<Segment<'_>>
pub fn segment_by_type(&self, seg_type: Type) -> Option<Segment<'_>>
Look for the segment with the given type. If there are multiple segment with the same type, it returns the first one.
pub fn remove_dynamic_entry(&mut self, entry: impl DynamicEntry)
pub fn remove_dynamic_entry(&mut self, entry: impl DynamicEntry)
Remove the given dynamic entry
pub fn remove_dynamic_entry_if<P>(&mut self, predicate: P) -> usizewhere
P: Fn(&Entries<'_>) -> bool,
pub fn remove_dynamic_entry_if<P>(&mut self, predicate: P) -> usizewhere P: Fn(&Entries<'_>) -> bool,
Remove the dynamic entries matching the given predicate.
The function returns the number of entries that have been deleted.
pub fn remove_library(&mut self, name: &str)
pub fn remove_library(&mut self, name: &str)
Remove the DT_NEEDED
dependency with the given name
pub fn add_segment(&mut self, segment: &Segment<'_>) -> Option<Segment<'_>>
pub fn add_segment(&mut self, segment: &Segment<'_>) -> Option<Segment<'_>>
Add the provided segment to the binary. This function returns the newly added segment which could define additional attributes like the virtual address.
pub fn set_interpreter(&mut self, interpreter: &str)
pub fn set_interpreter(&mut self, interpreter: &str)
Change the path to the interpreter
pub fn find_version_requirement(
&self,
libname: &str
) -> Option<SymbolVersionRequirement<'_>>
pub fn find_version_requirement( &self, libname: &str ) -> Option<SymbolVersionRequirement<'_>>
Try to find the SymbolVersionRequirement associated with the given library
name (e.g. libc.so.6
)
pub fn remove_version_requirement(&mut self, libname: &str) -> bool
pub fn remove_version_requirement(&mut self, libname: &str) -> bool
Deletes all required symbol versions linked to the specified library name. The function returns true if the operation succeed, false otherwise.
pub fn remove_segment(&mut self, segment: Segment<'_>, clear: bool)
pub fn remove_segment(&mut self, segment: Segment<'_>, clear: bool)
Remove the given segment. If clear
is set, the original content of the
segment will be filled with zeros before removal.
pub fn remove_segments_by_type(&mut self, ty: Type, clear: bool)
pub fn remove_segments_by_type(&mut self, ty: Type, clear: bool)
Remove all segments associated with the given type.
If clear
is set, the original content of the segments will be filled
with zeros before removal.
Trait Implementations§
§impl Binary for Binary
impl Binary for Binary
§fn entrypoint(&self) -> u64
fn entrypoint(&self) -> u64
§fn original_size(&self) -> u64
fn original_size(&self) -> u64
§fn debug_info(&self) -> Option<DebugInfo<'_>>
fn debug_info(&self) -> Option<DebugInfo<'_>>
crate::pdb::DebugInfo
or crate::dwarf::DebugInfo
. Read more§fn disassemble(&self, address: u64, size: u64) -> InstructionsIt<'_> ⓘ
fn disassemble(&self, address: u64, size: u64) -> InstructionsIt<'_> ⓘ
§fn disassemble_symbol(&self, name: &str) -> InstructionsIt<'_> ⓘ
fn disassemble_symbol(&self, name: &str) -> InstructionsIt<'_> ⓘ
§fn disassemble_address(&self, address: u64) -> InstructionsIt<'_> ⓘ
fn disassemble_address(&self, address: u64) -> InstructionsIt<'_> ⓘ
§fn disassemble_slice(&self, slice: &[u8], address: u64) -> InstructionsIt<'_> ⓘ
fn disassemble_slice(&self, slice: &[u8], address: u64) -> InstructionsIt<'_> ⓘ
address
parameter. Read more§fn assemble(&mut self, address: u64, asm: &str) -> Vec<u8>
fn assemble(&mut self, address: u64, asm: &str) -> Vec<u8>
§fn assemble_with_config(
&mut self,
address: u64,
asm: &str,
config: &AssemblerConfig
) -> Vec<u8>
fn assemble_with_config( &mut self, address: u64, asm: &str, config: &AssemblerConfig ) -> Vec<u8>
Binary::assemble
but this function takes an extra AssemblerConfig
that
is used to configure the assembly engine: dialect, symbols definitions.