modules.processing.strings

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

# Source Code for Module modules.processing.strings

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