Add json output format

pull/59/head
Bernhard Mueller 7 years ago
parent 270bf9cf60
commit 20079b8a6e
  1. 14
      myth
  2. 12
      mythril/analysis/report.py

14
myth

@ -57,6 +57,9 @@ inputs.add_argument('-c', '--code', help='hex-encoded bytecode string ("60606040
inputs.add_argument('-a', '--address', help='pull contract from the blockchain', metavar='CONTRACT_ADDRESS')
inputs.add_argument('-l', '--dynld', action='store_true', help='auto-load dependencies from the blockchain')
inputs = parser.add_argument_group('output formats')
inputs.add_argument('-o', '--outform', choices=['text', 'json'], default='text', help='report output format', metavar='<text/json>')
database = parser.add_argument_group('local contracts database')
database.add_argument('--init-db', action='store_true', help='initialize the contract database')
database.add_argument('-s', '--search', help='search the contract database', metavar='EXPRESSION')
@ -366,12 +369,13 @@ elif (args.graph) or (args.fire_lasers):
report = fire_lasers(states)
if (len(report.issues)):
print(report.as_text())
if (args.outform == 'text'):
if (len(report.issues)):
print(report.as_text())
else:
print("The analysis was completed successfully. No issues were detected.")
else:
print("The analysis was completed successfully. No issues were detected.")
print(report.as_json())
else:
parser.print_help()

@ -1,4 +1,5 @@
import hashlib
import json
class Issue:
@ -16,7 +17,7 @@ class Issue:
def as_dict(self):
return {'title': self.title, 'description':self.description, 'type': self.type}
return {'title': self.title, 'description':self.description, 'function': self.function, 'type': self.type, 'address': self.pc, 'debug': self.debug}
class Report:
@ -57,3 +58,12 @@ class Report:
text+="\n"
return text
def as_json(self):
issues = []
for key, issue in self.issues.items():
issues.append(issue.as_dict())
return json.dumps(issues)

Loading…
Cancel
Save