Skip to main content

Header

Enum Header 

Source
pub enum Header {
    V0(HeaderV0),
    V3(HeaderV3),
}
Expand description

Standard Android boot image header for versions 0 through 4

Variants§

§

V0(HeaderV0)

Header for versions 0-2

§

V3(HeaderV3)

Header for versions 3-4

Implementations§

Source§

impl Header

Source

pub fn parse<R: Read + Seek>(reader: &mut R) -> Result<Self, Error>

Parses a standard Android boot image header from a reader.

§Errors

This returns an error if reading fails or if the header is invalid.

Examples found in repository?
examples/extract-kernel.rs (line 12)
10fn main() {
11    let mut r = BufReader::new(File::open("boot_a.img").unwrap());
12    let hdr = Header::parse(&mut r).unwrap();
13    println!("{hdr:#?}");
14
15    println!("kernel position: {}", hdr.kernel_position());
16    let mut w = BufWriter::new(File::create("boot_a_kernel").unwrap());
17    let r = r.get_mut();
18    r.seek(SeekFrom::Start(hdr.kernel_position() as u64))
19        .unwrap();
20    io::copy(&mut r.take(hdr.kernel_size().into()), w.get_mut()).unwrap();
21}
Source

pub fn write<W: Write>(&self, writer: &mut W) -> Result<(), Error>

Serializes a standard Android boot image header to a writer.

Note that you must write the kernel, ramdisk, etc. yourself.

§Errors

This forwards errors from writer.

Source

pub const fn header_version(&self) -> u32

Returns the boot image header’s version number.

Source

pub const fn osversionpatch(&self) -> OsVersionPatch

Returns the boot image header’s OS version and patch level.

Source

pub const fn kernel_position(&self) -> usize

Returns the kernel’s position in the boot image.

Examples found in repository?
examples/extract-kernel.rs (line 15)
10fn main() {
11    let mut r = BufReader::new(File::open("boot_a.img").unwrap());
12    let hdr = Header::parse(&mut r).unwrap();
13    println!("{hdr:#?}");
14
15    println!("kernel position: {}", hdr.kernel_position());
16    let mut w = BufWriter::new(File::create("boot_a_kernel").unwrap());
17    let r = r.get_mut();
18    r.seek(SeekFrom::Start(hdr.kernel_position() as u64))
19        .unwrap();
20    io::copy(&mut r.take(hdr.kernel_size().into()), w.get_mut()).unwrap();
21}
Source

pub const fn kernel_size(&self) -> u32

Returns the kernel’s size.

Examples found in repository?
examples/extract-kernel.rs (line 20)
10fn main() {
11    let mut r = BufReader::new(File::open("boot_a.img").unwrap());
12    let hdr = Header::parse(&mut r).unwrap();
13    println!("{hdr:#?}");
14
15    println!("kernel position: {}", hdr.kernel_position());
16    let mut w = BufWriter::new(File::create("boot_a_kernel").unwrap());
17    let r = r.get_mut();
18    r.seek(SeekFrom::Start(hdr.kernel_position() as u64))
19        .unwrap();
20    io::copy(&mut r.take(hdr.kernel_size().into()), w.get_mut()).unwrap();
21}
Source

pub const fn ramdisk_position(&self) -> usize

Returns the ramdisk’s position in the boot image.

Source

pub const fn ramdisk_size(&self) -> u32

Returns the ramdisk’s size.

Source

pub const fn page_size(&self) -> usize

Returns the page size in bytes.

Source

pub const fn cmdline(&self) -> &[u8; 1536]

Returns the kernel command line.

Trait Implementations§

Source§

impl Clone for Header

Source§

fn clone(&self) -> Header

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Header

Source§

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

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

impl Hash for Header

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Header

Source§

fn eq(&self, other: &Header) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Header

Source§

impl StructuralPartialEq for Header

Auto Trait Implementations§

§

impl Freeze for Header

§

impl RefUnwindSafe for Header

§

impl Send for Header

§

impl Sync for Header

§

impl Unpin for Header

§

impl UnwindSafe for Header

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.