#[repr(C)] #[derive(Clone, Copy, Default, Pread, Pwrite, SizeWith)] /// The Mach-o `FatHeader` always has its data bigendian pubstruct FatHeader { /// The magic number, `cafebabe` pub magic: u32, /// How many fat architecture headers there are pub nfat_arch: u32,
}
impl FatHeader { /// Reinterpret a `FatHeader` from `bytes` pubfn from_bytes(bytes: [u8; SIZEOF_FAT_HEADER]) -> FatHeader { letmut offset = 0; let magic = bytes.gread_with(&mut offset, scroll::BE).unwrap(); let nfat_arch = bytes.gread_with(&mut offset, scroll::BE).unwrap();
FatHeader { magic, nfat_arch }
}
/// Reads a `FatHeader` from a `File` on disk #[cfg(feature = "std")] pubfn from_fd(fd: &mut File) -> io::Result<FatHeader> { letmut header = [0; SIZEOF_FAT_HEADER];
fd.read_exact(&mut header)?;
Ok(FatHeader::from_bytes(header))
}
/// Parse a mach-o fat header from the `bytes` pubfn parse(bytes: &[u8]) -> error::Result<FatHeader> {
Ok(bytes.pread_with::<FatHeader>(0, scroll::BE)?)
}
}
#[repr(C)] #[derive(Clone, Copy, Default, Pread, Pwrite, SizeWith)] /// The Mach-o `FatArch` always has its data bigendian pubstruct FatArch { /// What kind of CPU this binary is pub cputype: u32, pub cpusubtype: u32, /// Where in the fat binary it starts pub offset: u32, /// How big the binary is pub size: u32, pub align: u32,
}
impl FatArch { /// Get the slice of bytes this header describes from `bytes` pubfn slice<'a>(&self, bytes: &'a [u8]) -> &'a [u8] { // FIXME: This function should ideally validate the inputs and return a `Result`. // Best we can do for now without `panic`ing is return an empty slice. let start = self.offset as usize; match start
.checked_add(self.size as usize)
.and_then(|end| bytes.get(start..end))
{
Some(slice) => slice,
None => {
log::warn!("invalid `FatArch` offset");
&[]
}
}
}
/// Returns the cpu type pubfn cputype(&self) -> CpuType { self.cputype
}
/// Returns the cpu subtype with the capabilities removed pubfn cpusubtype(&self) -> CpuSubType { self.cpusubtype & !CPU_SUBTYPE_MASK
}
/// Returns the capabilities of the CPU pubfn cpu_caps(&self) -> u32 {
(self.cpusubtype & CPU_SUBTYPE_MASK) >> 24
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.