r""" ``register_for_address`` Register a plugin to be called with an address 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:
( cls, name: str, description: str, action: Callable[['binaryview.BinaryView', int], None], is_valid: Optional[Callable[['binaryview.BinaryView', int], bool]] = None )
| 418 | |
| 419 | @classmethod |
| 420 | def register_for_address( |
| 421 | cls, name: str, description: str, action: Callable[['binaryview.BinaryView', int], None], |
| 422 | is_valid: Optional[Callable[['binaryview.BinaryView', int], bool]] = None |
| 423 | ): |
| 424 | r""" |
| 425 | ``register_for_address`` Register a plugin to be called with an address argument |
| 426 | |
| 427 | :param str name: name of the plugin (use 'Folder\\Name' to have the menu item nested in a folder) |
| 428 | :param str description: description of the plugin |
| 429 | :param callback action: function to call with the :class:`~binaryview.BinaryView` and address as arguments |
| 430 | :param callback is_valid: optional argument of a function passed a :class:`~binaryview.BinaryView` and address to determine whether the plugin should be enabled for that view |
| 431 | :rtype: None |
| 432 | :Example: |
| 433 | |
| 434 | >>> def my_plugin(bv: BinaryView, address: int): |
| 435 | >>> log_info(f"My plugin was called on bv: `{bv}` at address {hex(address)}") |
| 436 | >>> PluginCommand.register_for_address("My Plugin", "My plugin description (not used)", my_plugin) |
| 437 | True |
| 438 | >>> def is_valid(bv: BinaryView, address: int) -> bool: |
| 439 | >>> return False |
| 440 | >>> PluginCommand.register_for_address("My Plugin (With Valid Function)", "My plugin description (not used)", my_plugin, is_valid) |
| 441 | True |
| 442 | |
| 443 | .. warning:: Calling ``register_for_address`` with the same function name will replace the existing function but will leak the memory of the original plugin. |
| 444 | """ |
| 445 | binaryninja._init_plugins() |
| 446 | action_obj = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.POINTER( |
| 447 | core.BNBinaryView |
| 448 | ), ctypes.c_ulonglong)(lambda ctxt, view, addr: cls._address_action(view, addr, action)) |
| 449 | is_valid_obj = ctypes.CFUNCTYPE( |
| 450 | ctypes.c_bool, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.c_ulonglong |
| 451 | )(lambda ctxt, view, addr: cls._address_is_valid(view, addr, is_valid)) |
| 452 | cls._registered_commands.append((action_obj, is_valid_obj)) |
| 453 | core.BNRegisterPluginCommandForAddress(name, description, action_obj, is_valid_obj, None) |
| 454 | |
| 455 | @classmethod |
| 456 | def register_for_range( |
no test coverage detected