/// An iterator for the sections in an [`XcoffFile32`](super::XcoffFile32). pubtype XcoffSectionIterator32<'data, 'file, R = &'data [u8]> =
XcoffSectionIterator<'data, 'file, xcoff::FileHeader32, R>; /// An iterator for the sections in an [`XcoffFile64`](super::XcoffFile64). pubtype XcoffSectionIterator64<'data, 'file, R = &'data [u8]> =
XcoffSectionIterator<'data, 'file, xcoff::FileHeader64, R>;
/// An iterator for the sections in an [`XcoffFile`]. #[derive(Debug)] pubstruct XcoffSectionIterator<'data, 'file, Xcoff, R = &'data [u8]> where
Xcoff: FileHeader,
R: ReadRef<'data>,
{ pub(super) file: &'file XcoffFile<'data, Xcoff, R>, pub(super) iter: iter::Enumerate<slice::Iter<'data, Xcoff::SectionHeader>>,
}
impl<'data, 'file, Xcoff, R> Iterator for XcoffSectionIterator<'data, 'file, Xcoff, R> where
Xcoff: FileHeader,
R: ReadRef<'data>,
{ type Item = XcoffSection<'data, 'file, Xcoff, R>;
/// A section in an [`XcoffFile32`](super::XcoffFile32). pubtype XcoffSection32<'data, 'file, R = &'data [u8]> =
XcoffSection<'data, 'file, xcoff::FileHeader32, R>; /// A section in an [`XcoffFile64`](super::XcoffFile64). pubtype XcoffSection64<'data, 'file, R = &'data [u8]> =
XcoffSection<'data, 'file, xcoff::FileHeader64, R>;
/// A section in an [`XcoffFile`]. /// /// Most functionality is provided by the [`ObjectSection`] trait implementation. #[derive(Debug)] pubstruct XcoffSection<'data, 'file, Xcoff, R = &'data [u8]> where
Xcoff: FileHeader,
R: ReadRef<'data>,
{ pub(super) file: &'file XcoffFile<'data, Xcoff, R>, pub(super) section: &'data Xcoff::SectionHeader, pub(super) index: SectionIndex,
}
impl<'data, 'file, Xcoff: FileHeader, R: ReadRef<'data>> XcoffSection<'data, 'file, Xcoff, R> { /// Get the XCOFF file containing this section. pubfn xcoff_file(&self) -> &'file XcoffFile<'data, Xcoff, R> { self.file
}
/// Get the raw XCOFF section header. pubfn xcoff_section(&self) -> &'data Xcoff::SectionHeader { self.section
}
/// Get the raw XCOFF relocation entries for this section. pubfn xcoff_relocations(&self) -> Result<&'data [Xcoff::Rel]> { self.section.relocations(self.file.data)
}
/// The table of section headers in an XCOFF file. /// /// Returned by [`FileHeader::sections`]. #[derive(Debug, Clone, Copy)] pubstruct SectionTable<'data, Xcoff: FileHeader> {
sections: &'data [Xcoff::SectionHeader],
}
impl<'data, Xcoff> SectionTable<'data, Xcoff> where
Xcoff: FileHeader,
{ /// Parse the section table. /// /// `data` must be the entire file data. /// `offset` must be after the optional file header. pubfn parse<R: ReadRef<'data>>(header: &Xcoff, data: R, offset: &mut u64) -> Result<Self> { let section_num = header.f_nscns(); if section_num == 0 { return Ok(SectionTable::default());
} let sections = data
.read_slice(offset, section_num as usize)
.read_error("Invalid XCOFF section headers")?;
Ok(SectionTable { sections })
}
/// Iterate over the section headers. #[inline] pubfn iter(&self) -> slice::Iter<'data, Xcoff::SectionHeader> { self.sections.iter()
}
/// Return true if the section table is empty. #[inline] pubfn is_empty(&self) -> bool { self.sections.is_empty()
}
/// The number of section headers. #[inline] pubfn len(&self) -> usize { self.sections.len()
}
/// Return the section header at the given index. /// /// The index is 1-based. pubfn section(&self, index: SectionIndex) -> read::Result<&yle='color:blue'>'data Xcoff::SectionHeader> { self.sections
.get(index.0.wrapping_sub(1))
.read_error("Invalid XCOFF section index")
}
}
/// A trait for generic access to [`xcoff::SectionHeader32`] and [`xcoff::SectionHeader64`]. #[allow(missing_docs)] pubtrait SectionHeader: Debug + Pod { type Word: Into<u64>; type HalfWord: Into<u32>; type Xcoff: FileHeader<SectionHeader = Self, Word = Self::Word>; type Rel: Rel<Word = Self::Word>;
/// Return the section name. fn name(&self) -> &[u8] { let sectname = &self.s_name()[..]; match memchr::memchr(b'\0', sectname) {
Some(end) => §name[..end],
None => sectname,
}
}
/// Return the offset and size of the section in the file. fn file_range(&self) -> Option<(u64, u64)> {
Some((self.s_scnptr().into(), self.s_size().into()))
}
/// Return the section data. /// /// Returns `Ok(&[])` if the section has no data. /// Returns `Err` for invalid values. fn data<'data, R: ReadRef<'data>>(&self, data: R) -> result::Result<&n style='color:blue'>'data [u8], ()> { iflet Some((offset, size)) = self.file_range() {
data.read_bytes_at(offset, size)
} else {
Ok(&[])
}
}
/// Read the relocations in a XCOFF32 file. /// /// `data` must be the entire file data. fn relocations<'data, R: ReadRef<'data>>(&self, data: R) -> read::Result<&'data [Self::Rel]> { let reloc_num = self.s_nreloc() as usize; // TODO: If more than 65,534 relocation entries are required, the field value will be 65535, // and an STYP_OVRFLO section header will contain the actual count of relocation entries in // the s_paddr field. if reloc_num == 65535 { return Err(Error("Overflow section is not supported yet."));
}
data.read_slice_at(self.s_relptr().into(), reloc_num)
.read_error("Invalid XCOFF relocation offset or number")
}
}
impl SectionHeader for xcoff::SectionHeader64 { type Word = u64; type HalfWord = u32; type Xcoff = xcoff::FileHeader64; type Rel = xcoff::Rel64;
/// Read the relocations in a XCOFF64 file. /// /// `data` must be the entire file data. fn relocations<'data, R: ReadRef<'data>>(&self, data: R) -> read::Result<&'data [Self::Rel]> {
data.read_slice_at(self.s_relptr(), self.s_nreloc() as usize)
.read_error("Invalid XCOFF relocation offset or number")
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-06-18)
¤
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.