1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Internal little-endian reading and signature helpers.
//!
//! These are the bounds-checked primitives shared by the container and record
//! parsers. Each reader takes an explicit offset and returns `None` instead of
//! panicking when the requested bytes fall outside `data`, so callers can treat
//! a short or malformed input as a recoverable miss.
/// Returns whether the input begins with the DOS `MZ` executable signature.
///
/// # Arguments
///
/// * `data` - Bytes to inspect, typically the start of a candidate input file.
///
/// # Returns
///
/// `true` if `data` starts with the two-byte `MZ` magic; `false` otherwise,
/// including when `data` is shorter than two bytes.
/// Reads a little-endian `u16` at `offset`.
///
/// # Arguments
///
/// * `data` - Buffer to read from.
/// * `offset` - Byte offset of the first of the two little-endian bytes.
///
/// # Returns
///
/// The decoded `u16`, or `None` if `offset + 2` overflows `usize` or extends
/// past the end of `data`.
/// Reads a little-endian `u32` at `offset`.
///
/// # Arguments
///
/// * `data` - Buffer to read from.
/// * `offset` - Byte offset of the first of the four little-endian bytes.
///
/// # Returns
///
/// The decoded `u32`, or `None` if `offset + 4` overflows `usize` or extends
/// past the end of `data`.