|
11 | 11 | import sys
|
12 | 12 | import traceback
|
13 | 13 | from importlib import metadata
|
14 |
| -from typing import Tuple, Optional, List, Dict, Type, Union, Any, Sequence |
| 14 | +from typing import Any, Dict, List, Optional, Sequence, Set, Tuple, Type, Union |
15 | 15 |
|
16 | 16 |
|
17 | 17 | from crytic_compile import cryticparser, CryticCompile, InvalidCompilation
|
@@ -211,47 +211,54 @@ def choose_detectors(
|
211 | 211 |
|
212 | 212 | if args.detectors_to_run == "all":
|
213 | 213 | detectors_to_run = all_detector_classes
|
214 |
| - if args.detectors_to_exclude: |
215 |
| - detectors_excluded = args.detectors_to_exclude.split(",") |
216 |
| - for detector in detectors: |
217 |
| - if detector in detectors_excluded: |
218 |
| - detectors_to_run.remove(detectors[detector]) |
219 | 214 | else:
|
220 |
| - for detector in args.detectors_to_run.split(","): |
221 |
| - if detector in detectors: |
222 |
| - detectors_to_run.append(detectors[detector]) |
223 |
| - else: |
224 |
| - raise ValueError(f"Error: {detector} is not a detector") |
225 |
| - detectors_to_run = sorted(detectors_to_run, key=lambda x: x.IMPACT) |
| 215 | + detectors_to_run = __include_detectors( |
| 216 | + set(detectors_to_run), args.detectors_to_run, detectors |
| 217 | + ) |
226 | 218 | return detectors_to_run
|
227 | 219 |
|
228 |
| - if args.exclude_optimization: |
229 |
| - detectors_to_run = [ |
230 |
| - d for d in detectors_to_run if d.IMPACT != DetectorClassification.OPTIMIZATION |
231 |
| - ] |
| 220 | + classification_map = { |
| 221 | + DetectorClassification.HIGH: args.exclude_high, |
| 222 | + DetectorClassification.MEDIUM: args.exclude_medium, |
| 223 | + DetectorClassification.LOW: args.exclude_low, |
| 224 | + DetectorClassification.INFORMATIONAL: args.exclude_informational, |
| 225 | + DetectorClassification.OPTIMIZATION: args.exclude_optimization, |
| 226 | + } |
| 227 | + excluded_classification = [ |
| 228 | + classification for classification, included in classification_map.items() if included |
| 229 | + ] |
| 230 | + detectors_to_run = [d for d in detectors_to_run if d.IMPACT not in excluded_classification] |
232 | 231 |
|
233 |
| - if args.exclude_informational: |
234 |
| - detectors_to_run = [ |
235 |
| - d for d in detectors_to_run if d.IMPACT != DetectorClassification.INFORMATIONAL |
236 |
| - ] |
237 |
| - if args.exclude_low: |
238 |
| - detectors_to_run = [d for d in detectors_to_run if d.IMPACT != DetectorClassification.LOW] |
239 |
| - if args.exclude_medium: |
240 |
| - detectors_to_run = [ |
241 |
| - d for d in detectors_to_run if d.IMPACT != DetectorClassification.MEDIUM |
242 |
| - ] |
243 |
| - if args.exclude_high: |
244 |
| - detectors_to_run = [d for d in detectors_to_run if d.IMPACT != DetectorClassification.HIGH] |
245 | 232 | if args.detectors_to_exclude:
|
246 | 233 | detectors_to_run = [
|
247 | 234 | d for d in detectors_to_run if d.ARGUMENT not in args.detectors_to_exclude
|
248 | 235 | ]
|
249 | 236 |
|
250 |
| - detectors_to_run = sorted(detectors_to_run, key=lambda x: x.IMPACT) |
| 237 | + if args.detectors_to_include: |
| 238 | + detectors_to_run = __include_detectors( |
| 239 | + set(detectors_to_run), args.detectors_to_include, detectors |
| 240 | + ) |
251 | 241 |
|
252 | 242 | return detectors_to_run
|
253 | 243 |
|
254 | 244 |
|
| 245 | +def __include_detectors( |
| 246 | + detectors_to_run: Set[Type[AbstractDetector]], |
| 247 | + detectors_to_include: str, |
| 248 | + detectors: Dict[str, Type[AbstractDetector]], |
| 249 | +) -> List[Type[AbstractDetector]]: |
| 250 | + include_detectors = detectors_to_include.split(",") |
| 251 | + |
| 252 | + for detector in include_detectors: |
| 253 | + if detector in detectors: |
| 254 | + detectors_to_run.add(detectors[detector]) |
| 255 | + else: |
| 256 | + raise ValueError(f"Error: {detector} is not a detector") |
| 257 | + |
| 258 | + detectors_to_run = sorted(detectors_to_run, key=lambda x: x.IMPACT) |
| 259 | + return detectors_to_run |
| 260 | + |
| 261 | + |
255 | 262 | def choose_printers(
|
256 | 263 | args: argparse.Namespace, all_printer_classes: List[Type[AbstractPrinter]]
|
257 | 264 | ) -> List[Type[AbstractPrinter]]:
|
@@ -407,6 +414,14 @@ def parse_args(
|
407 | 414 | default=defaults_flag_in_config["exclude_high"],
|
408 | 415 | )
|
409 | 416 |
|
| 417 | + group_detector.add_argument( |
| 418 | + "--include-detectors", |
| 419 | + help="Comma-separated list of detectors that should be included", |
| 420 | + action="store", |
| 421 | + dest="detectors_to_include", |
| 422 | + default=defaults_flag_in_config["detectors_to_include"], |
| 423 | + ) |
| 424 | + |
410 | 425 | fail_on_group = group_detector.add_mutually_exclusive_group()
|
411 | 426 | fail_on_group.add_argument(
|
412 | 427 | "--fail-pedantic",
|
|
0 commit comments