|
|
|
@ -1,12 +1,35 @@ |
|
|
|
|
from mythril.analysis.report import Report |
|
|
|
|
from collections import defaultdict |
|
|
|
|
from ethereum.opcodes import opcodes |
|
|
|
|
from mythril.analysis import modules |
|
|
|
|
import pkgutil |
|
|
|
|
import logging |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_detection_modules(entrypoint, except_modules=None): |
|
|
|
|
except_modules = [] if except_modules is None else except_modules |
|
|
|
|
except_modules.append("base") # always exclude base class file |
|
|
|
|
OPCODE_LIST = [c[0] for _, c in opcodes.items()] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_detection_module_hooks(): |
|
|
|
|
hook_dict = defaultdict(list) |
|
|
|
|
_modules = get_detection_modules(entrypoint="callback") |
|
|
|
|
for module in _modules: |
|
|
|
|
for op_code in map(lambda x: x.upper(), module.detector.hooks): |
|
|
|
|
if op_code in OPCODE_LIST: |
|
|
|
|
hook_dict[op_code].append(module.detector.execute) |
|
|
|
|
elif op_code.endswith("*"): |
|
|
|
|
to_register = filter(lambda x: x.startswith(op_code[:-1]), OPCODE_LIST) |
|
|
|
|
for actual_hook in to_register: |
|
|
|
|
hook_dict[actual_hook].append(module.detector.execute) |
|
|
|
|
else: |
|
|
|
|
logging.error( |
|
|
|
|
"Encountered invalid hook opcode %s in module %s", |
|
|
|
|
op_code, |
|
|
|
|
module.detector.name, |
|
|
|
|
) |
|
|
|
|
return dict(hook_dict) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_detection_modules(entrypoint, except_modules=()): |
|
|
|
|
except_modules = list(except_modules) + ["base"] |
|
|
|
|
_modules = [] |
|
|
|
|
|
|
|
|
|
for loader, name, _ in pkgutil.walk_packages(modules.__path__): |
|
|
|
@ -21,7 +44,7 @@ def get_detection_modules(entrypoint, except_modules=None): |
|
|
|
|
return _modules |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def fire_lasers(statespace, module_names=None): |
|
|
|
|
def fire_lasers(statespace, module_names=()): |
|
|
|
|
logging.info("Starting analysis") |
|
|
|
|
|
|
|
|
|
issues = [] |
|
|
|
|