summaryrefslogtreecommitdiff
path: root/tests/analysis/scan/matches.py
blob: efcae4f4afabb32a40c61cfa3a87797f9cf2ad8d (plain)
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

from common import RostTestClass
from pychrysalide.analysis.contents import MemoryContent


class TestRostMatchs(RostTestClass):
    """TestCases for the ROST pattern matching engine."""

    def testCountMatches(self):
        """Count matched patterns."""

        cnt = MemoryContent(b'aaa aaa bbb aaa')

        rule = '''
rule test {

   bytes:
      $a = "aaa"
      $b = "bbb"

   condition:
      #a == 3 and #b < 2

}
'''

        self.check_rule_success(rule, cnt)


    def testCountSameMatches(self):
        """Count matches of similar patterns."""

        cnt = MemoryContent(b'ABCDabcdABCDabcd')

        rule = '''
rule test {

   bytes:
      $a = "\x61\x62\x63\x64"
      $b = "\x61\x62\x63\x64"

   condition:
      #a == 2 and #b == 2

}
'''

        self.check_rule_success(rule, cnt)


        rule = '''
rule test {

   bytes:
      $a = "\x61\x62\x63\x64"
      $b = "\x61\x62\x63"

   condition:
      #a == 2 and #b == 2

}
'''

        self.check_rule_success(rule, cnt)