Rename interactive-mode to triage-mode

Improve triage input robustness
pull/172/head
Josselin 6 years ago
parent 018eb8f7c0
commit 8298c11bc8
  1. 12
      slither/__main__.py
  2. 16
      slither/detectors/abstract_detector.py
  3. 1
      slither/detectors/examples/backdoor.py
  4. 10
      slither/slither.py

@ -49,7 +49,7 @@ def process(filename, args, detector_classes, printer_classes):
solc_arguments=args.solc_args, solc_arguments=args.solc_args,
ast_format=ast, ast_format=ast,
filter_paths=parse_filter_paths(args), filter_paths=parse_filter_paths(args),
interactive_mode=args.interactive_mode) triage_mode=args.triage_mode)
return _process(slither, detector_classes, printer_classes) return _process(slither, detector_classes, printer_classes)
@ -107,7 +107,7 @@ def process_truffle(dirname, args, detector_classes, printer_classes):
solc_arguments=args.solc_args, solc_arguments=args.solc_args,
is_truffle=True, is_truffle=True,
filter_paths=parse_filter_paths(args), filter_paths=parse_filter_paths(args),
interactive_mode=args.interactive_mode) triage_mode=args.triage_mode)
return _process(slither, detector_classes, printer_classes) return _process(slither, detector_classes, printer_classes)
@ -125,7 +125,7 @@ def process_files(filenames, args, detector_classes, printer_classes):
disable_solc_warnings=args.disable_solc_warnings, disable_solc_warnings=args.disable_solc_warnings,
solc_arguments=args.solc_args, solc_arguments=args.solc_args,
filter_paths=parse_filter_paths(args), filter_paths=parse_filter_paths(args),
interactive_mode=args.interactive_mode) triage_mode=args.triage_mode)
return _process(slither, detector_classes, printer_classes) return _process(slither, detector_classes, printer_classes)
@ -399,10 +399,10 @@ def parse_args(detector_classes, printer_classes):
dest='ignore_truffle_compile', dest='ignore_truffle_compile',
default=defaults_flag_in_config['ignore_truffle_compile']) default=defaults_flag_in_config['ignore_truffle_compile'])
group_misc.add_argument('--interactive-mode', group_misc.add_argument('--triage-mode',
help='Run interactive mode (save results in slither.db.json)', help='Run triage mode (save results in slither.db.json)',
action='store_true', action='store_true',
dest='interactive_mode', dest='triage_mode',
default=False) default=False)
group_misc.add_argument('--config-file', group_misc.add_argument('--config-file',

@ -108,23 +108,29 @@ class AbstractDetector(metaclass=abc.ABCMeta):
if self.logger: if self.logger:
info = '\n' info = '\n'
for idx, result in enumerate(results): for idx, result in enumerate(results):
if self.slither.interactive_mode: if self.slither.triage_mode:
info += '{}: '.format(idx) info += '{}: '.format(idx)
info += result['description'] info += result['description']
info += 'Reference: {}'.format(self.WIKI) info += 'Reference: {}'.format(self.WIKI)
self._log(info) self._log(info)
if results and self.slither.interactive_mode: if results and self.slither.triage_mode:
not_well_formed = True while True:
while not_well_formed: indexes = input('Results to hide during next runs: "0,1,..." or "All" (enter to not hide results): '.format(len(results)))
indexes = input('Results to hide "0,1,..." or "All" (enter to not hide results): '.format(len(results)))
if indexes == 'All': if indexes == 'All':
self.slither.save_results_to_hide(results) self.slither.save_results_to_hide(results)
return [] return []
if indexes == '': if indexes == '':
return results return results
if indexes.startswith('['):
indexes = indexes[1:]
if indexes.endswith(']'):
indexes = indexes[:-1]
try:
indexes = [int(i) for i in indexes.split(',')] indexes = [int(i) for i in indexes.split(',')]
self.slither.save_results_to_hide([r for (idx, r) in enumerate(results) if idx in indexes]) self.slither.save_results_to_hide([r for (idx, r) in enumerate(results) if idx in indexes])
return [r for (idx, r) in enumerate(results) if idx not in indexes] return [r for (idx, r) in enumerate(results) if idx not in indexes]
except ValueError:
self.logger.error(yellow('Malformed input. Example of valid input: 0,1,2,3'))
return results return results

@ -33,5 +33,4 @@ class Backdoor(AbstractDetector):
self.add_function_to_json(f, json) self.add_function_to_json(f, json)
results.append(json) results.append(json)
return results return results

@ -30,7 +30,7 @@ class Slither(SlitherSolc):
ast_format (str): ast format (default '--ast-compact-json') ast_format (str): ast format (default '--ast-compact-json')
is_truffle (bool): is a truffle directory (default false) is_truffle (bool): is a truffle directory (default false)
filter_paths (list(str)): list of path to filter (default []) filter_paths (list(str)): list of path to filter (default [])
interactive_mode (bool): if true, switch to interactive mode (default false) triage_mode (bool): if true, switch to triage mode (default false)
''' '''
is_truffle = kwargs.get('is_truffle', False) is_truffle = kwargs.get('is_truffle', False)
@ -52,8 +52,8 @@ class Slither(SlitherSolc):
for p in filter_paths: for p in filter_paths:
self.add_path_to_filter(p) self.add_path_to_filter(p)
interactive_mode = kwargs.get('interactive_mode', False) triage_mode = kwargs.get('triage_mode', False)
self._interactive_mode = interactive_mode self._triage_mode = triage_mode
self._analyze_contracts() self._analyze_contracts()
@ -217,5 +217,5 @@ class Slither(SlitherSolc):
return stdout return stdout
@property @property
def interactive_mode(self): def triage_mode(self):
return self._interactive_mode return self._triage_mode

Loading…
Cancel
Save