From 6e8eb8c0d2a4905c813bfbe1ec62bfb37902a422 Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Fri, 23 Mar 2018 11:43:46 +0700 Subject: [PATCH] Set filename when mapping Solidity code to issues --- myth | 1 + mythril/analysis/report.py | 2 +- mythril/ether/soliditycontract.py | 2 +- mythril/support/signatures.py | 11 +++++++---- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/myth b/myth index 6728c9e1..c09430b2 100755 --- a/myth +++ b/myth @@ -426,6 +426,7 @@ elif (args.graph) or (args.fire_lasers): codeinfo = contract.get_source_info(issue.pc) + issue.filename = codeinfo.filename issue.code = codeinfo.code issue.lineno = codeinfo.lineno diff --git a/mythril/analysis/report.py b/mythril/analysis/report.py index 2c4b580b..2e13b542 100644 --- a/mythril/analysis/report.py +++ b/mythril/analysis/report.py @@ -61,7 +61,7 @@ class Report: text += issue.description + "\n--------------------\n" if issue.filename and issue.lineno: - text += "In file: " + issue.filename + ":" + str(issue.lineno) + text += "In file: " + issue.filename + ":" + str(issue.lineno) if issue.code: text += "\n\n" + issue.code + "\n\n--------------------\n" diff --git a/mythril/ether/soliditycontract.py b/mythril/ether/soliditycontract.py index 705665cc..180f875a 100644 --- a/mythril/ether/soliditycontract.py +++ b/mythril/ether/soliditycontract.py @@ -106,4 +106,4 @@ class SolidityContract(ETHContract): code = solidity_file.data[offset:offset + length] lineno = self.mappings[index].lineno - return SourceCodeInfo(filename, lineno, code) \ No newline at end of file + return SourceCodeInfo(filename, lineno, code) diff --git a/mythril/support/signatures.py b/mythril/support/signatures.py index 08037fa8..11a1e3f6 100644 --- a/mythril/support/signatures.py +++ b/mythril/support/signatures.py @@ -1,20 +1,21 @@ import re from ethereum import utils + def add_signatures_from_file(file, sigs={}): funcs = [] with open(file, encoding="utf-8") as f: - for line in f: - m = re.search(r'function\s+(.*\))', line) + code = f.read() - if m: - funcs.append(m.group(1)) + funcs = re.findall(r'function[\s]+(.*?\))', code, re.DOTALL) for f in funcs: + f = re.sub(r'[\n]', '', f) + m = re.search(r'^([A-Za-z0-9_]+)', f) if (m): @@ -38,4 +39,6 @@ def add_signatures_from_file(file, sigs={}): typelist = ",".join(types) signature += "(" + typelist + ")" + signature = re.sub(r'\s', '', signature) + sigs["0x" + utils.sha3(signature)[:4].hex()] = signature