Add exception handling

pull/53/head
Bernhard Mueller 7 years ago
parent 975062c395
commit 379fd8c19e
  1. 5
      myth
  2. 80
      mythril/support/truffle.py

@ -142,7 +142,10 @@ elif (args.hash):
if args.truffle:
analyze_truffle_project()
try:
analyze_truffle_project()
except FileNotFoundError:
print("Build directory not found. Make sure that you start the analysis from the project root, and that 'truffle compile' has executed successfully.")
sys.exit()

@ -21,68 +21,60 @@ def analyze_truffle_project():
with open(os.path.join(build_dir, contract_file)) as cf:
contractdata = json.load(cf)
name = contractdata['contractName']
bytecode = contractdata['deployedBytecode']
name = contractdata['contractName']
bytecode = contractdata['deployedBytecode']
if (len(bytecode) < 4):
continue
if (len(bytecode) < 4):
continue
ethcontract= ETHContract(bytecode, name=name, address = util.get_indexed_address(0))
ethcontract= ETHContract(bytecode, name=name, address = util.get_indexed_address(0))
contracts = [ethcontract]
contracts = [ethcontract]
states = StateSpace(contracts, max_depth = 10)
report = fire_lasers(states)
states = StateSpace(contracts, max_depth = 10)
report = fire_lasers(states)
# augment with source code
# augment with source code
disassembly = ethcontract.get_disassembly()
source = contractdata['source']
disassembly = ethcontract.get_disassembly()
source = contractdata['source']
deployedSourceMap = contractdata['deployedSourceMap'].split(";")
deployedSourceMap = contractdata['deployedSourceMap'].split(";")
mappings = []
i = 0
mappings = []
i = 0
while(i < len(deployedSourceMap)):
while(i < len(deployedSourceMap)):
# print("INDEX: " + str(i))
# print(deployedSourceMap[i])
m = re.search(r"^(\d+):*(\d+)", deployedSourceMap[i])
m = re.search(r"^(\d+):*(\d+)", deployedSourceMap[i])
if (m):
offset = m.group(1)
length = m.group(2)
else:
m = re.search(r"^:(\d+)", deployedSourceMap[i])
if m:
length = m.group(1)
# print("APPEND: " + str((offset, length)))
if (m):
offset = m.group(1)
length = m.group(2)
else:
m = re.search(r"^:(\d+)", deployedSourceMap[i])
mappings.append((int(offset), int(length)))
if m:
length = m.group(1)
i += 1
mappings.append((int(offset), int(length)))
for key, issue in report.issues.items():
i += 1
index = helper.get_instruction_index(disassembly.instruction_list, issue.pc)
for key, issue in report.issues.items():
# print("INDEX: " + str(index))
# print(mappings[index])
index = helper.get_instruction_index(disassembly.instruction_list, issue.pc)
if index:
issue.code_start = mappings[index][0]
issue.code_length = mappings[index][1]
issue.code = source[mappings[index][0]: mappings[index][0] + mappings[index][1]]
if index:
issue.code_start = mappings[index][0]
issue.code_length = mappings[index][1]
issue.code = source[mappings[index][0]: mappings[index][0] + mappings[index][1]]
if len(report.issues):
print("Analysis result for " + name + ":\n" + report.as_text())
else:
print("Analysis result for " + name + ": No issues found.")
if len(report.issues):
print("Analysis result for " + name + ":\n" + report.as_text())
else:
print("Analysis result for " + name + ": No issues found.")

Loading…
Cancel
Save