/// A 32-bit XCOFF object file. /// /// This is a file that starts with [`xcoff::FileHeader32`], and corresponds /// to [`crate::FileKind::Xcoff32`]. pubtype XcoffFile32<'data, R = &'data [u8]> = XcoffFile<'data, xcoff::FileHeader32, R>; /// A 64-bit XCOFF object file. /// /// This is a file that starts with [`xcoff::FileHeader64`], and corresponds /// to [`crate::FileKind::Xcoff64`]. pubtype XcoffFile64<'data, R = &'data [u8]> = XcoffFile<'data, xcoff::FileHeader64, R>;
/// A partially parsed XCOFF file. /// /// Most functionality is provided by the [`Object`] trait implementation. #[derive(Debug)] pubstruct XcoffFile<'data, Xcoff, R = &'data [u8]> where
Xcoff: FileHeader,
R: ReadRef<'data>,
{ pub(super) data: R, pub(super) header: &'data Xcoff, pub(super) aux_header: Option<&'data Xcoff::AuxHeader>, pub(super) sections: SectionTable<'data, Xcoff>, pub(super) symbols: SymbolTable<'data, Xcoff, R>,
}
impl<'data, Xcoff, R> XcoffFile<'data, Xcoff, R> where
Xcoff: FileHeader,
R: ReadRef<'data>,
{ /// Parse the raw XCOFF file data. pubfn parse(data: R) -> Result<Self> { letmut offset = 0; let header = Xcoff::parse(data, &mut offset)?; let aux_header = header.aux_header(data, &mut offset)?; let sections = header.sections(data, &mut offset)?; let symbols = header.symbols(data)?;
/// A trait for generic access to [`xcoff::FileHeader32`] and [`xcoff::FileHeader64`]. #[allow(missing_docs)] pubtrait FileHeader: Debug + Pod { type Word: Into<u64>; type AuxHeader: AuxHeader<Word = Self::Word>; type SectionHeader: SectionHeader<Word = Self::Word, Rel = Self::Rel>; type Symbol: Symbol<Word = Self::Word>; type FileAux: FileAux; type CsectAux: CsectAux; type Rel: Rel<Word = Self::Word>;
/// Return true if this type is a 64-bit header. fn is_type_64(&self) -> bool;
/// Read the file header. /// /// Also checks that the magic field in the file header is a supported format. fn parse<'data, R: ReadRef<'data>>(data: R, offset: &mut u64) -> Result<&pan style='color:blue'>'data Self> { let header = data
.read::<Self>(offset)
.read_error("Invalid XCOFF header size or alignment")?; if !header.is_supported() { return Err(Error("Unsupported XCOFF header"));
}
Ok(header)
}
/// Read the auxiliary file header. fn aux_header<'data, R: ReadRef<'data>>(
&self,
data: R,
offset: &mut u64,
) -> Result<Option<&'data Self::AuxHeader>> { let aux_header_size = self.f_opthdr(); ifself.f_flags() & xcoff::F_EXEC == 0 { // No auxiliary header is required for an object file that is not an executable. // TODO: Some AIX programs generate auxiliary headers for 32-bit object files // that end after the data_start field.
*offset += u64::from(aux_header_size); return Ok(None);
} // Executables, however, must have auxiliary headers that include the // full structure definitions. if aux_header_size != mem::size_of::<Self::AuxHeader>() as u16 {
*offset += u64::from(aux_header_size); return Ok(None);
} let aux_header = data
.read::<Self::AuxHeader>(offset)
.read_error("Invalid XCOFF auxiliary header size")?;
Ok(Some(aux_header))
}
impl FileHeader for xcoff::FileHeader32 { type Word = u32; type AuxHeader = xcoff::AuxHeader32; type SectionHeader = xcoff::SectionHeader32; type Symbol = xcoff::Symbol32; type FileAux = xcoff::FileAux32; type CsectAux = xcoff::CsectAux32; type Rel = xcoff::Rel32;
impl FileHeader for xcoff::FileHeader64 { type Word = u64; type AuxHeader = xcoff::AuxHeader64; type SectionHeader = xcoff::SectionHeader64; type Symbol = xcoff::Symbol64; type FileAux = xcoff::FileAux64; type CsectAux = xcoff::CsectAux64; type Rel = xcoff::Rel64;
/// A trait for generic access to [`xcoff::AuxHeader32`] and [`xcoff::AuxHeader64`]. #[allow(missing_docs)] pubtrait AuxHeader: Debug + Pod { type Word: Into<u64>;
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.