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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#[test]
fn ida_pattern() {
assert!(
// Valid IDA pattern (mix of ? and ?? is allowed)
aobscan::PatternBuilder::from_ida_style("48 8B ?? ?").is_ok()
);
assert!(
// Valid IDA pattern (spaces are not considered)
aobscan::PatternBuilder::from_ida_style("48 8B 48 8B 88").is_ok()
);
assert!(
// Valid IDA pattern (one-char patterns are allowed)
aobscan::PatternBuilder::from_ida_style("A").is_ok()
);
assert!(
// Invalid IDA pattern (empty pattern)
aobscan::PatternBuilder::from_ida_style("").is_err()
);
assert!(
// Invalid IDA pattern (invalid byte)
aobscan::PatternBuilder::from_ida_style("48 8B ? ? 48 8B 88 ? ? ? ZA").is_err()
);
assert!(
// Invalid IDA pattern (invalid wildcard length)
aobscan::PatternBuilder::from_ida_style("48 8B ? ? 48 8B 88 ? ? ???").is_err()
);
assert!(
// Valid IDA pattern (signatures without static bytes are allowed, but pointless)
aobscan::PatternBuilder::from_ida_style("?? ?? ?? ??").is_ok()
);
}
#[test]
fn code_pattern() {
// Code patterns are usually pretty safe, so we don't need to test them as much.
assert!(
// Valid code pattern
aobscan::PatternBuilder::from_code_style(b"\x48\x8B\x00\x00", "..??").is_ok()
);
assert!(
// Invalid code pattern (length of pattern and mask don't match)
aobscan::PatternBuilder::from_code_style(b"\x48\x8B\x00\x00", "...??").is_err()
);
}
#[test]
fn hex_pattern() {
assert!(
// Valid hex pattern
aobscan::PatternBuilder::from_hex_string("488b????").is_ok()
);
assert!(
// Valid hex pattern (signatures without static bytes are allowed, but pointless)
aobscan::PatternBuilder::from_hex_string("????").is_ok()
);
assert!(
// Invalid hex pattern (invalid byte)
aobscan::PatternBuilder::from_hex_string("488b????ZA").is_err()
);
assert!(
// Invalid hex pattern (single char wildcard)
aobscan::PatternBuilder::from_hex_string("488b???b").is_err()
);
assert!(
// Invalid hex pattern (length of pattern is not a multiple of 2)
aobscan::PatternBuilder::from_hex_string("488b0f3").is_err()
);
assert!(
// Invalid hex pattern (empty pattern)
aobscan::PatternBuilder::from_hex_string("").is_err()
);
assert!(
// Invalid hex pattern (empty pattern)
aobscan::PatternBuilder::from_hex_string(" ").is_err()
);
assert!(
// Invalid hex pattern (single-char wildcard)
aobscan::PatternBuilder::from_hex_string("?").is_err()
);
}