MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / find_all_data

Method find_all_data

python/binaryview.py:8986–9052  ·  view source on GitHub ↗

``find_all_data`` searches for the bytes ``data`` starting at the virtual address ``start`` until the virtual address ``end``. Once a match is found, the ``match_callback`` is called. :param int start: virtual address to start searching from. :param int end: virtual address to end the sear

(
	    self, start: int, end: int, data: bytes, flags: FindFlag = FindFlag.FindCaseSensitive,
	    progress_func: Optional[ProgressFuncType] = None, match_callback: Optional[DataMatchCallbackType] = None
	)

Source from the content-addressed store, hash-verified

8984 raise StopIteration
8985
8986 def find_all_data(
8987 self, start: int, end: int, data: bytes, flags: FindFlag = FindFlag.FindCaseSensitive,
8988 progress_func: Optional[ProgressFuncType] = None, match_callback: Optional[DataMatchCallbackType] = None
8989 ) -> QueueGenerator:
8990 """
8991 ``find_all_data`` searches for the bytes ``data`` starting at the virtual address ``start``
8992 until the virtual address ``end``. Once a match is found, the ``match_callback`` is called.
8993
8994 :param int start: virtual address to start searching from.
8995 :param int end: virtual address to end the search.
8996 :param Union[bytes, bytearray, str] data: data to search for
8997 :param FindFlag flags: (optional) defaults to case-insensitive data search
8998
8999 ==================== ============================
9000 FindFlag Description
9001 ==================== ============================
9002 FindCaseSensitive Case-sensitive search
9003 FindCaseInsensitive Case-insensitive search
9004 ==================== ============================
9005 :param callback progress_func: optional function to be called with the current progress \
9006 and total count. This function should return a boolean value that decides whether the \
9007 search should continue or stop
9008 :param callback match_callback: function that gets called when a match is found. The \
9009 callback takes two parameters, i.e., the address of the match, and the actual DataBuffer \
9010 that satisfies the search. If this parameter is None, this function becomes a generator \
9011 and yields a tuple of the matching address and the matched DataBuffer. This function \
9012 can return a boolean value that decides whether the search should continue or stop.
9013 :rtype QueueGenerator: A generator object that will yield all the found results
9014 """
9015 if not isinstance(data, bytes):
9016 raise TypeError("data parameter must be bytes, bytearray, or str")
9017
9018 buf = databuffer.DataBuffer(data)
9019 if not isinstance(flags, FindFlag):
9020 raise TypeError('flag parameter must have type FindFlag')
9021
9022 if progress_func:
9023 progress_func_obj = ctypes.CFUNCTYPE(
9024 ctypes.c_bool, ctypes.c_void_p, ctypes.c_ulonglong, ctypes.c_ulonglong
9025 )(lambda ctxt, cur, total: progress_func(cur, total))
9026 else:
9027 progress_func_obj = ctypes.CFUNCTYPE(
9028 ctypes.c_bool, ctypes.c_void_p, ctypes.c_ulonglong, ctypes.c_ulonglong
9029 )(lambda ctxt, cur, total: True)
9030
9031 if match_callback:
9032 # the `not match_callback(...) is False` tolerates the users who forget to return
9033 # `True` from inside the callback
9034 match_callback_obj = ctypes.CFUNCTYPE(
9035 ctypes.c_bool, ctypes.c_void_p, ctypes.c_ulonglong, ctypes.POINTER(core.BNDataBuffer)
9036 )(lambda ctxt, addr, match: not match_callback(addr, databuffer.DataBuffer(handle=match)) is False)
9037 return core.BNFindAllDataWithProgress(
9038 self.handle, start, end, buf.handle, flags, None, progress_func_obj, None, match_callback_obj
9039 )
9040 else:
9041 results = queue.Queue()
9042 match_callback_obj = ctypes.CFUNCTYPE(
9043 ctypes.c_bool, ctypes.c_void_p, ctypes.c_ulonglong, ctypes.POINTER(core.BNDataBuffer)

Callers

nothing calls this directly

Calls 2

DataBufferMethod · 0.80
putMethod · 0.80

Tested by

no test coverage detected