From 8452b3219000ff707b8ba0bed3500513fb24d81e Mon Sep 17 00:00:00 2001 From: Josselin Date: Thu, 3 Jan 2019 17:10:27 +0000 Subject: [PATCH] Add CFG Printer --- slither/__main__.py | 4 +++- slither/printers/functions/cfg.py | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 slither/printers/functions/cfg.py diff --git a/slither/__main__.py b/slither/__main__.py index 3be86abf6..4fcfadf3a 100644 --- a/slither/__main__.py +++ b/slither/__main__.py @@ -168,6 +168,7 @@ def get_detectors_and_printers(): from slither.printers.functions.authorization import PrinterWrittenVariablesAndAuthorization from slither.printers.summary.slithir import PrinterSlithIR from slither.printers.summary.human_summary import PrinterHumanSummary + from slither.printers.functions.cfg import CFG printers = [FunctionSummary, ContractSummary, @@ -176,7 +177,8 @@ def get_detectors_and_printers(): PrinterCallGraph, PrinterWrittenVariablesAndAuthorization, PrinterSlithIR, - PrinterHumanSummary] + PrinterHumanSummary, + CFG] # Handle plugins! for entry_point in iter_entry_points(group='slither_analyzer.plugin', name=None): diff --git a/slither/printers/functions/cfg.py b/slither/printers/functions/cfg.py new file mode 100644 index 000000000..d276ce423 --- /dev/null +++ b/slither/printers/functions/cfg.py @@ -0,0 +1,24 @@ +""" +""" + +from slither.printers.abstract_printer import AbstractPrinter +from slither.core.declarations.function import Function + +class CFG(AbstractPrinter): + + ARGUMENT = 'cfg' + HELP = 'Export the CFG of each functions' + + def output(self, original_filename): + """ + _filename is not used + Args: + _filename(string) + """ + + for contract in self.contracts: + for function in contract.functions + contract.modifiers: + filename = "{}-{}-{}.dot".format(original_filename, contract.name, function.full_name) + self.info('Export {}'.format(filename)) + function.slithir_cfg_to_dot(filename) +