|
|
@ -23,7 +23,7 @@ from slither.detectors.abstract_detector import AbstractDetector, DetectorClassi |
|
|
|
from slither.printers import all_printers |
|
|
|
from slither.printers import all_printers |
|
|
|
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.output import output_to_json, output_to_zip, ZIP_TYPES_ACCEPTED |
|
|
|
from slither.utils.output import output_to_json, output_to_zip, output_to_sarif, ZIP_TYPES_ACCEPTED |
|
|
|
from slither.utils.output_capture import StandardOutputCapture |
|
|
|
from slither.utils.output_capture import StandardOutputCapture |
|
|
|
from slither.utils.colors import red, blue, set_colorization_enabled |
|
|
|
from slither.utils.colors import red, blue, set_colorization_enabled |
|
|
|
from slither.utils.command_line import ( |
|
|
|
from slither.utils.command_line import ( |
|
|
@ -388,6 +388,13 @@ def parse_args(detector_classes, printer_classes): # pylint: disable=too-many-s |
|
|
|
default=defaults_flag_in_config["json"], |
|
|
|
default=defaults_flag_in_config["json"], |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
group_misc.add_argument( |
|
|
|
|
|
|
|
"--sarif", |
|
|
|
|
|
|
|
help='Export the results as a SARIF JSON file ("--sarif -" to export to stdout)', |
|
|
|
|
|
|
|
action="store", |
|
|
|
|
|
|
|
default=defaults_flag_in_config["sarif"], |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
group_misc.add_argument( |
|
|
|
group_misc.add_argument( |
|
|
|
"--json-types", |
|
|
|
"--json-types", |
|
|
|
help="Comma-separated list of result types to output to JSON, defaults to " |
|
|
|
help="Comma-separated list of result types to output to JSON, defaults to " |
|
|
@ -636,6 +643,8 @@ def main_impl(all_detector_classes, all_printer_classes): |
|
|
|
output_error = None |
|
|
|
output_error = None |
|
|
|
outputting_json = args.json is not None |
|
|
|
outputting_json = args.json is not None |
|
|
|
outputting_json_stdout = args.json == "-" |
|
|
|
outputting_json_stdout = args.json == "-" |
|
|
|
|
|
|
|
outputting_sarif = args.sarif is not None |
|
|
|
|
|
|
|
outputting_sarif_stdout = args.sarif == "-" |
|
|
|
outputting_zip = args.zip is not None |
|
|
|
outputting_zip = args.zip is not None |
|
|
|
if args.zip_type not in ZIP_TYPES_ACCEPTED.keys(): |
|
|
|
if args.zip_type not in ZIP_TYPES_ACCEPTED.keys(): |
|
|
|
to_log = f'Zip type not accepted, it must be one of {",".join(ZIP_TYPES_ACCEPTED.keys())}' |
|
|
|
to_log = f'Zip type not accepted, it must be one of {",".join(ZIP_TYPES_ACCEPTED.keys())}' |
|
|
@ -643,8 +652,8 @@ def main_impl(all_detector_classes, all_printer_classes): |
|
|
|
|
|
|
|
|
|
|
|
# If we are outputting JSON, capture all standard output. If we are outputting to stdout, we block typical stdout |
|
|
|
# If we are outputting JSON, capture all standard output. If we are outputting to stdout, we block typical stdout |
|
|
|
# output. |
|
|
|
# output. |
|
|
|
if outputting_json: |
|
|
|
if outputting_json or output_to_sarif: |
|
|
|
StandardOutputCapture.enable(outputting_json_stdout) |
|
|
|
StandardOutputCapture.enable(outputting_json_stdout or outputting_sarif_stdout ) |
|
|
|
|
|
|
|
|
|
|
|
printer_classes = choose_printers(args, all_printer_classes) |
|
|
|
printer_classes = choose_printers(args, all_printer_classes) |
|
|
|
detector_classes = choose_detectors(args, all_detector_classes) |
|
|
|
detector_classes = choose_detectors(args, all_detector_classes) |
|
|
@ -723,7 +732,7 @@ def main_impl(all_detector_classes, all_printer_classes): |
|
|
|
) = process_all(filename, args, detector_classes, printer_classes) |
|
|
|
) = process_all(filename, args, detector_classes, printer_classes) |
|
|
|
|
|
|
|
|
|
|
|
# Determine if we are outputting JSON |
|
|
|
# Determine if we are outputting JSON |
|
|
|
if outputting_json or outputting_zip: |
|
|
|
if outputting_json or outputting_zip or output_to_sarif: |
|
|
|
# Add our compilation information to JSON |
|
|
|
# Add our compilation information to JSON |
|
|
|
if "compilations" in args.json_types: |
|
|
|
if "compilations" in args.json_types: |
|
|
|
compilation_results = [] |
|
|
|
compilation_results = [] |
|
|
@ -800,6 +809,10 @@ def main_impl(all_detector_classes, all_printer_classes): |
|
|
|
StandardOutputCapture.disable() |
|
|
|
StandardOutputCapture.disable() |
|
|
|
output_to_json(None if outputting_json_stdout else args.json, output_error, json_results) |
|
|
|
output_to_json(None if outputting_json_stdout else args.json, output_error, json_results) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if outputting_sarif: |
|
|
|
|
|
|
|
StandardOutputCapture.disable() |
|
|
|
|
|
|
|
output_to_sarif(None if outputting_sarif_stdout else args.sarif, None, json_results) |
|
|
|
|
|
|
|
|
|
|
|
if outputting_zip: |
|
|
|
if outputting_zip: |
|
|
|
output_to_zip(args.zip, output_error, json_results, args.zip_type) |
|
|
|
output_to_zip(args.zip, output_error, json_results, args.zip_type) |
|
|
|
|
|
|
|
|
|
|
|