r""" ``register_for_range`` Register a plugin to be called with a range argument :param str name: name of the plugin (use 'Folder\\Name' to have the menu item nested in a folder) :param str description: description of the plugin :param callback action: function to call with the :class:`~bin
( cls, name: str, description: str, action: Callable[['binaryview.BinaryView', int, int], None], is_valid: Optional[Callable[['binaryview.BinaryView', int, int], bool]] = None )
| 454 | |
| 455 | @classmethod |
| 456 | def register_for_range( |
| 457 | cls, name: str, description: str, action: Callable[['binaryview.BinaryView', int, int], None], |
| 458 | is_valid: Optional[Callable[['binaryview.BinaryView', int, int], bool]] = None |
| 459 | ): |
| 460 | r""" |
| 461 | ``register_for_range`` Register a plugin to be called with a range argument |
| 462 | |
| 463 | :param str name: name of the plugin (use 'Folder\\Name' to have the menu item nested in a folder) |
| 464 | :param str description: description of the plugin |
| 465 | :param callback action: function to call with the :class:`~binaryview.BinaryView`, start address, and length as arguments |
| 466 | :param callback is_valid: optional argument of a function passed a :class:`~binaryview.BinaryView`, start address, and length to determine whether the plugin should be enabled for that view |
| 467 | :rtype: None |
| 468 | :Example: |
| 469 | |
| 470 | >>> def my_plugin(bv: BinaryView, start: int, length: int): |
| 471 | >>> log_info(f"My plugin was called on bv: `{bv}` at {hex(start)} of length {hex(length)}") |
| 472 | >>> PluginCommand.register_for_range("My Plugin", "My plugin description (not used)", my_plugin) |
| 473 | True |
| 474 | >>> def is_valid(bv: BinaryView, start: int, length: int) -> bool: |
| 475 | >>> return False |
| 476 | >>> PluginCommand.register_for_range("My Plugin (With Valid Function)", "My plugin description (not used)", my_plugin, is_valid) |
| 477 | True |
| 478 | |
| 479 | .. warning:: Calling ``register_for_range`` with the same function name will replace the existing function but will leak the memory of the original plugin. |
| 480 | """ |
| 481 | binaryninja._init_plugins() |
| 482 | action_obj = ctypes.CFUNCTYPE( |
| 483 | None, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.c_ulonglong, ctypes.c_ulonglong |
| 484 | )(lambda ctxt, view, addr, length: cls._range_action(view, addr, length, action)) |
| 485 | is_valid_obj = ctypes.CFUNCTYPE( |
| 486 | ctypes.c_bool, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.c_ulonglong, ctypes.c_ulonglong |
| 487 | )(lambda ctxt, view, addr, length: cls._range_is_valid(view, addr, length, is_valid)) |
| 488 | cls._registered_commands.append((action_obj, is_valid_obj)) |
| 489 | core.BNRegisterPluginCommandForRange(name, description, action_obj, is_valid_obj, None) |
| 490 | |
| 491 | @classmethod |
| 492 | def register_for_function( |
no test coverage detected