def check(self, file):
        """
        Checks a given file against all available yara rules
        :param file: Path to file
        :type file:str
        :returns: Python list with matched rules info
        :rtype: list
        """
        result = []
        all_matches = []
        for filerules in os.listdir(self.rulepaths):
            try:
                rule = yara.compile(os.path.join(self.rulepaths, filerules))
            except yara.SyntaxError:
                continue
            matches = rule.match(file)
            if len(matches) > 0:
                for rulem in matches:
                    rule_family = "_".join([x for x in rulem.rule.replace("_", ".", 1).split("_")[:-1]])
                    if rule_family not in all_matches:
                        all_matches.append(rule_family)
        for rule_family in all_matches:
            rules_info_txt = requests.get('{}/family/{}'.format(self.baseurl, rule_family),
                                          auth=HTTPBasicAuth(self.user, self.pwd))
            rules_info_json = json.loads(rules_info_txt.text)
            result.append({
                'family': rule_family,
                'common_name': rules_info_json['common_name'],
                'description': rules_info_json['description'],
                'attribution': rules_info_json['attribution'],
                'alt_names': rules_info_json['alt_names'],
                'urls': rules_info_json['urls']
            })

        return result
def check ( self , file ) : result = [ ] all_matches = [ ] for filerules in os . listdir ( self . rulepaths ) : try : rule = yara . compile ( os . path . join ( self . rulepaths , filerules ) ) except yara . SyntaxError : continue matches = rule . match ( file ) if len ( matches ) > 0 : for rulem in matches : rule_family = "_" . join ( [ x for x in rulem . rule . replace ( "_" , "." , 1 ) . split ( "_" ) [ : - 1 ] ] ) if rule_family not in all_matches : all_matches . append ( rule_family ) for rule_family in all_matches : rules_info_txt = requests . get ( '{}/family/{}' . format ( self . baseurl , rule_family ) , auth = HTTPBasicAuth ( self . user , self . pwd ) ) rules_info_json = json . loads ( rules_info_txt . text ) result . append ( { 'family' : rule_family , 'common_name' : rules_info_json [ 'common_name' ] , 'description' : rules_info_json [ 'description' ] , 'attribution' : rules_info_json [ 'attribution' ] , 'alt_names' : rules_info_json [ 'alt_names' ] , 'urls' : rules_info_json [ 'urls' ] } ) return result
Checks a given file against all available yara rules
        :param file: Path to file
        :type file:str
        :returns: Python list with matched rules info
        :rtype: list