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
impl MachoFile
Sourcepub 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
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.
Sourcepub fn cpu(&self) -> Option<MachoCpu>
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.
Sourcepub fn segments(&self) -> Vec<Segment64>
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.
Sourcepub fn segment_data(&self) -> &[Vec<u8>]
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.
Sourcepub fn segment_command_indices(&self) -> &[usize]
pub fn segment_command_indices(&self) -> &[usize]
Indices into commands for each segment_data entry.
Sourcepub fn padding(&self) -> &[(u64, Vec<u8>)]
pub fn padding(&self) -> &[(u64, Vec<u8>)]
Padding bytes — gaps between structured regions, stored as
(file_offset, bytes).
Sourcepub fn write_to_vec(&self) -> Vec<u8> ⓘ
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.