Macro aob::aob

source ·
aob!() { /* proc-macro */ }
Expand description

Parses, validates, and constructs a Needle at compile-time.

§Syntax

aob! {
    [pub] const NAME_1 = METHOD_1("PATTERN_1");
    [pub] const NAME_2 = METHOD_2("PATTERN_2");
    ...
    [pub] const NAME_N = METHOD_N("PATTERN_N");
}

Expects syntax of the form: $VISIBILITY? const $IDENTIFIER = $METHOD("$PATTERN");

With the following rules:

  • $VISIBILITY is a valid Visibility token, or nothing.
  • $IDENTIFIER is a valid Identifier token.
  • $METHOD is one of:
    • ida.
  • $PATTERN is a valid pattern whose syntax depends on the chosen $METHOD.

§Example

aob! {
    const NEEDLE = ida("78 ? BC");
}
let haystack = [0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE];
let matched = NEEDLE.find(&haystack).unwrap();
assert_eq!(matched.as_bytes(), [0x78, 0x9A, 0xBC]);