Add --list-detectors-json hidden option

pull/113/head
Josselin 6 years ago
parent a376efabd4
commit 7f93370128
  1. 15
      slither/__main__.py
  2. 28
      slither/utils/command_line.py

@ -16,7 +16,7 @@ from slither.detectors.abstract_detector import (AbstractDetector,
from slither.printers.abstract_printer import AbstractPrinter from slither.printers.abstract_printer import AbstractPrinter
from slither.slither import Slither from slither.slither import Slither
from slither.utils.colors import red from slither.utils.colors import red
from slither.utils.command_line import output_to_markdown, output_detectors, output_printers from slither.utils.command_line import output_to_markdown, output_detectors, output_printers, output_detectors_json
logging.basicConfig() logging.basicConfig()
logger = logging.getLogger("Slither") logger = logging.getLogger("Slither")
@ -384,6 +384,12 @@ def parse_args(detector_classes, printer_classes):
nargs=0, nargs=0,
default=False) default=False)
parser.add_argument('--list-detectors-json',
help=argparse.SUPPRESS,
action=ListDetectorsJson,
nargs=0,
default=False)
parser.add_argument('--compact-ast', parser.add_argument('--compact-ast',
help=argparse.SUPPRESS, help=argparse.SUPPRESS,
action='store_true', action='store_true',
@ -403,6 +409,12 @@ class ListDetectors(argparse.Action):
output_detectors(detectors) output_detectors(detectors)
parser.exit() parser.exit()
class ListDetectorsJson(argparse.Action):
def __call__(self, parser, *args, **kwargs):
detectors, _ = get_detectors_and_printers()
output_detectors_json(detectors)
parser.exit()
class ListPrinters(argparse.Action): class ListPrinters(argparse.Action):
def __call__(self, parser, *args, **kwargs): def __call__(self, parser, *args, **kwargs):
_, printers = get_detectors_and_printers() _, printers = get_detectors_and_printers()
@ -416,6 +428,7 @@ class OutputMarkdown(argparse.Action):
parser.exit() parser.exit()
def choose_detectors(args, all_detector_classes): def choose_detectors(args, all_detector_classes):
# If detectors are specified, run only these ones # If detectors are specified, run only these ones

@ -1,3 +1,4 @@
import json
from prettytable import PrettyTable from prettytable import PrettyTable
from slither.detectors.abstract_detector import classification_txt from slither.detectors.abstract_detector import classification_txt
@ -70,6 +71,33 @@ def output_detectors(detector_classes):
idx = idx + 1 idx = idx + 1
print(table) print(table)
def output_detectors_json(detector_classes):
detectors_list = []
for detector in detector_classes:
argument = detector.ARGUMENT
# dont show the backdoor example
if argument == 'backdoor':
continue
help_info = detector.HELP
impact = detector.IMPACT
confidence = classification_txt[detector.CONFIDENCE]
wiki = detector.WIKI
detectors_list.append((argument, help_info, impact, confidence, wiki))
# Sort by impact, confidence, and name
detectors_list = sorted(detectors_list, key=lambda element: (element[2], element[3], element[0]))
idx = 1
table = []
for (argument, help_info, impact, confidence, wiki) in detectors_list:
table.append({'index': idx,
'check': argument,
'description': help_info,
'impact': classification_txt[impact],
'confidence': confidence,
'wiki': wiki})
idx = idx + 1
print(json.dumps(table))
def output_printers(printer_classes): def output_printers(printer_classes):
printers_list = [] printers_list = []
for printer in printer_classes: for printer in printer_classes:

Loading…
Cancel
Save