amebazii::types::section

Struct Section

Source
pub struct Section {
    pub header: SectionHeader,
    pub entry_header: EntryHeader,
    /* private fields */
}
Expand description

Represents a section in a sub-image.

This struct encapsulates a section within the image, consisting of the following components:

  • header: The metadata and configuration for the section (represented by SectionHeader).
  • entry_header: The header that defines the entry point and loading address of the section (represented by EntryHeader).
  • data: A Vec<u8> containing the raw data for the section, which can be processed or manipulated as needed.

§Default Values:

  • The header and entry_header are initialized with their default values.
  • The data is an empty vector by default.

Fields§

§header: SectionHeader

The metadata and configuration for the section.

§entry_header: EntryHeader

The header that defines the entry point and loading address of the section.

Implementations§

Source§

impl Section

Source

pub fn new_with_size(capacity: usize) -> Section

Creates a new Section with a specified data capacity.

This static method allows you to create a new Section with a predefined data capacity. The data field will be initialized as a vector of zeroed bytes with the given size.

§Parameters:
  • capacity: The size (in bytes) to which the data vector should be initialized.
§Returns:

A new Section instance with the specified capacity for its data field.

§Example:
let section = Section::new_with_size(1024);
Source

pub fn get_data(&self) -> &[u8]

Returns a reference to the section’s data.

§Returns:

A slice of the section’s data (&[u8]).

Source

pub fn build_aligned_length(&self) -> u32

Computes the aligned length of the section data, ensuring it is padded to a 0x20-byte boundary.

This function calculates the total length of the section (including the EntryHeader and the section’s data) and ensures that the result is aligned to a 0x20-byte boundary.

§Returns:
  • u32: The aligned length of the section, including the EntryHeader and section data.
Source

pub fn build_aligned_size(&self) -> u32

Computes the aligned size of the section, including the SectionHeader, EntryHeader, and section data.

§Returns:
  • u32: The aligned size of the section, including headers and data.
Source

pub fn set_data(&mut self, data: Vec<u8>)

Replaces the current content of the data field with a new byte vector.

§Arguments
  • data - The new byte data (Vec<u8>) to be assigned to the section.

Trait Implementations§

Source§

impl Debug for Section

Source§

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

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

impl Default for Section

Source§

fn default() -> Section

Returns a default Section with default headers and an empty data vector.

Source§

impl FromStream for Section

Source§

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

Reads a Section from a stream.

§Parameters:
  • reader: The stream (Read + Seek) from which the Section will be read.
§Returns:

A result containing Ok(()) if the section was successfully read, or an Error if something went wrong during the process.

Source§

impl ToStream for Section

Source§

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

Writes a Section to a stream.

§Parameters:
  • writer: The stream (Write + Seek) to which the Section will be written.
§Returns:

A result containing Ok(()) if the section was successfully written, or an Error if something went wrong during the process.

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.