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::FunctionCommand; # use binaryninja::binary_view::BinaryView; # use binaryninja::function::Function; # use binaryninja::command::register_command_for_function; struct MyCommand; impl FunctionCommand for MyCommand { fn action(
(name: S, desc: S, command: C)
| 404 | /// } |
| 405 | /// ``` |
| 406 | pub fn register_command_for_function<S, C>(name: S, desc: S, command: C) |
| 407 | where |
| 408 | S: BnStrCompatible, |
| 409 | C: FunctionCommand, |
| 410 | { |
| 411 | extern "C" fn cb_action<C>(ctxt: *mut c_void, view: *mut BNBinaryView, func: *mut BNFunction) |
| 412 | where |
| 413 | C: FunctionCommand, |
| 414 | { |
| 415 | ffi_wrap!("FunctionCommand::action", unsafe { |
| 416 | let cmd = &*(ctxt as *const C); |
| 417 | |
| 418 | debug_assert!(!view.is_null()); |
| 419 | let view = BinaryView { handle: view }; |
| 420 | |
| 421 | debug_assert!(!func.is_null()); |
| 422 | let func = Function { handle: func }; |
| 423 | |
| 424 | cmd.action(&view, &func); |
| 425 | }) |
| 426 | } |
| 427 | |
| 428 | extern "C" fn cb_valid<C>( |
| 429 | ctxt: *mut c_void, |
| 430 | view: *mut BNBinaryView, |
| 431 | func: *mut BNFunction, |
| 432 | ) -> bool |
| 433 | where |
| 434 | C: FunctionCommand, |
| 435 | { |
| 436 | ffi_wrap!("FunctionCommand::valid", unsafe { |
| 437 | let cmd = &*(ctxt as *const C); |
| 438 | |
| 439 | debug_assert!(!view.is_null()); |
| 440 | let view = BinaryView { handle: view }; |
| 441 | |
| 442 | debug_assert!(!func.is_null()); |
| 443 | let func = Function { handle: func }; |
| 444 | |
| 445 | cmd.valid(&view, &func) |
| 446 | }) |
| 447 | } |
| 448 | |
| 449 | let name = name.into_bytes_with_nul(); |
| 450 | let desc = desc.into_bytes_with_nul(); |
| 451 | |
| 452 | let name_ptr = name.as_ref().as_ptr() as *mut _; |
| 453 | let desc_ptr = desc.as_ref().as_ptr() as *mut _; |
| 454 | |
| 455 | let ctxt = Box::into_raw(Box::new(command)); |
| 456 | |
| 457 | unsafe { |
| 458 | BNRegisterPluginCommandForFunction( |
| 459 | name_ptr, |
| 460 | desc_ptr, |
| 461 | Some(cb_action::<C>), |
| 462 | Some(cb_valid::<C>), |
| 463 | ctxt as *mut _, |
no test coverage detected