@@ -186,9 +186,14 @@ def _process_results(
186
186
for result in results :
187
187
line_start , line_end = result ["start" ]["line" ], result ["end" ]["line" ]
188
188
if (line_start , line_end ) not in lines_by_rule [result ["check_id" ]]:
189
- line_no .add ((line_start , line_end ))
190
189
result_by_rule [result ["check_id" ]].append (result )
191
190
lines_by_rule [result ["check_id" ]].add ((line_start , line_end ))
191
+ extended_preview = self .metadata_cache .get (result ["check_id" ], {}).get (
192
+ "extend_preview" , 0
193
+ )
194
+ if extended_preview :
195
+ line_start = max (line_start - extended_preview , first_line_no )
196
+ line_no .add ((line_start , line_end ))
192
197
193
198
lines = dict ()
194
199
if line_no :
@@ -207,6 +212,9 @@ def _process_results(
207
212
metadata = self .metadata_cache .get (rule_id , {})
208
213
title = metadata .get ("title" , metadata .get ("name" , message [:100 ]))
209
214
attack_id = metadata .get ("attack_id" )
215
+ extend_preview = metadata .get ("extend_preview" , 0 )
216
+ if not isinstance (extend_preview , int ):
217
+ extend_preview = 0
210
218
211
219
section = ResultTextSection (
212
220
title ,
@@ -216,7 +224,8 @@ def _process_results(
216
224
section .set_heuristic (heuristic , signature = rule_id , attack_id = attack_id )
217
225
for match in matches :
218
226
line_start , line_end = match ["start" ]["line" ], match ["end" ]["line" ]
219
- line = lines .get ((line_start , line_end ), "" )
227
+
228
+ line = lines .get ((max (line_start - extend_preview , first_line_no ), line_end ), "" )
220
229
code_hash = self ._get_code_hash (line )
221
230
222
231
if first_line_no == 0 :
@@ -225,6 +234,8 @@ def _process_results(
225
234
title = f"Match at lines { line_start } - { line_end } "
226
235
if line_start == line_end :
227
236
title = f"Match at line { line_start } "
237
+ if extend_preview :
238
+ title = f"{ title } (+{ extend_preview } lines before)"
228
239
ResultMemoryDumpSection (
229
240
title ,
230
241
body = line [:MAX_LINE_SIZE ],
0 commit comments