1
2
3
4
5 import os
6 import json
7 import codecs
8
9 from lib.cuckoo.common.abstracts import Report
10 from lib.cuckoo.common.exceptions import CuckooReportError
11
13 """Saves analysis results in JSON format."""
14
15 - def run(self, results):
16 """Writes report.
17 @param results: Cuckoo results dict.
18 @raise CuckooReportError: if fails to write report.
19 """
20 indent = self.options.get("indent", 4)
21 encoding = self.options.get("encoding", "utf-8")
22
23 try:
24 path = os.path.join(self.reports_path, "report.json")
25 with codecs.open(path, "w", "utf-8") as report:
26 json.dump(results, report, sort_keys=False,
27 indent=int(indent), encoding=encoding)
28 except (UnicodeError, TypeError, IOError) as e:
29 raise CuckooReportError("Failed to generate JSON report: %s" % e)
30