amebazii::types::header

Struct SectionHeader

Source
pub struct SectionHeader {
    pub length: u32,
    pub next_offset: Option<u32>,
    pub sect_type: SectionType,
    pub sce_enabled: bool,
    pub xip_page_size: XipPageRemapSize,
    pub xip_block_size: u8,
    /* private fields */
}
Expand description

Represents the header of a section in a binary image.

The SectionHeader struct contains information about the section’s length, type, offset to the next section, as well as details about encryption, remapping, and validation. The struct is designed to handle sections in a memory or file layout where the sections could represent different types of data, such as executable code (XIP), memory regions (DTCM, ITCM), and more. Fields like xip_page_size, xip_key, and xip_iv are especially relevant when dealing with Execute-In-Place (XIP) sections.

Fields§

§length: u32

The length of the section in bytes.

This field stores the total size of the section, which may include data and metadata. The exact meaning and content depend on the section type (sect_type).

§next_offset: Option<u32>

Offset to the next section.

This field indicates the position of the next section in memory. A value of 0xFFFF_FFFF indicates that this is the last section, and no further sections exist.

§sect_type: SectionType

The type of the current section.

§sce_enabled: bool

Indicates whether Secure Copy Engine (SCE) is enabled for this section.

§xip_page_size: XipPageRemapSize

XIP (Execute-In-Place) page size and remapping setting.

This field indicates the page size used for remapping during XIP operations. The value is an integer representing one of three possible values: 0 (16K), 1 (32K), and 2 (64K).

§xip_block_size: u8

Block size for XIP remapping.

This field defines the block size used for XIP remapping, typically represented in bytes. The default value is 0, which means that remapping block size is not defined.

Implementations§

Source§

impl SectionHeader

Source

pub fn has_next(&self) -> bool

Checks if the section has a next section.

This method checks if the next_offset field of the SectionHeader is set to the special value 0xFFFF_FFFF, which indicates that there is no next section. If next_offset is different from this value, it implies that there is a subsequent section, and the method returns true. Otherwise, it returns false, indicating this is the last section.

§Returns
  • true if the section has a next section (i.e., next_offset is not 0xFFFF_FFFF).
  • false if this is the last section (i.e., next_offset is 0xFFFF_FFFF).
Source

pub fn xip_key_iv_valid(&self) -> bool

Checks if both the xip_key and xip_iv fields are valid.

This method uses the is_valid_data! macro to check the validity of both the xip_key and xip_iv fields. It returns true if both fields are valid (i.e., they do not consist entirely of 0xFF bytes). If either field is invalid, it returns false.

This method is typically used to determine if the section is encrypted and can be used for cryptographic operations.

§Returns
  • true if both xip_key and xip_iv are valid.
  • false if either xip_key or xip_iv is invalid.
Source

pub fn get_xip_key(&self) -> DataRefType<'_, 16>

Retrieves the XIP key.

Source

pub fn get_xip_iv(&self) -> DataRefType<'_, 16>

Retrieves the XIP IV.

Source

pub fn get_valid_pattern(&self) -> &[u8; 8]

Retrieves the valid pattern.

Source

pub fn set_xip_iv(&mut self, iv: DataType<16>)

Source

pub fn set_xip_key(&mut self, key: DataType<16>)

Trait Implementations§

Source§

impl BinarySize for SectionHeader

Source§

fn binary_size() -> usize

Returns the binary size (in bytes) of the SectionHeader struct.

§Returns

Returns the binary size as a constant usize value, which is 0x60 (96 bytes).

Source§

impl Debug for SectionHeader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SectionHeader

Source§

fn default() -> SectionHeader

Returns the default SectionHeader instance with predefined values.

  • length set to 0, representing an empty section.
  • next_offset set to 0xFFFF_FFFF, which indicates the absence of a next section.
  • sect_type set to SectionType::XIP, as a default section type.
  • sce_enabled set to false (assuming encryption is not enabled by default).
  • xip_page_size set to XipPageRemapSize::_16K, the smallest page size for XIP remapping.
  • xip_block_size set to 0, indicating no block size set.
  • valid_pattern set to a default validation pattern of increasing values.
  • xip_key and xip_iv both set to 0xFF, representing uninitialized keys/IV.
§Returns

Returns a SectionHeader with the default values.

Source§

impl FromStream for SectionHeader

Source§

fn read_from<R>(&mut self, reader: &mut R) -> Result<(), Error>
where R: Read + Seek,

Reads the SectionHeader struct from a stream.

§Error Handling

This method may return an error if there is an issue with reading from the stream or if an invalid value is encountered during deserialization (e.g., an invalid enum value for sect_type or xip_page_size). Any errors encountered during reading from the stream will be propagated as an Error.

§Returns
  • Ok(()) if the SectionHeader was successfully read from the stream.
  • Err(Error) if there was an issue reading from the stream or an invalid value was encountered.
§Panics

This function assumes that the binary data is well-formed and follows the expected format. If the format is incorrect or the stream is malformed, this function will return an error instead of panicking. However, it is still important to handle errors appropriately in calling code.

Source§

impl ToStream for SectionHeader

Source§

fn write_to<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write + Seek,

Serializes the SectionHeader struct to a stream.

§Parameters
  • writer: A mutable reference to a type that implements the std::io::Write trait. The data will be written to this stream.
§Returns
  • Ok(()): If the data is written successfully.
  • Err(Error): If there is an issue writing the data to the stream.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.