1
2
3
4
5
6 import codecs
7 import logging
8 import os
9
10 from lib.cuckoo.common.abstracts import Processing
11 from lib.cuckoo.common.exceptions import CuckooProcessingError
12 from lib.cuckoo.core.database import Database
13
14 log = logging.getLogger(__name__)
15
18 list.__init__(self)
19 self.filepath = filepath
20
22 try:
23 for line in codecs.open(self.filepath, "rb", "utf-8"):
24 yield line
25 except Exception as e:
26 log.info("Error decoding %s: %s", self.filepath, e)
27
29 return bool(os.path.getsize(self.filepath))
30
32 """Analysis debug information."""
33
35 """Run debug analysis.
36 @return: debug information dict.
37 """
38 self.key = "debug"
39 debug = {"log": [], "cuckoo": [], "errors": []}
40
41 if os.path.exists(self.log_path):
42 try:
43 f = codecs.open(self.log_path, "rb", "utf-8")
44 debug["log"] = f.readlines()
45 except ValueError as e:
46 raise CuckooProcessingError("Error decoding %s: %s" %
47 (self.log_path, e))
48 except (IOError, OSError) as e:
49 raise CuckooProcessingError("Error opening %s: %s" %
50 (self.log_path, e))
51
52 if os.path.exists(self.cuckoolog_path):
53 debug["cuckoo"] = Logfile(self.cuckoolog_path)
54
55 for error in Database().view_errors(int(self.task["id"])):
56 debug["errors"].append(error.message)
57
58 if os.path.exists(self.mitmerr_path):
59 mitmerr = open(self.mitmerr_path, "rb").read()
60 if mitmerr:
61 debug["errors"].append(mitmerr)
62
63 return debug
64