bmatcher_core/atom.rs
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 60 61 62 63 64 65 66
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum JumpType {
RelByte,
RelDWord,
AbsQWord,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum ReadWidth {
Byte,
Word,
DWord,
}
/// An atom represents a single operation that the matcher should perform.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Atom {
/// Match a sequence of bytes from the sequence array.
ByteSequence { seq_start: u16, seq_end: u16 },
/// Match a sequence of bytes from the sequence array
/// using a custom bitmask.
ByteSequenceMasked {
/// Start of the byte sequence in the sequence array.
seq_start: u16,
/// Start of the byte mask in the sequence array.
mask_start: u16,
/// Number of bytes to match
len: u16,
},
/// Skip a fixed number of bytes.
WildcardFixed(u16),
/// Skip a variable number of bytes.
WildcardRange { min: u16, max: u16 },
/// Jump to the relative / absolute based on the binary data the current cursor location.
Jump(JumpType),
/// Read the data value of a specified size at the current cursors location and save it to the save stack.
/// This also advances the data cursor by the specified size.
Read(ReadWidth),
/// Match any one of the two subexpressions
/// and then continue where we left of.
Branch {
/// Length of the left subpattern
left_len: u16,
/// Length of the right subpattern
right_len: u16,
},
/// Push the cursor location to the cursor stack
CursorPush,
/// Pop the cursor location from the cursor stack and advance by X bytes
CursorPop { advance: u16 },
/// Save the current cursor position to the save stack
SaveCursor,
/// Save the constant to the save stack.
/// This can be usefull to save which branch has been taken.
SaveConstant(u32),
}