Skip to main content

MachoFile

Struct MachoFile 

Source
pub struct MachoFile {
    pub header: MachHeader64,
    pub commands: Vec<LoadCommand>,
    /* private fields */
}
Expand description

A parsed thin 64-bit Mach-O file in a form that round-trips byte-identically.

The structured fields (header, commands) are interpreted; every load command’s body carries the raw bytes for that command, and each segment’s file data is captured in segment_data parallel to the LC_SEGMENT_64 entries in commands. Gaps between structured regions land in padding — same (file_offset, bytes) convention Elf64File uses.

Fields§

§header: MachHeader64§commands: Vec<LoadCommand>

Implementations§

Source§

impl MachoFile

Source

pub fn parse(bytes: &[u8]) -> Result<Self>

Parse a thin 64-bit little-endian Mach-O file.

Source

pub fn from_parts( header: MachHeader64, commands: Vec<LoadCommand>, segment_data: Vec<Vec<u8>>, segment_cmd_indices: Vec<usize>, padding: Vec<(u64, Vec<u8>)>, file_size: u64, ) -> Self

Reconstruct from already-parsed pieces. Used by the lower path when assembling a Mach-O from .ud source.

Source

pub fn cpu(&self) -> Option<MachoCpu>

Architecture flavour this file targets. Returns None when the cputype isn’t one v1 supports — parse already rejects unsupported types, so this can only happen via from_parts.

Source

pub fn segments(&self) -> Vec<Segment64>

Walk every LC_SEGMENT_64 and return a structurally-decoded view of each segment + its sections. The raw bytes still live in commands[i].body; this is purely a read-side convenience for callers that don’t want to re-parse the fixed LC_SEGMENT_64 layout themselves.

Source

pub fn segment_data(&self) -> &[Vec<u8>]

Segment file data parallel to the LC_SEGMENT_64 commands in self.commands. Each entry corresponds to the segment whose cmd_index is at the matching slot in Self::segment_command_indices.

Source

pub fn segment_command_indices(&self) -> &[usize]

Indices into commands for each segment_data entry.

Source

pub fn padding(&self) -> &[(u64, Vec<u8>)]

Padding bytes — gaps between structured regions, stored as (file_offset, bytes).

Source

pub fn file_size(&self) -> u64

Total on-disk size in bytes.

Source

pub fn write_to_vec(&self) -> Vec<u8>

Serialize back to bytes. The contract is byte-identity: parse(b)?.write_to_vec() == b for every supported input.

Trait Implementations§

Source§

impl Clone for MachoFile

Source§

fn clone(&self) -> MachoFile

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MachoFile

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.