Struct lief::macho::binary::Binary

pub struct Binary { /* private fields */ }
Expand description

This is the main interface to read and write Mach-O binary attributes.

Note that this structure implements the generic::Binary trait from which other generic functions are exposed

Implementations§

§

impl Binary

pub fn header(&self) -> Header<'_>

Return the main Mach-O header

pub fn commands(&self) -> CommandsIter<'_>

Return an iterator over the different crate::macho::Commands used by the Mach-O binary

pub fn sections(&self) -> Sections<'_>

Return an iterator over the different crate::macho::Section of the binary

pub fn segments(&self) -> Segments<'_>

Return an iterator over the different crate::macho::commands::Segment (LC_SEGMENT/LC_SIGNATURE) of the binary.

pub fn libraries(&self) -> Libraries<'_>

Return an iterator over the crate::macho::commands::Dylib used by this binary

pub fn relocations(&self) -> Relocations<'_>

Return an iterator over the different crate::macho::Relocation of this binary

pub fn symbols(&self) -> Symbols<'_>

Return an iterator over the different crate::macho::Symbol of this binary

pub fn dyld_info(&self) -> Option<DyldInfo<'_>>

Return the LC_DYLD_INFO/LC_DYLD_INFO_ONLY command if present

pub fn uuid(&self) -> Option<UUID<'_>>

Return the LC_UUID command if present

pub fn main_command(&self) -> Option<Main<'_>>

Return the LC_MAIN command if present

pub fn dylinker(&self) -> Option<Dylinker<'_>>

Return the LC_LOAD_DYLINKER/LC_ID_DYLINKER command if present

pub fn function_starts(&self) -> Option<FunctionStarts<'_>>

Return the LC_FUNCTION_STARTS command if present

pub fn source_version(&self) -> Option<SourceVersion<'_>>

Return the LC_SOURCE_VERSION command if present

pub fn thread_command(&self) -> Option<ThreadCommand<'_>>

Return the LC_THREAD/LC_UNIXTHREAD command if present

pub fn rpath(&self) -> Option<RPath<'_>>

Return the LC_RPATH command if present

pub fn routine(&self) -> Option<Routine<'_>>

Return the LC_ROUTINE/LC_ROUTINE64 command if present

pub fn symbol_command(&self) -> Option<SymbolCommand<'_>>

Return the LC_SYMTAB command if present

pub fn dynamic_symbol(&self) -> Option<DynamicSymbolCommand<'_>>

Return the LC_DYSYMTAB command if present

pub fn code_signature(&self) -> Option<CodeSignature<'_>>

Return the LC_CODE_SIGNATURE command if present

pub fn code_signature_dir(&self) -> Option<CodeSignatureDir<'_>>

Return the LC_DYLIB_CODE_SIGN_DRS command if present

pub fn data_in_code(&self) -> Option<DataInCode<'_>>

Return the LC_DATA_IN_CODE command if present

pub fn segment_split_info(&self) -> Option<SegmentSplitInfo<'_>>

Return the LC_SEGMENT_SPLIT_INFO command if present

pub fn encryption_info(&self) -> Option<EncryptionInfo<'_>>

Return the LC_ENCRYPTION_INFO/LC_ENCRYPTION_INFO_64 command if present

pub fn sub_framework(&self) -> Option<SubFramework<'_>>

Return the LC_SUB_FRAMEWORK command if present

pub fn subclients(&self) -> SubClients<'_>

Return the LC_SUBCLIENT command if present

pub fn dyld_environment(&self) -> Option<DyldEnvironment<'_>>

Return the LC_DYLD_ENVIRONMENT command if present

pub fn build_version(&self) -> Option<BuildVersion<'_>>

Return the LC_BUILD_VERSION command if present

pub fn dyld_chained_fixups(&self) -> Option<DyldChainedFixups<'_>>

Return the LC_DYLD_CHAINED_FIXUPS command if present

pub fn dyld_exports_trie(&self) -> Option<DyldExportsTrie<'_>>

Return the LC_DYLD_EXPORTS_TRIE command if present

pub fn two_level_hints(&self) -> Option<TwoLevelHints<'_>>

Return the LC_TWOLEVEL_HINTS command if present

pub fn linker_opt_hint(&self) -> Option<LinkerOptHint<'_>>

Return the LC_LINKER_OPTIMIZATION_HINT command if present

pub fn version_min(&self) -> Option<VersionMin<'_>>

Return the LC_VERSION_MIN_MACOSX/VERSION_MIN_IPHONEOS command if present

pub fn support_arm64_ptr_auth(&self) -> bool

Check if the binary is supporting ARM64 pointer authentication (arm64e)

pub fn bindings(&self) -> BindingsInfo<'_>

Return an iterator over the bindings located in DyldInfo or DyldChainedFixups

pub fn symbol_stubs(&self) -> Stubs<'_>

Return an iterator over the symbol stubs.

These stubs are involved when calling an imported function and are similar to the ELF’s plt/got mechanism.

There are located in sections like: __stubs,__auth_stubs,__symbol_stub,__picsymbolstub4

pub fn objc_metadata(&self) -> Option<Metadata<'_>>

Return Objective-C metadata if present

pub fn platform(&self) -> Platform

Return the platform for which this Mach-O has been compiled for

pub fn is_ios(&self) -> bool

True if this binary targets iOS

pub fn is_macos(&self) -> bool

True if this binary targets macOS

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)

Write back the current MachO binary into the file specified in parameter

pub fn write_with_config(&mut self, output: &Path, config: Config)

Write back the current MachO binary into the file specified in parameter with the configuration provided in the second parameter.

pub fn add_library<'a>(&'a mut self, libname: &str) -> Dylib<'a>

Insert a new shared library through a LC_LOAD_DYLIB command

Trait Implementations§

§

impl Binary for Binary

§

fn entrypoint(&self) -> u64

Binary’s entrypoint
§

fn imagebase(&self) -> u64

Default base address where the binary should be mapped
§

fn is_pie(&self) -> bool

Whether the current binary is an executable and position independent
§

fn has_nx(&self) -> bool

Whether the binary defines a non-executable stack
§

fn original_size(&self) -> u64

Original file size of the binary
§

fn debug_info(&self) -> Option<DebugInfo<'_>>

Return the debug info if present. It can be either a crate::pdb::DebugInfo or crate::dwarf::DebugInfo. Read more
§

fn disassemble(&self, address: u64, size: u64) -> InstructionsIt<'_>

Disassemble code starting a the given virtual address and with the given size. Read more
§

fn disassemble_symbol(&self, name: &str) -> InstructionsIt<'_>

Disassemble code for the given symbol name Read more
§

fn disassemble_address(&self, address: u64) -> InstructionsIt<'_>

Disassemble code at the given virtual address Read more
§

fn disassemble_slice(&self, slice: &[u8], address: u64) -> InstructionsIt<'_>

Disassemble code provided by the given slice at the specified address parameter. Read more
§

fn assemble(&mut self, address: u64, asm: &str) -> Vec<u8>

Assemble and patch the provided assembly code at the specified address. Read more
§

impl Debug for Binary

§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Binary

§

impl !Send for Binary

§

impl !Sync for Binary

§

impl Unpin for Binary

§

impl UnwindSafe for Binary

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.