The function call required for generic commands; commands added in this way will be in the `Plugins` submenu of the menu bar. # Example ```no_run # use binaryninja::command::Command; # use binaryninja::binary_view::BinaryView; struct MyCommand; impl Command for MyCommand { fn action(&self, view: &BinaryView) { // Your code here } fn valid(&self, view: &BinaryView) -> bool { // Your code here tr
(name: S, desc: S, command: C)
| 94 | /// } |
| 95 | /// ``` |
| 96 | pub fn register_command<S, C>(name: S, desc: S, command: C) |
| 97 | where |
| 98 | S: BnStrCompatible, |
| 99 | C: Command, |
| 100 | { |
| 101 | extern "C" fn cb_action<C>(ctxt: *mut c_void, view: *mut BNBinaryView) |
| 102 | where |
| 103 | C: Command, |
| 104 | { |
| 105 | ffi_wrap!("Command::action", unsafe { |
| 106 | let cmd = &*(ctxt as *const C); |
| 107 | |
| 108 | debug_assert!(!view.is_null()); |
| 109 | let view = BinaryView { handle: view }; |
| 110 | |
| 111 | cmd.action(&view); |
| 112 | }) |
| 113 | } |
| 114 | |
| 115 | extern "C" fn cb_valid<C>(ctxt: *mut c_void, view: *mut BNBinaryView) -> bool |
| 116 | where |
| 117 | C: Command, |
| 118 | { |
| 119 | ffi_wrap!("Command::valid", unsafe { |
| 120 | let cmd = &*(ctxt as *const C); |
| 121 | |
| 122 | debug_assert!(!view.is_null()); |
| 123 | let view = BinaryView { handle: view }; |
| 124 | |
| 125 | cmd.valid(&view) |
| 126 | }) |
| 127 | } |
| 128 | |
| 129 | let name = name.into_bytes_with_nul(); |
| 130 | let desc = desc.into_bytes_with_nul(); |
| 131 | |
| 132 | let name_ptr = name.as_ref().as_ptr() as *mut _; |
| 133 | let desc_ptr = desc.as_ref().as_ptr() as *mut _; |
| 134 | |
| 135 | let ctxt = Box::into_raw(Box::new(command)); |
| 136 | |
| 137 | unsafe { |
| 138 | BNRegisterPluginCommand( |
| 139 | name_ptr, |
| 140 | desc_ptr, |
| 141 | Some(cb_action::<C>), |
| 142 | Some(cb_valid::<C>), |
| 143 | ctxt as *mut _, |
| 144 | ); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | /// The trait required for address-associated commands. See [register_command_for_address] for example usage. |
| 149 | pub trait AddressCommand: 'static + Sync { |
no test coverage detected