r""" ``register_for_function`` Register a plugin to be called with a function 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', 'function.Function'], None], is_valid: Optional[Callable[['binaryview.BinaryView', 'function.Function'], bool]] = None )
| 490 | |
| 491 | @classmethod |
| 492 | def register_for_function( |
| 493 | cls, name: str, description: str, action: Callable[['binaryview.BinaryView', 'function.Function'], None], |
| 494 | is_valid: Optional[Callable[['binaryview.BinaryView', 'function.Function'], bool]] = None |
| 495 | ): |
| 496 | r""" |
| 497 | ``register_for_function`` Register a plugin to be called with a function argument |
| 498 | |
| 499 | :param str name: name of the plugin (use 'Folder\\Name' to have the menu item nested in a folder) |
| 500 | :param str description: description of the plugin |
| 501 | :param callback action: function to call with the :class:`~binaryview.BinaryView` and a :class:`~function.Function` as arguments |
| 502 | :param callback is_valid: optional argument of a function passed a :class:`~binaryview.BinaryView` and :class:`~function.Function` to determine whether the plugin should be enabled for that view |
| 503 | :rtype: None |
| 504 | :Example: |
| 505 | |
| 506 | >>> def my_plugin(bv: BinaryView, func: Function): |
| 507 | >>> log_info(f"My plugin was called on func {func} in bv `{bv}`") |
| 508 | >>> PluginCommand.register_for_function("My Plugin", "My plugin description (not used)", my_plugin) |
| 509 | True |
| 510 | >>> def is_valid(bv: BinaryView, func: Function) -> bool: |
| 511 | >>> return False |
| 512 | >>> PluginCommand.register_for_function("My Plugin (With Valid Function)", "My plugin description (not used)", my_plugin, is_valid) |
| 513 | True |
| 514 | |
| 515 | .. warning:: Calling ``register_for_function`` with the same function name will replace the existing function but will leak the memory of the original plugin. |
| 516 | """ |
| 517 | binaryninja._init_plugins() |
| 518 | action_obj = ctypes.CFUNCTYPE( |
| 519 | None, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.POINTER(core.BNFunction) |
| 520 | )(lambda ctxt, view, func: cls._function_action(view, func, action)) |
| 521 | is_valid_obj = ctypes.CFUNCTYPE( |
| 522 | ctypes.c_bool, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.POINTER(core.BNFunction) |
| 523 | )(lambda ctxt, view, func: cls._function_is_valid(view, func, is_valid)) |
| 524 | cls._registered_commands.append((action_obj, is_valid_obj)) |
| 525 | core.BNRegisterPluginCommandForFunction(name, description, action_obj, is_valid_obj, None) |
| 526 | |
| 527 | @classmethod |
| 528 | def register_for_low_level_il_function( |
no test coverage detected