1
2
3
4
5 import os.path
6 import re
7
8 from lib.cuckoo.common.abstracts import Processing
9 from lib.cuckoo.common.exceptions import CuckooProcessingError
10
12 """Extract strings from analyzed file."""
13
15 """Run extract of printable strings.
16 @return: list of printable strings.
17 """
18 self.key = "strings"
19 strings = []
20
21 if self.task["category"] == "file":
22 if not os.path.exists(self.file_path):
23 raise CuckooProcessingError("Sample file doesn't exist: \"%s\"" % self.file_path)
24
25 try:
26 data = open(self.file_path, "r").read()
27 except (IOError, OSError) as e:
28 raise CuckooProcessingError("Error opening file %s" % e)
29 strings = re.findall("[\x1f-\x7e]{6,}", data)
30 strings += [str(ws.decode("utf-16le")) for ws in re.findall("(?:[\x1f-\x7e][\x00]){6,}", data)]
31
32 return strings
33