MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / register_command_for_address

Function register_command_for_address

rust/src/command.rs:197–247  ·  view source on GitHub ↗

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::AddressCommand; # use binaryninja::binary_view::BinaryView; struct MyCommand; impl AddressCommand for MyCommand { fn action(&self, view: &BinaryView, addr: u64) { // Your code here } fn valid(&self, view: &BinaryView, addr:

(name: S, desc: S, command: C)

Source from the content-addressed store, hash-verified

195/// }
196/// ```
197pub fn register_command_for_address<S, C>(name: S, desc: S, command: C)
198where
199 S: BnStrCompatible,
200 C: AddressCommand,
201{
202 extern "C" fn cb_action<C>(ctxt: *mut c_void, view: *mut BNBinaryView, addr: u64)
203 where
204 C: AddressCommand,
205 {
206 ffi_wrap!("AddressCommand::action", unsafe {
207 let cmd = &*(ctxt as *const C);
208
209 debug_assert!(!view.is_null());
210 let view = BinaryView { handle: view };
211
212 cmd.action(&view, addr);
213 })
214 }
215
216 extern "C" fn cb_valid<C>(ctxt: *mut c_void, view: *mut BNBinaryView, addr: u64) -> bool
217 where
218 C: AddressCommand,
219 {
220 ffi_wrap!("AddressCommand::valid", unsafe {
221 let cmd = &*(ctxt as *const C);
222
223 debug_assert!(!view.is_null());
224 let view = BinaryView { handle: view };
225
226 cmd.valid(&view, addr)
227 })
228 }
229
230 let name = name.into_bytes_with_nul();
231 let desc = desc.into_bytes_with_nul();
232
233 let name_ptr = name.as_ref().as_ptr() as *mut _;
234 let desc_ptr = desc.as_ref().as_ptr() as *mut _;
235
236 let ctxt = Box::into_raw(Box::new(command));
237
238 unsafe {
239 BNRegisterPluginCommandForAddress(
240 name_ptr,
241 desc_ptr,
242 Some(cb_action::<C>),
243 Some(cb_valid::<C>),
244 ctxt as *mut _,
245 );
246 }
247}
248
249/// The trait required for range-associated commands. See [register_command_for_range] for example usage.
250pub trait RangeCommand: 'static + Sync {

Callers

nothing calls this directly

Calls 2

into_bytes_with_nulMethod · 0.80
as_refMethod · 0.45

Tested by

no test coverage detected