From f5f0ed0e759654cb4d4f1ef6119356872570b6fd Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Mon, 15 Jul 2019 00:02:40 +0200 Subject: [PATCH] Add function names to report output --- mythril/analysis/report.py | 22 +++++++++++++++++++ .../templates/report_as_markdown.jinja2 | 2 +- .../analysis/templates/report_as_text.jinja2 | 2 +- mythril/disassembler/disassembly.py | 6 ++--- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/mythril/analysis/report.py b/mythril/analysis/report.py index 7491b614..7411d6fa 100644 --- a/mythril/analysis/report.py +++ b/mythril/analysis/report.py @@ -11,6 +11,7 @@ from mythril.analysis.swc_data import SWC_TO_TITLE from mythril.support.source_support import Source from mythril.support.start_time import StartTime from mythril.support.support_utils import get_code_hash +from mythril.support.signatures import SignatureDB from time import time log = logging.getLogger(__name__) @@ -151,6 +152,26 @@ class Issue: else: self.source_mapping = self.address + def resolve_function_names(self): + """ Resolves function names for each step """ + + if ( + self.transaction_sequence is None + or "steps" not in self.transaction_sequence + ): + return + + signatures = SignatureDB() + + for step in self.transaction_sequence["steps"]: + _hash = step["input"][:10] + sig = signatures.get(_hash) + + if len(sig) > 0: + step["name"] = sig[0] + else: + step["name"] = "unknown" + class Report: """A report containing the content of multiple issues.""" @@ -187,6 +208,7 @@ class Report: """ m = hashlib.md5() m.update((issue.contract + str(issue.address) + issue.title).encode("utf-8")) + issue.resolve_function_names() self.issues[m.digest()] = issue def as_text(self): diff --git a/mythril/analysis/templates/report_as_markdown.jinja2 b/mythril/analysis/templates/report_as_markdown.jinja2 index 4fd73f84..4583eb26 100644 --- a/mythril/analysis/templates/report_as_markdown.jinja2 +++ b/mythril/analysis/templates/report_as_markdown.jinja2 @@ -32,7 +32,7 @@ In file: {{ issue.filename }}:{{ issue.lineno }} {% if step == issue.tx_sequence.steps[0] and step.input != "0x" and step.origin == "0xaffeaffeaffeaffeaffeaffeaffeaffeaffeaffe" %} Caller: [CREATOR], data: [CONTRACT CREATION], value: {{ step.value }} {% else %} -Caller: {% if step.origin == "0xaffeaffeaffeaffeaffeaffeaffeaffeaffeaffe" %}[CREATOR]{% elif step.origin == "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef" %}[ATTACKER]{% else %}[SOMEGUY]{% endif %}, data: {{ step.input }}, value: {{ step.value }} +Caller: {% if step.origin == "0xaffeaffeaffeaffeaffeaffeaffeaffeaffeaffe" %}[CREATOR]{% elif step.origin == "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef" %}[ATTACKER]{% else %}[SOMEGUY]{% endif %}, function: {{ step.name }}, txdata: {{ step.input }}, value: {{ step.value }} {% endif %} {% endfor %} {% endif %} diff --git a/mythril/analysis/templates/report_as_text.jinja2 b/mythril/analysis/templates/report_as_text.jinja2 index dd70bb45..d7b84355 100644 --- a/mythril/analysis/templates/report_as_text.jinja2 +++ b/mythril/analysis/templates/report_as_text.jinja2 @@ -25,7 +25,7 @@ Transaction Sequence: {% if step == issue.tx_sequence.steps[0] and step.input != "0x" and step.origin == "0xaffeaffeaffeaffeaffeaffeaffeaffeaffeaffe" %} Caller: [CREATOR], data: [CONTRACT CREATION], value: {{ step.value }} {% else %} -Caller: {% if step.origin == "0xaffeaffeaffeaffeaffeaffeaffeaffeaffeaffe" %}[CREATOR]{% elif step.origin == "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef" %}[ATTACKER]{% else %}[SOMEGUY]{% endif %}, data: {{ step.input }}, value: {{ step.value }} +Caller: {% if step.origin == "0xaffeaffeaffeaffeaffeaffeaffeaffeaffeaffe" %}[CREATOR]{% elif step.origin == "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef" %}[ATTACKER]{% else %}[SOMEGUY]{% endif %}, function: {{ step.name }}, txdata: {{ step.input }}, value: {{ step.value }} {% endif %} {% endfor %} {% endif %} diff --git a/mythril/disassembler/disassembly.py b/mythril/disassembler/disassembly.py index 595b2583..d51927a1 100644 --- a/mythril/disassembler/disassembly.py +++ b/mythril/disassembler/disassembly.py @@ -84,10 +84,8 @@ def get_function_info( # Append with missing 0s at the beginning function_hash = "0x" + instruction_list[index]["argument"][2:].rjust(8, "0") function_names = signature_database.get(function_hash) - if len(function_names) > 1: - # In this case there was an ambiguous result - function_name = "[{}] (ambiguous)".format(", ".join(function_names)) - elif len(function_names) == 1: + + if len(function_names) > 0: function_name = function_names[0] else: function_name = "_function_" + function_hash