<commit_before>#!/usr/bin/env python
from cortexutils.analyzer import Analyzer
import io
import os
import hashlib


class VirusshareAnalyzer(Analyzer):
    """
    This analyzer allows searching through a previously downloaded hash list of virusshare. If the hash has not the
    length of 32 characters (md5), search is skipped and the ``isonvs`` report parameter is set to ``unknown``. In the
    report, a button is placed for redirecting to virusshare.com.
    As parameter this analyzer takes ``path`` which contains the path (obviously...) to the virusshare hash lists. To be
    able to downloads the lists in an easier way, ``download_hashes.py`` was provided. More info in the documentation.
    """
    def __init__(self):
        Analyzer.__init__(self)
        self.path = self.getParam('config.path', None, 'No path to virusshare hash directory given.')
        if not os.path.isdir(self.path):
            self.error('Given path is not a directory.')
        self.filelist = os.listdir(self.path)

    def summary(self, raw):
        taxonomies = []
        level = "safe"
        namespace = "Virusshare"
        predicate = "Search"
        value = "\"Unknown\""

        if raw["isonvs"]:
            if raw["isonvs"] == "Unknown":
                value = "\"Not MD5\""
                level = "suspicious"
            else:
                value = "\"Found\""
                level = "malicious"
        else:
            value = "\"Not Found\""

        taxonomies.append(self.build_taxonomy(level, namespace, predicate, value))
        return {'taxonomies': taxonomies}

    def run(self):
        searchhash = ''
        if self.data_type == 'hash':
            searchhash = self.getData()
            if len(searchhash) != 32:
                self.report({'isonvs': 'Unknown',
                             'hash': searchhash})
        elif self.data_type == 'file':
            filepath = self.getParam('file')
            hasher = hashlib.md5()
            with io.open(filepath, mode='rb') as afile:
                for chunk in iter(lambda: afile.read(65536), b''):
                    hasher.update(chunk)<commit_msg>Implemented better fix so the templates are not affected. :)<commit_after>#!/usr/bin/env python
from cortexutils.analyzer import Analyzer
import io
import os
import hashlib


class VirusshareAnalyzer(Analyzer):
    """
    This analyzer allows searching through a previously downloaded hash list of virusshare. If the hash has not the
    length of 32 characters (md5), search is skipped and the ``isonvs`` report parameter is set to ``unknown``. In the
    report, a button is placed for redirecting to virusshare.com.
    As parameter this analyzer takes ``path`` which contains the path (obviously...) to the virusshare hash lists. To be
    able to downloads the lists in an easier way, ``download_hashes.py`` was provided. More info in the documentation.
    """
    def __init__(self):
        Analyzer.__init__(self)
        self.path = self.getParam('config.path', None, 'No path to virusshare hash directory given.')
        if not os.path.isdir(self.path):
            self.error('Given path is not a directory.')
        self.filelist = os.listdir(self.path)

    def summary(self, raw):
        taxonomies = []
        level = "safe"
        namespace = "Virusshare"
        predicate = "Search"
        value = "\"Unknown\""

        if raw["isonvs"]:
            if raw["isonvs"] == "unknown":
                value = "\"Not MD5\""
                level = "suspicious"
            else:
                value = "\"Found\""
                level = "malicious"
        else:
            value = "\"Not Found\""

        taxonomies.append(self.build_taxonomy(level, namespace, predicate, value))
        return {'taxonomies': taxonomies}

    def run(self):
        searchhash = ''
        if self.data_type == 'hash':
            searchhash = self.getData()
            if len(searchhash) != 32:
                self.report({'isonvs': 'unknown',
                             'hash': searchhash})
        elif self.data_type == 'file':
            filepath = self.getParam('file')
            hasher = hashlib.md5()
            with io.open(filepath, mode='rb') as afile:
                for chunk in iter(lambda: afile.read(65536), b''):
                    hasher.update(chunk)
{'fraction_non_alphanumeric': 0.11193168705285023, 'fraction_numerical': 0.0055388876067389795, 'mean_word_length': 2.124729632299928, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4208556', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1164, 'n_words': 390}