Calculate and output line numbers

pull/72/head
Bernhard Mueller 7 years ago
parent ed2baf9bd2
commit 5a9a9b300b
  1. 1
      myth
  2. 3
      mythril/analysis/report.py
  3. 9
      mythril/ether/soliditycontract.py

@ -395,6 +395,7 @@ elif (args.graph) or (args.fire_lasers):
length = contract.mappings[index].length
issue.code = solidity_file.data[offset:offset+length]
issue.lineno = contract.mappings[index].lineno
for i in range(0, len(issues)):
report.append_issue(issues[i])

@ -14,6 +14,7 @@ class Issue:
self.debug = debug
self.filename = None
self.code = None
self.lineno = None
def as_dict(self):
@ -51,7 +52,7 @@ class Report:
text += issue.description + "\n--------------------\n"
if issue.filename:
text += "In file: " + issue.filename + "\n"
text += "In file: " + issue.filename + ":" + str(issue.lineno)
if issue.code:
text += "\n\n" + issue.code + "\n\n--------------------\n"

@ -4,10 +4,12 @@ from mythril.exceptions import NoContractFoundError
class SourceMapping:
def __init__(self, solidity_file_idx, offset, length):
def __init__(self, solidity_file_idx, offset, length, lineno):
self.solidity_file_idx = solidity_file_idx
self.offset = offset
self.length = length
self.lineno = lineno
class SolidityFile:
@ -15,6 +17,7 @@ class SolidityFile:
self.filename = filename
self.data = data
class SolidityContract(ETHContract):
def __init__(self, input_file, contract_name = None):
@ -60,6 +63,8 @@ class SolidityContract(ETHContract):
if len(mapping) > 2 and len(mapping[2]) > 0:
idx = int(mapping[2])
self.mappings.append(SourceMapping(idx, offset, length))
lineno = self.solidity_files[idx].data[0:offset].count('\n') + 1
self.mappings.append(SourceMapping(idx, offset, length, lineno))
super().__init__(self.code, self.creation_code, name)

Loading…
Cancel
Save