@@ -58,7 +58,6 @@ def scan(self, data, file, options, expire_at):
5858 self .load_yara_rules (options )
5959 if not self .compiled_yara :
6060 self .flags .append ("no_rules_loaded" )
61- return
6261
6362 # Set the total rules loaded
6463 self .event ["rules_loaded" ] = self .rules_loaded
@@ -79,35 +78,36 @@ def scan(self, data, file, options, expire_at):
7978 self .event ["hex" ] = []
8079
8180 # Match the data against the YARA rules.
82- yara_matches = self .compiled_yara .match (data = data )
83- for match in yara_matches :
84- # Append rule matches and update tags.
85- self .event ["matches" ].append (match .rule )
86- self .event ["tags" ].extend (match .tags )
87-
88- # Extract hex representation if configured to store offsets.
89- if self .store_offset and self .offset_meta_key :
90- if match .meta .get (self .offset_meta_key ):
91- for string_data in match .strings :
92- for instance in string_data .instances :
93- offset = instance .offset
94- matched_string = instance .matched_data
95- self .extract_match_hex (
96- match .rule ,
97- offset ,
98- matched_string ,
99- data ,
100- self .offset_padding ,
101- )
102-
103- # Append meta information if configured to do so.
104- for k , v in match .meta .items ():
105- self .event ["meta" ].append (
106- {"rule" : match .rule , "identifier" : k , "value" : v }
107- )
81+ if self .compiled_yara :
82+ yara_matches = self .compiled_yara .match (data = data )
83+ for match in yara_matches :
84+ # Append rule matches and update tags.
85+ self .event ["matches" ].append (match .rule )
86+ self .event ["tags" ].extend (match .tags )
87+
88+ # Extract hex representation if configured to store offsets.
89+ if self .store_offset and self .offset_meta_key :
90+ if match .meta .get (self .offset_meta_key ):
91+ for string_data in match .strings :
92+ for instance in string_data .instances :
93+ offset = instance .offset
94+ matched_string = instance .matched_data
95+ self .extract_match_hex (
96+ match .rule ,
97+ offset ,
98+ matched_string ,
99+ data ,
100+ self .offset_padding ,
101+ )
102+
103+ # Append meta information if configured to do so.
104+ for k , v in match .meta .items ():
105+ self .event ["meta" ].append (
106+ {"rule" : match .rule , "identifier" : k , "value" : v }
107+ )
108108
109- # De-duplicate tags.
110- self .event ["tags" ] = list (set (self .event ["tags" ]))
109+ # De-duplicate tags.
110+ self .event ["tags" ] = list (set (self .event ["tags" ]))
111111
112112 def load_yara_rules (self , options ):
113113 """Loads YARA rules based on the provided path.
@@ -159,7 +159,8 @@ def load_yara_rules(self, options):
159159 self .flags .append (f"compiling_error_syntax_{ e } " )
160160
161161 # Set the total rules loaded.
162- self .rules_loaded = len (list (self .compiled_yara ))
162+ if self .compiled_yara :
163+ self .rules_loaded = len (list (self .compiled_yara ))
163164
164165 def extract_match_hex (self , rule , offset , matched_string , data , offset_padding = 32 ):
165166 """
0 commit comments