Modify loop detection to trigger after >2 iterations

pull/1125/head
Bernhard Mueller 5 years ago
parent 02217dede7
commit 1125c34ddb
  1. 18
      mythril/analysis/modules/dos.py

@ -19,7 +19,7 @@ class VisitsAnnotation(StateAnnotation):
def __init__(self) -> None: def __init__(self) -> None:
self.loop_start = None self.loop_start = None
self.jump_targets = [] # type: List[int] self.jump_targets = {} # type: Dict[int]
def __copy__(self): def __copy__(self):
result = VisitsAnnotation() result = VisitsAnnotation()
@ -76,13 +76,19 @@ class DOS(DetectionModule):
annotation = annotations[0] annotation = annotations[0]
if opcode in ["JUMP", "JUMPI"]: if opcode in ["JUMP", "JUMPI"]:
if annotation.loop_start is not None:
return []
target = util.get_concrete_int(state.mstate.stack[-1]) target = util.get_concrete_int(state.mstate.stack[-1])
if annotation.loop_start is None: if target in annotation.jump_targets:
if target in annotation.jump_targets: annotation.jump_targets[target] += 1
annotation.loop_start = address else:
else: annotation.jump_targets[target] = 1
annotation.jump_targets.append(target)
if annotation.jump_targets[target] > 2:
annotation.loop_start = target
elif annotation.loop_start is not None: elif annotation.loop_start is not None:

Loading…
Cancel
Save