|
|
@ -1,5 +1,6 @@ |
|
|
|
import os |
|
|
|
import os |
|
|
|
import re |
|
|
|
import re |
|
|
|
|
|
|
|
import sys |
|
|
|
import json |
|
|
|
import json |
|
|
|
from mythril.ether import util |
|
|
|
from mythril.ether import util |
|
|
|
from mythril.ether.ethcontract import ETHContract |
|
|
|
from mythril.ether.ethcontract import ETHContract |
|
|
@ -14,15 +15,22 @@ def analyze_truffle_project(): |
|
|
|
|
|
|
|
|
|
|
|
build_dir = os.path.join(project_root, "build", "contracts") |
|
|
|
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) |
|
|
|
contractdata = json.load(cf) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
name = contractdata['contractName'] |
|
|
|
name = contractdata['contractName'] |
|
|
|
bytecode = contractdata['deployedBytecode'] |
|
|
|
bytecode = contractdata['deployedBytecode'] |
|
|
|
|
|
|
|
except: |
|
|
|
|
|
|
|
print("Unable to parse contract data. Please use Truffle 4 to compile your project.") |
|
|
|
|
|
|
|
sys.exit() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (len(bytecode) < 4): |
|
|
|
if (len(bytecode) < 4): |
|
|
|
continue |
|
|
|
continue |
|
|
@ -71,7 +79,6 @@ def analyze_truffle_project(): |
|
|
|
issue.code = source[mappings[index][0]: mappings[index][0] + mappings[index][1]] |
|
|
|
issue.code = source[mappings[index][0]: mappings[index][0] + mappings[index][1]] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(report.issues): |
|
|
|
if len(report.issues): |
|
|
|
print("Analysis result for " + name + ":\n" + report.as_text()) |
|
|
|
print("Analysis result for " + name + ":\n" + report.as_text()) |
|
|
|
else: |
|
|
|
else: |
|
|
|