Updates templating for markdown reports

pull/206/head
Josh Asplund 7 years ago
parent aaf0b81091
commit 262461549d
  1. 34
      mythril/analysis/report.py
  2. 36
      mythril/analysis/templates/report_as_markdown.jinja2
  3. 4
      mythril/interfaces/cli.py

@ -61,34 +61,6 @@ class Report:
return json.dumps(result) return json.dumps(result)
def as_markdown(self): def as_markdown(self):
text = "" filename = list(self.issues.values())[0].filename
template = Report.environment.get_template('report_as_markdown.jinja2')
for key, issue in self.issues.items(): return template.render(filename=filename, issues=self.issues, verbose=self.verbose)
if text == "":
if (issue.filename):
text += "# Analysis results for " + issue.filename
text += "\n\n## " + issue.title + "\n\n"
text += "- Type: " + issue.type + "\n"
if len(issue.contract):
text += "- Contract: " + issue.contract + "\n"
else:
text += "- Contract: Unknown\n"
text += "- Function name: `" + issue.function + "`\n"
text += "- PC address: " + str(issue.address) + "\n\n"
text += "### Description\n\n" + issue.description
if issue.filename and issue.lineno:
text += "\nIn *%s:%d*\n" % (issue.filename, issue.lineno)
if issue.code:
text += "\n```\n" + issue.code + "\n```"
if self.verbose and issue.debug:
text += "\n\n### Debugging Information\n" + issue.debug
return text

@ -0,0 +1,36 @@
# Analysis results for {{ filename }}
{%- if issues %}
{% for key, issue in issues.items() %}
## {{ issue.title }}
- Type: {{ issue.type }}
- Contract: {{ issue.contract | default("Unknown") }}
- Function name: `{{ issue.function }}`
- PC address: {{ issue.address }}
### Description
{{ issue.description }}
{% if issue.filename and issue.lineno -%}
In file: {{ issue.filename }}:{{ issue.lineno }}
{%- endif -%}
{%- if issue.code %}
### Code
```
{{ issue.code }}
```
{%- endif -%}
{%- if verbose and issue.debug -%}
--------------------
### Debugging Information:
{{ issue.debug }}
{%- endif -%}
{%- endfor -%}
{%- else -%}
The analysis was completed successfully. No issues were detected.
{%- endif -%}

@ -202,8 +202,8 @@ def main():
max_depth=args.max_depth) max_depth=args.max_depth)
outputs = { outputs = {
'json': report.as_json(), 'json': report.as_json(),
'text': report.as_text() or "The analysis was completed successfully. No issues were detected.", 'text': report.as_text(),
'markdown': report.as_markdown() or "The analysis was completed successfully. No issues were detected." 'markdown': report.as_markdown()
} }
print(outputs[args.outform]) print(outputs[args.outform])

Loading…
Cancel
Save