From 262461549d2175b35280886726c4ca888085a968 Mon Sep 17 00:00:00 2001 From: Josh Asplund Date: Wed, 23 May 2018 19:54:00 -0500 Subject: [PATCH] Updates templating for markdown reports --- mythril/analysis/report.py | 34 ++---------------- .../templates/report_as_markdown.jinja2 | 36 +++++++++++++++++++ mythril/interfaces/cli.py | 4 +-- 3 files changed, 41 insertions(+), 33 deletions(-) create mode 100644 mythril/analysis/templates/report_as_markdown.jinja2 diff --git a/mythril/analysis/report.py b/mythril/analysis/report.py index f14c9631..90fcf177 100644 --- a/mythril/analysis/report.py +++ b/mythril/analysis/report.py @@ -61,34 +61,6 @@ class Report: return json.dumps(result) def as_markdown(self): - text = "" - - for key, issue in self.issues.items(): - - 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 + filename = list(self.issues.values())[0].filename + template = Report.environment.get_template('report_as_markdown.jinja2') + return template.render(filename=filename, issues=self.issues, verbose=self.verbose) diff --git a/mythril/analysis/templates/report_as_markdown.jinja2 b/mythril/analysis/templates/report_as_markdown.jinja2 new file mode 100644 index 00000000..3b09cbe0 --- /dev/null +++ b/mythril/analysis/templates/report_as_markdown.jinja2 @@ -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 -%} diff --git a/mythril/interfaces/cli.py b/mythril/interfaces/cli.py index 579772ce..7145a065 100644 --- a/mythril/interfaces/cli.py +++ b/mythril/interfaces/cli.py @@ -202,8 +202,8 @@ def main(): max_depth=args.max_depth) outputs = { 'json': report.as_json(), - 'text': report.as_text() or "The analysis was completed successfully. No issues were detected.", - 'markdown': report.as_markdown() or "The analysis was completed successfully. No issues were detected." + 'text': report.as_text(), + 'markdown': report.as_markdown() } print(outputs[args.outform])