Exit with error if invalid Truffle JSON is encountered

pull/53/head
Bernhard Mueller 7 years ago
parent c116d4a11b
commit e4a6097e67
  1. 15
      mythril/support/truffle.py

@ -1,5 +1,6 @@
import os
import re
import sys
import json
from mythril.ether import util
from mythril.ether.ethcontract import ETHContract
@ -14,15 +15,22 @@ def analyze_truffle_project():
build_dir = os.path.join(project_root, "build", "contracts")
contract_files = os.listdir(build_dir)
files = os.listdir(build_dir)
for contract_file in contract_files:
for filename in files:
with open(os.path.join(build_dir, contract_file)) as cf:
if re.match(r'.*\.json$', filename):
with open(os.path.join(build_dir, filename)) as cf:
contractdata = json.load(cf)
try:
name = contractdata['contractName']
bytecode = contractdata['deployedBytecode']
except:
print("Unable to parse contract data. Please use Truffle 4 to compile your project.")
sys.exit()
if (len(bytecode) < 4):
continue
@ -71,7 +79,6 @@ def analyze_truffle_project():
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:

Loading…
Cancel
Save