mirror of https://github.com/crytic/slither
Merge pull request #14 from trailofbits/register-api
Make detectors and printers registrablepull/15/head
commit
d3265490ea
@ -1,5 +0,0 @@ |
||||
class DetectorClassification: |
||||
LOW = 0 |
||||
MEDIUM = 1 |
||||
HIGH = 2 |
||||
CODE_QUALITY = 3 |
@ -1,52 +0,0 @@ |
||||
import sys, inspect |
||||
import os |
||||
import logging |
||||
|
||||
from slither.detectors.abstractDetector import AbstractDetector |
||||
from slither.detectors.detectorClassification import DetectorClassification |
||||
|
||||
# Detectors must be imported here |
||||
from slither.detectors.examples.backdoor import Backdoor |
||||
from slither.detectors.variables.uninitializedStateVarsDetection import UninitializedStateVarsDetection |
||||
from slither.detectors.attributes.constant_pragma import ConstantPragma |
||||
from slither.detectors.attributes.old_solc import OldSolc |
||||
|
||||
### |
||||
|
||||
logger_detector = logging.getLogger("Detectors") |
||||
|
||||
class Detectors: |
||||
|
||||
def __init__(self): |
||||
self.detectors = {} |
||||
self.low = [] |
||||
self.medium = [] |
||||
self.high = [] |
||||
self.code_quality = [] |
||||
|
||||
self._load_detectors() |
||||
|
||||
def _load_detectors(self): |
||||
for name, obj in inspect.getmembers(sys.modules[__name__]): |
||||
if inspect.isclass(obj): |
||||
if issubclass(obj, AbstractDetector) and name != 'AbstractDetector': |
||||
if obj.HIDDEN_DETECTOR: |
||||
continue |
||||
if name in self.detectors: |
||||
raise Exception('Detector name collision: {}'.format(name)) |
||||
self.detectors[name] = obj |
||||
if obj.CLASSIFICATION == DetectorClassification.LOW: |
||||
self.low.append(name) |
||||
elif obj.CLASSIFICATION == DetectorClassification.MEDIUM: |
||||
self.medium.append(name) |
||||
elif obj.CLASSIFICATION == DetectorClassification.HIGH: |
||||
self.high.append(name) |
||||
elif obj.CLASSIFICATION == DetectorClassification.CODE_QUALITY: |
||||
self.code_quality.append(name) |
||||
else: |
||||
raise Exception('Unknown classification') |
||||
|
||||
def run_detector(self, slither, name): |
||||
Detector = self.detectors[name] |
||||
instance = Detector(slither, logger_detector) |
||||
return instance.detect() |
@ -1,20 +1,24 @@ |
||||
import abc |
||||
|
||||
|
||||
class IncorrectPrinterInitialization(Exception): |
||||
pass |
||||
|
||||
class AbstractPrinter(object, metaclass=abc.ABCMeta): |
||||
ARGUMENT = '' # run the printer with slither.py --ARGUMENT |
||||
HELP = '' # help information |
||||
|
||||
class AbstractPrinter(metaclass=abc.ABCMeta): |
||||
ARGUMENT = '' # run the printer with slither.py --ARGUMENT |
||||
HELP = '' # help information |
||||
|
||||
def __init__(self, slither, logger): |
||||
self.slither = slither |
||||
self.contracts = slither.contracts |
||||
self.filename = slither.filename |
||||
self.logger = logger |
||||
if self.HELP == '': |
||||
|
||||
if not self.HELP: |
||||
raise IncorrectPrinterInitialization('HELP is not initialized') |
||||
if self.ARGUMENT == '': |
||||
|
||||
if not self.ARGUMENT: |
||||
raise IncorrectPrinterInitialization('ARGUMENT is not initialized') |
||||
|
||||
def info(self, info): |
@ -1,31 +0,0 @@ |
||||
import sys, inspect |
||||
import logging |
||||
|
||||
from slither.printers.abstractPrinter import AbstractPrinter |
||||
|
||||
# Printer must be imported here |
||||
from slither.printers.summary.printerSummary import PrinterSummary |
||||
from slither.printers.summary.printerQuickSummary import PrinterQuickSummary |
||||
from slither.printers.inheritance.printerInheritance import PrinterInheritance |
||||
from slither.printers.functions.authorization import PrinterWrittenVariablesAndAuthorization |
||||
|
||||
logger_printer = logging.getLogger("Printers") |
||||
|
||||
class Printers: |
||||
|
||||
def __init__(self): |
||||
self.printers = {} |
||||
self._load_printers() |
||||
|
||||
def _load_printers(self): |
||||
for name, obj in inspect.getmembers(sys.modules[__name__]): |
||||
if inspect.isclass(obj): |
||||
if issubclass(obj, AbstractPrinter) and name != 'AbstractPrinter': |
||||
if name in self.printers: |
||||
raise Exception('Printer name collision: {}'.format(name)) |
||||
self.printers[name] = obj |
||||
|
||||
def run_printer(self, slither, name): |
||||
Printer = self.printers[name] |
||||
instance = Printer(slither, logger_printer) |
||||
return instance.output(slither.filename) |
Loading…
Reference in new issue