Allow for different output formats in truffle projects

pull/72/head
vdrg 7 years ago
parent 14bf07769b
commit 6692475e09
  1. 2
      myth
  2. 21
      mythril/support/truffle.py

@ -149,7 +149,7 @@ elif (args.hash):
if args.truffle:
try:
analyze_truffle_project()
analyze_truffle_project(args)
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.")

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

Loading…
Cancel
Save