diff options
| author | Xusheng <xusheng@vector35.com> | 2021-04-22 12:54:53 +0800 |
|---|---|---|
| committer | Xusheng <xusheng@vector35.com> | 2021-04-22 13:32:42 +0800 |
| commit | f3596af24b9ca5705cba677b6aff11d72ed7abf4 (patch) | |
| tree | c1b153931426966287d64b0f4ccd85cc86e0a90e | |
| parent | c4b1dd712783e7474570705e6d95183a0c02a76e (diff) | |
fix Python search API
| -rw-r--r-- | python/binaryview.py | 11 | ||||
| -rw-r--r-- | suite/testcommon.py | 6 |
2 files changed, 10 insertions, 7 deletions
diff --git a/python/binaryview.py b/python/binaryview.py index 02cdf191..ca288486 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -5664,10 +5664,13 @@ class BinaryView(object): (lambda ctxt, cur, total: True) if match_callback: + # The reason we use `not match_callback(...) is False` is the user tends to happily + # deal with the returned data, but forget to return True at the end of the callback. + # Then only the first result will be returned. match_callback_obj = ctypes.CFUNCTYPE(ctypes.c_bool, ctypes.c_void_p, ctypes.c_ulonglong, ctypes.c_char_p, ctypes.POINTER(core.BNLinearDisassemblyLine))\ - (lambda ctxt, addr, match, line: match_callback(addr, match,\ + (lambda ctxt, addr, match, line: not match_callback(addr, match,\ self._LinearDisassemblyLine_convertor(line)) is False) return core.BNFindAllTextWithProgress(self.handle, start, end, text, @@ -5739,11 +5742,11 @@ class BinaryView(object): results = queue.Queue() match_callback_obj = ctypes.CFUNCTYPE(ctypes.c_bool, ctypes.c_void_p,\ ctypes.c_ulonglong, ctypes.POINTER(core.BNLinearDisassemblyLine))\ - (lambda ctxt, addr, line: results.put(addr,\ - self._LinearDisassemblyLine_convertor(line)) or True) + (lambda ctxt, addr, line: results.put((addr,\ + self._LinearDisassemblyLine_convertor(line))) or True) t = threading.Thread(target = lambda: core.BNFindAllConstantWithProgress(self.handle, - start, end, constant, graph_type, settings.handle, None, progress_func_obj, None,\ + start, end, constant, settings.handle, graph_type, None, progress_func_obj, None,\ match_callback_obj)) return self.QueueGenerator(t, results) diff --git a/suite/testcommon.py b/suite/testcommon.py index 48eeccab..95c10f85 100644 --- a/suite/testcommon.py +++ b/suite/testcommon.py @@ -1110,7 +1110,7 @@ class TestBuilder(Builder): line %s' % (addr, match, line)) for addr, line in bv.find_all_constant(bv.start, bv.end, 0x58): - retinfo.append('constant 0x58 is found at address 0x%lx with line' %\ + retinfo.append('constant 0x58 is found at address 0x%lx with line %s' %\ (addr, line)) def data_callback(addr, match): @@ -1123,8 +1123,8 @@ class TestBuilder(Builder): retinfo.append('match found at address: 0x%lx with string %s, line %s' %\ (addr, match, line)) - bv.find_all_text(bv.start, bv.end, 'test', None, FindFlag.FindCaseSensitive, None, - string_callback) + bv.find_all_text(bv.start, bv.end, 'test', None, FindFlag.FindCaseSensitive, + FunctionGraphType.NormalFunctionGraph, None, string_callback) def constant_callback(addr, line): retinfo.append('match found at address: 0x%lx with constant 0x58, line %s'\ |
