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

Function register_command_for_range

rust/src/command.rs:299–354  ·  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 std::ops::Range; # use binaryninja::command::RangeCommand; # use binaryninja::binary_view::BinaryView; struct MyCommand; impl RangeCommand for MyCommand { fn action(&self, view: &BinaryView, range: Range ) { // Your code here } fn valid(&sel

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

Source from the content-addressed store, hash-verified

297/// }
298/// ```
299pub fn register_command_for_range<S, C>(name: S, desc: S, command: C)
300where
301 S: BnStrCompatible,
302 C: RangeCommand,
303{
304 extern "C" fn cb_action<C>(ctxt: *mut c_void, view: *mut BNBinaryView, addr: u64, len: u64)
305 where
306 C: RangeCommand,
307 {
308 ffi_wrap!("RangeCommand::action", unsafe {
309 let cmd = &*(ctxt as *const C);
310
311 debug_assert!(!view.is_null());
312 let view = BinaryView { handle: view };
313
314 cmd.action(&view, addr..addr.wrapping_add(len));
315 })
316 }
317
318 extern "C" fn cb_valid<C>(
319 ctxt: *mut c_void,
320 view: *mut BNBinaryView,
321 addr: u64,
322 len: u64,
323 ) -> bool
324 where
325 C: RangeCommand,
326 {
327 ffi_wrap!("RangeCommand::valid", unsafe {
328 let cmd = &*(ctxt as *const C);
329
330 debug_assert!(!view.is_null());
331 let view = BinaryView { handle: view };
332
333 cmd.valid(&view, addr..addr.wrapping_add(len))
334 })
335 }
336
337 let name = name.into_bytes_with_nul();
338 let desc = desc.into_bytes_with_nul();
339
340 let name_ptr = name.as_ref().as_ptr() as *mut _;
341 let desc_ptr = desc.as_ref().as_ptr() as *mut _;
342
343 let ctxt = Box::into_raw(Box::new(command));
344
345 unsafe {
346 BNRegisterPluginCommandForRange(
347 name_ptr,
348 desc_ptr,
349 Some(cb_action::<C>),
350 Some(cb_valid::<C>),
351 ctxt as *mut _,
352 );
353 }
354}
355
356/// The trait required for function-associated commands. See [register_command_for_function] for example usage.

Callers

nothing calls this directly

Calls 2

into_bytes_with_nulMethod · 0.80
as_refMethod · 0.45

Tested by

no test coverage detected