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 try:
21 path = os.path.join(self.reports_path, "report.json")
22 report = codecs.open(path, "w", "utf-8")
23 json.dump(results, report, sort_keys=False, indent=4)
24 report.close()
25 except (UnicodeError, TypeError, IOError) as e:
26 raise CuckooReportError("Failed to generate JSON report: %s" % e)
27