Skip to main content

MethodHeader

Struct MethodHeader 

Source
pub struct MethodHeader {
    pub param_count: u8,
    pub varargs: bool,
    pub optional_param_count: u8,
    pub local_count: u16,
    pub stack_depth: u16,
    pub exception_table_offset: u16,
    pub debug_records_offset: u16,
}
Expand description

The fixed-size record at the start of every function.

Fields§

§param_count: u8

Number of required parameters.

§varargs: bool

Whether the function accepts any number of further arguments.

§optional_param_count: u8

Number of optional parameters after the required ones.

§local_count: u16

Number of local variables.

§stack_depth: u16

Stack slots the function needs for locals and intermediate values.

§exception_table_offset: u16

Offset of the exception table from the start of the header, or 0.

§debug_records_offset: u16

Offset of the debug records from the start of the header, or 0.

Implementations§

Source§

impl MethodHeader

Source

pub const MIN_SIZE: usize = 10

The smallest header this crate reads. Images state their own header size, which may be larger; later fields are ignored.

Source

pub fn parse(bytes: &[u8]) -> Option<Self>

Read a header from the start of bytes.

Examples found in repository?
examples/probe.rs (line 18)
8fn main() {
9    let args: Vec<String> = std::env::args().skip(1).collect();
10    let data = std::fs::read(&args[0]).expect("cannot read image");
11    let image = Image::parse(&data).expect("cannot parse image");
12    let address = u32::from_str_radix(args[1].trim_start_matches("0x"), 16).expect("bad address");
13    let count: usize = args.get(2).map_or(40, |n| n.parse().expect("bad count"));
14    let page = image
15        .code_pool
16        .at(address)
17        .expect("address is not in the code pool");
18    println!("{:?}", MethodHeader::parse(page));
19    println!("{:02x?}", &page[..page.len().min(16)]);
20    let mut offset = u32::from(image.entry_point.method_header_size);
21    for _ in 0..count {
22        match decode(page, offset) {
23            Ok(i) => {
24                println!(
25                    "{:04x}  {:<14} {:?} {:?}",
26                    i.offset,
27                    i.opcode.name(),
28                    i.operands,
29                    i.payload
30                );
31                offset += i.len;
32            }
33            Err(error) => {
34                println!("{error}");
35                break;
36            }
37        }
38    }
39}

Trait Implementations§

Source§

impl Clone for MethodHeader

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for MethodHeader

Source§

impl Debug for MethodHeader

Source§

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

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

impl Eq for MethodHeader

Source§

impl PartialEq for MethodHeader

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for MethodHeader

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> 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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.