From 8c8e54b00710755a15f538cd4c20a4f46dac6cf5 Mon Sep 17 00:00:00 2001 From: Josselin Feist Date: Fri, 12 Aug 2022 18:44:34 +0200 Subject: [PATCH 1/2] Add printer for dominator tree --- slither/printers/all_printers.py | 1 + slither/printers/functions/dominator.py | 38 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 slither/printers/functions/dominator.py diff --git a/slither/printers/all_printers.py b/slither/printers/all_printers.py index 3165d220f..d72dce062 100644 --- a/slither/printers/all_printers.py +++ b/slither/printers/all_printers.py @@ -19,3 +19,4 @@ from .guidance.echidna import Echidna from .summary.evm import PrinterEVM from .summary.when_not_paused import PrinterWhenNotPaused from .summary.declaration import Declaration +from .functions.dominator import Dominator \ No newline at end of file diff --git a/slither/printers/functions/dominator.py b/slither/printers/functions/dominator.py new file mode 100644 index 000000000..bafa8cc73 --- /dev/null +++ b/slither/printers/functions/dominator.py @@ -0,0 +1,38 @@ +from typing import List + +from slither.core.declarations import Function +from slither.printers.abstract_printer import AbstractPrinter + + +class Dominator(AbstractPrinter): + + ARGUMENT = "dominator" + HELP = "Export the dominator tree of each functions" + + WIKI = "https://github.com/trailofbits/slither/wiki/Printer-documentation#dominator" + + def output(self, filename): + """ + _filename is not used + Args: + _filename(string) + """ + + info = "" + all_files = [] + for contract in self.contracts: + for function in contract.functions + contract.modifiers: + if filename: + new_filename = f"{filename}-{contract.name}-{function.full_name}.dot" + else: + new_filename = f"dominator-{contract.name}-{function.full_name}.dot" + info += f"Export {new_filename}\n" + content = function.dominator_tree_to_dot(new_filename) + all_files.append((new_filename, content)) + + self.info(info) + + res = self.generate_output(info) + for filename_result, content in all_files: + res.add_file(filename_result, content) + return res From eed53dd4b077490c66d30891181d5ed0b541696e Mon Sep 17 00:00:00 2001 From: Josselin Feist Date: Mon, 15 Aug 2022 12:00:46 +0200 Subject: [PATCH 2/2] minor --- slither/printers/all_printers.py | 2 +- slither/printers/functions/dominator.py | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/slither/printers/all_printers.py b/slither/printers/all_printers.py index d72dce062..6dc8dddbd 100644 --- a/slither/printers/all_printers.py +++ b/slither/printers/all_printers.py @@ -19,4 +19,4 @@ from .guidance.echidna import Echidna from .summary.evm import PrinterEVM from .summary.when_not_paused import PrinterWhenNotPaused from .summary.declaration import Declaration -from .functions.dominator import Dominator \ No newline at end of file +from .functions.dominator import Dominator diff --git a/slither/printers/functions/dominator.py b/slither/printers/functions/dominator.py index bafa8cc73..f618fd5db 100644 --- a/slither/printers/functions/dominator.py +++ b/slither/printers/functions/dominator.py @@ -1,6 +1,3 @@ -from typing import List - -from slither.core.declarations import Function from slither.printers.abstract_printer import AbstractPrinter