<commit_before># Copyright (C) 2010-2015 Cuckoo Foundation.
# This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org
# See the file 'docs/LICENSE' for copying permission.

import os
import subprocess

from lib.cuckoo.common.abstracts import Processing

class Screenshots(Processing):
    """Screenshot files analysis."""

    def run(self):
        """Run analysis.
        @return: list of dropped files with related information.
        """

        self.key = "screenshots"
        screenshots = []

        if os.path.exists(self.shots_path):
            # Walk through the files and select the JPGs.
            for shot_file in sorted(os.listdir(self.shots_path)):
                if not shot_file.endswith(".jpg"):
                    continue

                # Get path to the screenshot.
                shot_path = os.path.join(self.shots_path, shot_file)
                # Initialize the entry for the results dict.
                shot_entry = dict(path=shot_path, ocr="")

                try:
                    # Try to launch tesseract.
                    ocr = subprocess.Popen(["tesseract", shot_path, "stdout"],
                        stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                except OSError:
                    # Tesseract is not installed.
                    pass
                else:
                    shot_entry["ocr"] = ocr.stdout.read()

                # Append entry to list of screenshots.<commit_msg>Fixed comment<commit_after># Copyright (C) 2010-2015 Cuckoo Foundation.
# This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org
# See the file 'docs/LICENSE' for copying permission.

import os
import subprocess

from lib.cuckoo.common.abstracts import Processing

class Screenshots(Processing):
    """Screenshot files analysis."""

    def run(self):
        """Run analysis.
        @return: list of screenshots with OCR content.
        """

        self.key = "screenshots"
        screenshots = []

        if os.path.exists(self.shots_path):
            # Walk through the files and select the JPGs.
            for shot_file in sorted(os.listdir(self.shots_path)):
                if not shot_file.endswith(".jpg"):
                    continue

                # Get path to the screenshot.
                shot_path = os.path.join(self.shots_path, shot_file)
                # Initialize the entry for the results dict.
                shot_entry = dict(path=shot_path, ocr="")

                try:
                    # Try to launch tesseract.
                    ocr = subprocess.Popen(["tesseract", shot_path, "stdout"],
                        stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                except OSError:
                    # Tesseract is not installed.
                    pass
                else:
                    shot_entry["ocr"] = ocr.stdout.read()

                # Append entry to list of screenshots.
{'fraction_non_alphanumeric': 0.08861622358554874, 'fraction_numerical': 0.0054533060668029995, 'mean_word_length': 1.705069124423963, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1536395', 'n_tokens_mistral': 841, 'n_tokens_neox': 767, 'n_words': 223}