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

Function register_command

rust/src/command.rs:96–146  ·  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::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)

Source from the content-addressed store, hash-verified

94/// }
95/// ```
96pub fn register_command<S, C>(name: S, desc: S, command: C)
97where
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.
149pub trait AddressCommand: 'static + Sync {

Callers 5

CorePluginInitFunction · 0.85
UIPluginInitFunction · 0.85
CorePluginInitFunction · 0.85
plugin_initFunction · 0.85
CorePluginInitFunction · 0.85

Calls 2

into_bytes_with_nulMethod · 0.80
as_refMethod · 0.45

Tested by

no test coverage detected