/// An iterator for the segments in a [`MachOFile32`](super::MachOFile32). pubtype MachOSegmentIterator32<'data, 'file, Endian = Endianness, R = &'data [u8]> =
MachOSegmentIterator<'data, 'file, macho::MachHeader32<Endian>, R>; /// An iterator for the segments in a [`MachOFile64`](super::MachOFile64). pubtype MachOSegmentIterator64<'data, 'file, Endian = Endianness, R = &'data [u8]> =
MachOSegmentIterator<'data, 'file, macho::MachHeader64<Endian>, R>;
/// An iterator for the segments in a [`MachOFile`]. #[derive(Debug)] pubstruct MachOSegmentIterator<'data, 'file, Mach, R = &'data [u8]> where
Mach: MachHeader,
R: ReadRef<'data>,
{ pub(super) file: &'file MachOFile<'data, Mach, R>, pub(super) iter: slice::Iter<'file, MachOSegmentInternal<'data, Mach, R>>,
}
impl<'data, 'file, Mach, R> Iterator for MachOSegmentIterator<'data, 'file, Mach, R> where
Mach: MachHeader,
R: ReadRef<'data>,
{ type Item = MachOSegment<'data, 'file, Mach, R>;
/// A segment in a [`MachOFile32`](super::MachOFile32). pubtype MachOSegment32<'data, 'file, Endian = Endianness, R = &'data [u8]> =
MachOSegment<'data, 'file, macho::MachHeader32<Endian>, R>; /// A segment in a [`MachOFile64`](super::MachOFile64). pubtype MachOSegment64<'data, 'file, Endian = Endianness, R = &'data [u8]> =
MachOSegment<'data, 'file, macho::MachHeader64<Endian>, R>;
/// A segment in a [`MachOFile`]. /// /// Most functionality is provided by the [`ObjectSegment`] trait implementation. #[derive(Debug)] pubstruct MachOSegment<'data, 'file, Mach, R = &'data [u8]> where
Mach: MachHeader,
R: ReadRef<'data>,
{
file: &'file MachOFile<'data, Mach, R>,
internal: &'file MachOSegmentInternal<'data, Mach, R>,
}
impl<'data, 'file, Mach, R> MachOSegment<'data, 'file, Mach, R> where
Mach: MachHeader,
R: ReadRef<'data>,
{ /// Get the Mach-O file containing this segment. pubfn macho_file(&self) -> &'file MachOFile<'data, Mach, R> { self.file
}
/// Get the raw Mach-O segment structure. pubfn macho_segment(&self) -> &'data Mach::Segment { self.internal.segment
}
#[inline] fn flags(&self) -> SegmentFlags { let flags = self.internal.segment.flags(self.file.endian); let maxprot = self.internal.segment.maxprot(self.file.endian); let initprot = self.internal.segment.initprot(self.file.endian);
SegmentFlags::MachO {
flags,
maxprot,
initprot,
}
}
}
#[derive(Debug, Clone, Copy)] pub(super) struct MachOSegmentInternal<'data, Mach: MachHeader, R: ReadRef<'data>> { pub segment: &'data Mach::Segment, /// The data for the file that contains the segment data. /// /// This is required for dyld caches, where this may be a different subcache /// from the file containing the Mach-O load commands. pub data: R,
}
/// A trait for generic access to [`macho::SegmentCommand32`] and [`macho::SegmentCommand64`]. #[allow(missing_docs)] pubtrait Segment: Debug + Pod { type Word: Into<u64>; type Endian: endian::Endian; type Section: Section<Endian = Self::Endian>;
/// Return the `segname` bytes up until the null terminator. fn name(&self) -> &[u8] { let segname = &self.segname()[..]; match memchr::memchr(b'\0', segname) {
Some(end) => &segname[..end],
None => segname,
}
}
/// Return the offset and size of the segment in the file. fn file_range(&self, endian: Self::Endian) -> (u64, u64) {
(self.fileoff(endian).into(), self.filesize(endian).into())
}
/// Get the segment data from the file data. /// /// Returns `Err` for invalid values. fn data<'data, R: ReadRef<'data>>(
&self,
endian: Self::Endian,
data: R,
) -> result::Result<&'data [u8], ()> { let (offset, size) = self.file_range(endian);
data.read_bytes_at(offset, size)
}
/// Get the array of sections from the data following the segment command. /// /// Returns `Err` for invalid values. fn sections<'data, R: ReadRef<'data>>(
&self,
endian: Self::Endian,
section_data: R,
) -> Result<&'data [Self::Section]> {
section_data
.read_slice_at(0, self.nsects(endian) as usize)
.read_error("Invalid Mach-O number of sections")
}
}
impl<Endian: endian::Endian> Segment for macho::SegmentCommand32<Endian> { type Word = u32; type Endian = Endian; type Section = macho::Section32<Self::Endian>;
impl<Endian: endian::Endian> Segment for macho::SegmentCommand64<Endian> { type Word = u64; type Endian = Endian; type Section = macho::Section64<Self::Endian>;
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.