@@ -195,6 +195,9 @@ def register(self):
195195 self ._cb .recognizeExternPointer = self ._cb .recognizeExternPointer .__class__ (self ._recognize_extern_pointer )
196196 if self .recognize_import .__func__ != StringRecognizer .recognize_import :
197197 self ._cb .recognizeImport = self ._cb .recognizeImport .__class__ (self ._recognize_import )
198+ if self .recognize_constant_data .__func__ != StringRecognizer .recognize_constant_data :
199+ self ._cb .recognizeConstantData = self ._cb .recognizeConstantData .__class__ (
200+ self ._recognize_constant_data )
198201 self .handle = core .BNRegisterStringRecognizer (self .__class__ .recognizer_name , self ._cb )
199202 self .__class__ ._registered_recognizers .append (self )
200203
@@ -263,6 +266,19 @@ def _recognize_import(self, ctxt, hlil, expr, type, val, result):
263266 log_error_for_exception ("Unhandled Python exception in StringRecognizer._recognize_import" )
264267 return False
265268
269+ def _recognize_constant_data (self , ctxt , hlil , expr , result ):
270+ try :
271+ hlil = highlevelil .HighLevelILFunction (handle = core .BNNewHighLevelILFunctionReference (hlil ))
272+ instr = hlil .get_expr (highlevelil .ExpressionIndex (expr ))
273+ ref = self .recognize_constant_data (instr )
274+ if ref is None :
275+ return False
276+ result [0 ] = ref ._to_core_struct (True )
277+ return True
278+ except Exception :
279+ log_error_for_exception ("Unhandled Python exception in StringRecognizer._recognize_constant_data" )
280+ return False
281+
266282 @property
267283 def name (self ) -> str :
268284 if hasattr (self , 'handle' ):
@@ -347,6 +363,22 @@ def recognize_import(
347363 """
348364 return None
349365
366+ def recognize_constant_data (
367+ self , instr : 'highlevelil.HighLevelILInstruction'
368+ ) -> Optional ['binaryview.DerivedString' ]:
369+ """
370+ Can be overridden to recognize strings for constant data expressions (HLIL_CONST_DATA).
371+ These expressions are generated by the outline resolver when it recovers constant data
372+ streams from scattered stores. The instruction provides access to the data buffer and
373+ builtin type via its ``constant_data`` accessor.
374+
375+ If a string is found, return a :py:class:`~binaryninja.binaryview.DerivedString` with the string information.
376+
377+ :param instr: High level expression containing the constant data
378+ :return: Optional :py:class:`~binaryninja.binaryview.DerivedString` for any string that is found.
379+ """
380+ return None
381+
350382
351383_recognizer_cache = {}
352384
@@ -402,3 +434,11 @@ def recognize_import(
402434 if not core .BNStringRecognizerRecognizeImport (self .handle , instr .function .handle , instr .expr_index , type .handle , val , string ):
403435 return None
404436 return binaryview .DerivedString ._from_core_struct (string , True )
437+
438+ def recognize_constant_data (
439+ self , instr : 'highlevelil.HighLevelILInstruction'
440+ ) -> Optional ['binaryview.DerivedString' ]:
441+ string = core .BNDerivedString ()
442+ if not core .BNStringRecognizerRecognizeConstantData (self .handle , instr .function .handle , instr .expr_index , string ):
443+ return None
444+ return binaryview .DerivedString ._from_core_struct (string , True )
0 commit comments