<commit_before># Copyright (C) 2013-2014 Claudio "nex" Guarnieri.
# This file is part of Viper - https://github.com/botherder/viper
# See the file 'LICENSE' for copying permission.

import os
import getopt

from viper.common.out import *
from viper.common.abstracts import Module
from viper.core.database import Database
from viper.core.session import __session__
from viper.core.storage import get_sample_path

try:
    import yara
    HAVE_YARA = True
except ImportError:
    HAVE_YARA = False

class YaraScan(Module):
    cmd = 'yara'
    description = 'Run Yara scan'

    def scan(self):
        def usage():
            print("usage: yara scan [-a]")

        def help():
            usage()
            print("")
            print("Options:")
            print("\t--help (-h)\tShow this help message")
            print("\t--rule (-r)\tSpecify a ruleset file path (default will run data/yara/index.yara)")
            print("\t--all (-a)\tScan all stored files (default if no session is open)")
            print("")

        rule_path = ''
        scan_all = False

        try:
            opts, argv = getopt.getopt(self.args[1:], 'r:a', ['rule=', 'all'])
        except getopt.GetoptError as e:
            print(e)
            return

        for opt, value in opts:
            if opt in ('-h', '--help'):
                help()
                return
            elif opt in ('-r', '--rule'):
                rule_path = value
            elif opt in ('-a', '--all'):
                scan_all = True

        # If no custom ruleset is specified, we use the default one.
        if not rule_path:
            rule_path = 'data/yara/index.yara'

        # Check if the selected ruleset actually exists.
        if not os.path.exists(rule_path):
            print_error("No valid Yara ruleset at {0}".format(rule_path))
            return

        # Compile all rules from given ruleset.
        rules = yara.compile(rule_path)
        files = []

        # If there is a session open and the user didn't specifically
        # request to scan the full repository, we just add the currently
        # opened file's path.
        if __session__.is_set() and not scan_all:<commit_msg>Forgot help option in getopt parsing for yara module<commit_after># Copyright (C) 2013-2014 Claudio "nex" Guarnieri.
# This file is part of Viper - https://github.com/botherder/viper
# See the file 'LICENSE' for copying permission.

import os
import getopt

from viper.common.out import *
from viper.common.abstracts import Module
from viper.core.database import Database
from viper.core.session import __session__
from viper.core.storage import get_sample_path

try:
    import yara
    HAVE_YARA = True
except ImportError:
    HAVE_YARA = False

class YaraScan(Module):
    cmd = 'yara'
    description = 'Run Yara scan'

    def scan(self):
        def usage():
            print("usage: yara scan [-a]")

        def help():
            usage()
            print("")
            print("Options:")
            print("\t--help (-h)\tShow this help message")
            print("\t--rule (-r)\tSpecify a ruleset file path (default will run data/yara/index.yara)")
            print("\t--all (-a)\tScan all stored files (default if no session is open)")
            print("")

        rule_path = ''
        scan_all = False

        try:
            opts, argv = getopt.getopt(self.args[1:], 'hr:a', ['help', 'rule=', 'all'])
        except getopt.GetoptError as e:
            print(e)
            return

        for opt, value in opts:
            if opt in ('-h', '--help'):
                help()
                return
            elif opt in ('-r', '--rule'):
                rule_path = value
            elif opt in ('-a', '--all'):
                scan_all = True

        # If no custom ruleset is specified, we use the default one.
        if not rule_path:
            rule_path = 'data/yara/index.yara'

        # Check if the selected ruleset actually exists.
        if not os.path.exists(rule_path):
            print_error("No valid Yara ruleset at {0}".format(rule_path))
            return

        # Compile all rules from given ruleset.
        rules = yara.compile(rule_path)
        files = []

        # If there is a session open and the user didn't specifically
        # request to scan the full repository, we just add the currently
        # opened file's path.
        if __session__.is_set() and not scan_all:
{'fraction_non_alphanumeric': 0.10622462787550745, 'fraction_numerical': 0.0045105999097880016, 'mean_word_length': 1.9409814323607426, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '7107356', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1258, 'n_words': 438}