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: u8Number of required parameters.
varargs: boolWhether the function accepts any number of further arguments.
optional_param_count: u8Number of optional parameters after the required ones.
local_count: u16Number of local variables.
stack_depth: u16Stack slots the function needs for locals and intermediate values.
exception_table_offset: u16Offset of the exception table from the start of the header, or 0.
debug_records_offset: u16Offset of the debug records from the start of the header, or 0.
Implementations§
Source§impl MethodHeader
impl MethodHeader
Sourcepub const MIN_SIZE: usize = 10
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.
Sourcepub fn parse(bytes: &[u8]) -> Option<Self>
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
impl Clone for MethodHeader
impl Copy for MethodHeader
Source§impl Debug for MethodHeader
impl Debug for MethodHeader
impl Eq for MethodHeader
Source§impl PartialEq for MethodHeader
impl PartialEq for MethodHeader
impl StructuralPartialEq for MethodHeader
Auto Trait Implementations§
impl Forget for MethodHeader
impl Freeze for MethodHeader
impl Move for MethodHeader
impl RefUnwindSafe for MethodHeader
impl Send for MethodHeader
impl Sync for MethodHeader
impl Unpin for MethodHeader
impl UnsafeUnpin for MethodHeader
impl UnwindSafe for MethodHeader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more