bmatcher_core/
atom.rs

1#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
2pub enum JumpType {
3    RelByte,
4    RelDWord,
5    AbsQWord,
6}
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
9pub enum ReadWidth {
10    Byte,
11    Word,
12    DWord,
13}
14
15/// An atom represents a single operation that the matcher should perform.
16#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
17pub enum Atom {
18    /// Match a sequence of bytes from the sequence array.
19    ByteSequence { seq_start: u16, seq_end: u16 },
20
21    /// Match a sequence of bytes from the sequence array
22    /// using a custom bitmask.
23    ByteSequenceMasked {
24        /// Start of the byte sequence in the sequence array.
25        seq_start: u16,
26
27        /// Start of the byte mask in the sequence array.
28        mask_start: u16,
29
30        /// Number of bytes to match
31        len: u16,
32    },
33
34    /// Skip a fixed number of bytes.
35    WildcardFixed(u16),
36    /// Skip a variable number of bytes.
37    WildcardRange { min: u16, max: u16 },
38
39    /// Jump to the relative / absolute based on the binary data the current cursor location.
40    Jump(JumpType),
41
42    /// Read the data value of a specified size at the current cursors location and save it to the save stack.
43    /// This also advances the data cursor by the specified size.
44    Read(ReadWidth),
45
46    /// Match any one of the two subexpressions
47    /// and then continue where we left of.
48    Branch {
49        /// Length of the left subpattern
50        left_len: u16,
51
52        /// Length of the right subpattern
53        right_len: u16,
54    },
55
56    /// Push the cursor location to the cursor stack
57    CursorPush,
58    /// Pop the cursor location from the cursor stack and advance by X bytes
59    CursorPop { advance: u16 },
60
61    /// Save the current cursor position to the save stack
62    SaveCursor,
63    /// Save the constant to the save stack.
64    /// This can be usefull to save which branch has been taken.    
65    SaveConstant(u32),
66}