-
My Codes: #[derive(Debug, BinRead)]
#[br(little)]
pub struct ImageDosHeader { // DOS .EXE header
#[br(magic = b"MZ")]
e_magic: u16, // Magic number
e_cblp: u16, // Bytes on last page of file
e_cp: u16,
...
}
...
fn main() {
let imageDosHeader = ImageDosHeader::parse("D:\\sample.exe");
println!("{:?}", &imageDosHeader);
} The binary data in the sample exe file:
The output is:
The field |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
Hi, thanks for your question! The
Since the magic value must be a constant, storing what is matched is a waste of memory. However, if you really want to store a value and then assert that it matches some thing, you can do that using the |
Beta Was this translation helpful? Give feedback.
Hi, thanks for your question! The
magic
directive always consumes the matched value. From the docs:Since the magic value must be a constant, storing what is matched is a waste of memory. However, if you really want to store a value and then assert that it matches some thing, you can do that using the
assert
directive instead.