Merge pull request #72 from vdrg/master

Allow for different output formats in truffle projects
pull/62/merge
Bernhard Mueller 7 years ago committed by GitHub
commit 584f075821
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      myth
  2. 17
      mythril/support/truffle.py

@ -149,7 +149,7 @@ elif (args.hash):
if args.truffle: if args.truffle:
try: try:
analyze_truffle_project() analyze_truffle_project(args)
except FileNotFoundError: 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.") print("Build directory not found. Make sure that you start the analysis from the project root, and that 'truffle compile' has executed successfully.")

@ -10,7 +10,7 @@ from mythril.analysis.report import Report
from laser.ethereum import helper from laser.ethereum import helper
def analyze_truffle_project(): def analyze_truffle_project(args):
project_root = os.getcwd() project_root = os.getcwd()
@ -42,8 +42,11 @@ def analyze_truffle_project():
issues = fire_lasers(states) issues = fire_lasers(states)
if not len(issues): if not len(issues):
if (args.outform == 'text' or args.outform == 'markdown'):
print("Analysis result for " + name + ": No issues found.") print("Analysis result for " + name + ": No issues found.")
else:
result = { 'contract': name, 'result': {'success': True, 'error': None, 'issues': []} }
print(json.dumps(result))
else: else:
report = Report() report = Report()
@ -80,4 +83,14 @@ def analyze_truffle_project():
report.append_issue(issue) report.append_issue(issue)
if (args.outform == 'json'):
result = { 'contract': name, 'result': {'success': True, 'error': None, 'issues': list(map(lambda x: x.as_dict(), issues))}}
print(json.dumps(result))
else:
if (args.outform == 'text'):
print("Analysis result for " + name + ":\n" + report.as_text()) print("Analysis result for " + name + ":\n" + report.as_text())
elif (args.outform == 'markdown'):
print("Analysis result for " + name + ":\n" + report.as_markdown())

Loading…
Cancel
Save