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