Struct object::read::macho::MachOFile

source ·
pub struct MachOFile<'data, Mach, R = &'data [u8]>
where Mach: MachHeader, R: ReadRef<'data>,
{ pub(super) endian: Mach::Endian, pub(super) data: R, pub(super) header_offset: u64, pub(super) header: &'data Mach, pub(super) segments: Vec<MachOSegmentInternal<'data, Mach, R>>, pub(super) sections: Vec<MachOSectionInternal<'data, Mach, R>>, pub(super) symbols: SymbolTable<'data, Mach, R>, }
Expand description

A partially parsed Mach-O file.

Most of the functionality of this type is provided by the Object trait implementation.

Fields§

§endian: Mach::Endian§data: R§header_offset: u64§header: &'data Mach§segments: Vec<MachOSegmentInternal<'data, Mach, R>>§sections: Vec<MachOSectionInternal<'data, Mach, R>>§symbols: SymbolTable<'data, Mach, R>

Implementations§

source§

impl<'data, Mach, R> MachOFile<'data, Mach, R>
where Mach: MachHeader, R: ReadRef<'data>,

source

pub fn parse(data: R) -> Result<Self>

Parse the raw Mach-O file data.

source

pub fn parse_dyld_cache_image<'cache, E: Endian>( image: &DyldCacheImage<'data, 'cache, E, R>, ) -> Result<Self>

Parse the Mach-O file for the given image from the dyld shared cache. This will read different sections from different subcaches, if necessary.

source

pub(super) fn section_internal( &self, index: SectionIndex, ) -> Result<&MachOSectionInternal<'data, Mach, R>>

Return the section at the given index.

source

pub fn endian(&self) -> Mach::Endian

Returns the endianness.

source

pub fn data(&self) -> R

Returns the raw data.

source

pub fn raw_header(&self) -> &'data Mach

👎Deprecated: Use macho_header instead

Returns the raw Mach-O file header.

source

pub fn macho_header(&self) -> &'data Mach

Get the raw Mach-O file header.

source

pub fn macho_load_commands( &self, ) -> Result<LoadCommandIterator<'data, Mach::Endian>>

Get the Mach-O load commands.

source

pub fn macho_symbol_table(&self) -> &SymbolTable<'data, Mach, R>

Get the Mach-O symbol table.

Returns an empty symbol table if the file has no symbol table.

source

pub fn build_version( &self, ) -> Result<Option<&'data BuildVersionCommand<Mach::Endian>>>

Return the LC_BUILD_VERSION load command if present.

Trait Implementations§

source§

impl<'data, Mach, R> Debug for MachOFile<'data, Mach, R>
where Mach: MachHeader + Debug, R: ReadRef<'data> + Debug, Mach::Endian: Debug,

source§

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

Formats the value using the given formatter. Read more
source§

impl<'data, Mach, R> Object<'data> for MachOFile<'data, Mach, R>
where Mach: MachHeader, R: ReadRef<'data>,

source§

type Segment<'file> = MachOSegment<'data, 'file, Mach, R> where Self: 'file, 'data: 'file

A loadable segment in the object file.
source§

type SegmentIterator<'file> = MachOSegmentIterator<'data, 'file, Mach, R> where Self: 'file, 'data: 'file

An iterator for the loadable segments in the object file.
source§

type Section<'file> = MachOSection<'data, 'file, Mach, R> where Self: 'file, 'data: 'file

A section in the object file.
source§

type SectionIterator<'file> = MachOSectionIterator<'data, 'file, Mach, R> where Self: 'file, 'data: 'file

An iterator for the sections in the object file.
source§

type Comdat<'file> = MachOComdat<'data, 'file, Mach, R> where Self: 'file, 'data: 'file

A COMDAT section group in the object file.
source§

type ComdatIterator<'file> = MachOComdatIterator<'data, 'file, Mach, R> where Self: 'file, 'data: 'file

An iterator for the COMDAT section groups in the object file.
source§

type Symbol<'file> = MachOSymbol<'data, 'file, Mach, R> where Self: 'file, 'data: 'file

A symbol in the object file.
source§

type SymbolIterator<'file> = MachOSymbolIterator<'data, 'file, Mach, R> where Self: 'file, 'data: 'file

An iterator for symbols in the object file.
source§

type SymbolTable<'file> = MachOSymbolTable<'data, 'file, Mach, R> where Self: 'file, 'data: 'file

A symbol table in the object file.
source§

type DynamicRelocationIterator<'file> = NoDynamicRelocationIterator where Self: 'file, 'data: 'file

An iterator for the dynamic relocations in the file. Read more
source§

fn architecture(&self) -> Architecture

Get the architecture type of the file.
source§

fn sub_architecture(&self) -> Option<SubArchitecture>

Get the sub-architecture type of the file if known. Read more
source§

fn is_little_endian(&self) -> bool

Return true if the file is little endian, false if it is big endian.
source§

fn is_64(&self) -> bool

Return true if the file can contain 64-bit addresses.
source§

fn kind(&self) -> ObjectKind

Return the kind of this object.
source§

fn segments(&self) -> MachOSegmentIterator<'data, '_, Mach, R>

Get an iterator for the loadable segments in the file. Read more
source§

fn section_by_name_bytes<'file>( &'file self, section_name: &[u8], ) -> Option<MachOSection<'data, 'file, Mach, R>>

Like Self::section_by_name, but allows names that are not UTF-8.
source§

fn section_by_index( &self, index: SectionIndex, ) -> Result<MachOSection<'data, '_, Mach, R>>

Get the section at the given index. Read more
source§

fn sections(&self) -> MachOSectionIterator<'data, '_, Mach, R>

Get an iterator for the sections in the file.
source§

fn comdats(&self) -> MachOComdatIterator<'data, '_, Mach, R>

Get an iterator for the COMDAT section groups in the file.
source§

fn symbol_by_index( &self, index: SymbolIndex, ) -> Result<MachOSymbol<'data, '_, Mach, R>>

Get the debugging symbol at the given index. Read more
source§

fn symbols(&self) -> MachOSymbolIterator<'data, '_, Mach, R>

Get an iterator for the debugging symbols in the file. Read more
source§

fn symbol_table(&self) -> Option<MachOSymbolTable<'data, '_, Mach, R>>

Get the debugging symbol table, if any.
source§

fn dynamic_symbols(&self) -> MachOSymbolIterator<'data, '_, Mach, R>

Get an iterator for the dynamic linking symbols in the file. Read more
source§

fn dynamic_symbol_table(&self) -> Option<MachOSymbolTable<'data, '_, Mach, R>>

Get the dynamic linking symbol table, if any. Read more
source§

fn object_map(&self) -> ObjectMap<'data>

Construct a map from addresses to symbol names and object file names. Read more
source§

fn imports(&self) -> Result<Vec<Import<'data>>>

Get the imported symbols.
source§

fn exports(&self) -> Result<Vec<Export<'data>>>

Get the exported symbols that expose both a name and an address. Read more
source§

fn dynamic_relocations(&self) -> Option<NoDynamicRelocationIterator>

Get the dynamic relocations for this file. Read more
source§

fn has_debug_symbols(&self) -> bool

Return true if the file contains DWARF debug information sections, false if not.
source§

fn mach_uuid(&self) -> Result<Option<[u8; 16]>>

The UUID from a Mach-O LC_UUID load command.
source§

fn relative_address_base(&self) -> u64

Get the base address used for relative virtual addresses. Read more
source§

fn entry(&self) -> u64

Get the virtual address of the entry point of the binary.
source§

fn flags(&self) -> FileFlags

File flags that are specific to each file format.
source§

fn endianness(&self) -> Endianness

Get the endianness of the file.
source§

fn section_by_name(&self, section_name: &str) -> Option<Self::Section<'_>>

Get the section named section_name, if such a section exists. Read more
source§

fn symbol_by_name<'file>( &'file self, symbol_name: &str, ) -> Option<Self::Symbol<'file>>

Get the symbol named symbol_name, if the symbol exists.
source§

fn symbol_by_name_bytes<'file>( &'file self, symbol_name: &[u8], ) -> Option<Self::Symbol<'file>>

Like Self::symbol_by_name, but allows names that are not UTF-8.
source§

fn symbol_map(&self) -> SymbolMap<SymbolMapName<'data>>

Construct a map from addresses to symbol names. Read more
source§

fn build_id(&self) -> Result<Option<&'data [u8]>>

The build ID from an ELF NT_GNU_BUILD_ID note.
The filename and CRC from a .gnu_debuglink section.
The filename and build ID from a .gnu_debugaltlink section.
source§

fn pdb_info(&self) -> Result<Option<CodeView<'_>>>

The filename and GUID from the PE CodeView section.
source§

impl<'data, Mach, R> Sealed for MachOFile<'data, Mach, R>
where Mach: MachHeader, R: ReadRef<'data>,

Auto Trait Implementations§

§

impl<'data, Mach, R> Freeze for MachOFile<'data, Mach, R>
where <Mach as MachHeader>::Endian: Freeze, R: Freeze,

§

impl<'data, Mach, R> RefUnwindSafe for MachOFile<'data, Mach, R>

§

impl<'data, Mach, R> Send for MachOFile<'data, Mach, R>
where <Mach as MachHeader>::Endian: Send, R: Send, Mach: Sync, <Mach as MachHeader>::Nlist: Sync, <Mach as MachHeader>::Segment: Sync, <Mach as MachHeader>::Section: Sync,

§

impl<'data, Mach, R> Sync for MachOFile<'data, Mach, R>
where <Mach as MachHeader>::Endian: Sync, R: Sync, Mach: Sync, <Mach as MachHeader>::Nlist: Sync, <Mach as MachHeader>::Segment: Sync, <Mach as MachHeader>::Section: Sync,

§

impl<'data, Mach, R> Unpin for MachOFile<'data, Mach, R>
where <Mach as MachHeader>::Endian: Unpin, R: Unpin,

§

impl<'data, Mach, R> UnwindSafe for MachOFile<'data, Mach, R>

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

source§

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

source§

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.