Compile all defined string pattern matchers into a dictionary indexed by type :signatures: a list of defined signatures (loaded from json file)
(cls, signatures: List[dict])
| 77 | |
| 78 | @classmethod |
| 79 | def compile_patterns(cls, signatures: List[dict]) -> List[PatternMatcher]: |
| 80 | """ |
| 81 | Compile all defined string pattern matchers into a dictionary indexed by type |
| 82 | :signatures: a list of defined signatures (loaded from json file) |
| 83 | """ |
| 84 | types = PatternMatcher.get_patterns() |
| 85 | |
| 86 | compiled = [] |
| 87 | for s in signatures: |
| 88 | if type(s) == str: |
| 89 | s = {"type": "exact", "pattern": s, "message": "n/a"} |
| 90 | |
| 91 | if s["type"] not in types: |
| 92 | raise ValueError("Unknown signature type: " + s["type"]) |
| 93 | |
| 94 | compiled.append(types[s["type"]](s)) |
| 95 | |
| 96 | return compiled |
| 97 | |
| 98 | @classmethod |
| 99 | def find_matches(cls, value, signatures: list): |