Package modules :: Package processing :: Module strings
[hide private]
[frames] | no frames]

Source Code for Module modules.processing.strings

 1  # Copyright (C) 2010-2014 Cuckoo Foundation. 
 2  # This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org 
 3  # See the file 'docs/LICENSE' for copying permission. 
 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   
11 -class Strings(Processing):
12 """Extract strings from analyzed file.""" 13
14 - def run(self):
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