Skip to content

Commit 095fcab

Browse files
committed
[Rust] Misc cleanup for data notifications
1 parent b820e22 commit 095fcab

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

rust/src/data_notification.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1+
//! Receive notifications for many types of core events.
2+
13
use std::ffi::{c_char, c_void, CStr};
24
use std::ptr::NonNull;
35

4-
use binaryninjacore_sys::{
5-
BNBinaryDataNotification, BNBinaryView, BNComponent, BNDataVariable, BNExternalLibrary,
6-
BNExternalLocation, BNFunction, BNQualifiedName, BNRegisterDataNotification, BNSection,
7-
BNSegment, BNStringType, BNSymbol, BNTagReference, BNTagType, BNType, BNTypeArchive,
8-
BNUndoEntry, BNUnregisterDataNotification,
9-
};
6+
use binaryninjacore_sys::*;
107

11-
use crate::binary_view::BinaryView;
8+
use crate::binary_view::{BinaryView, StringType};
129
use crate::component::Component;
1310
use crate::database::undo::UndoEntry;
14-
use crate::disassembly::StringType;
1511
use crate::external_library::{ExternalLibrary, ExternalLocation};
1612
use crate::function::Function;
1713
use crate::rc::Ref;
@@ -36,10 +32,9 @@ macro_rules! trait_handler {
3632
) $(-> $ret_type:ty)?
3733
),* $(,)?
3834
) => {
39-
/// Used to describe which call should be triggered by BinaryNinja.
40-
/// By default all calls are disabled.
35+
/// Used to describe which call should be triggered. By default, all calls are disabled.
4136
///
42-
/// Used by [CustomDataNotification::register]
37+
/// Used by [`CustomDataNotification::register`]
4338
#[derive(Default)]
4439
pub struct DataNotificationTriggers {
4540
$($fun_name: bool,)*
@@ -91,7 +86,11 @@ macro_rules! trait_handler {
9186
let leak_notify = Box::leak(Box::new(notify));
9287
let handle = BNBinaryDataNotification {
9388
context: leak_notify as *mut _ as *mut c_void,
94-
$($ffi_param_name: triggers.$fun_name.then_some($fun_name::<H>)),*
89+
$($ffi_param_name: triggers.$fun_name.then_some($fun_name::<H>)),*,
90+
// TODO: Require all BNBinaryDataNotification's to be implemented?
91+
// Since core developers are not required to write Rust bindings (yet) we do not
92+
// force new binary data notifications callbacks to be written here.of core developers who do not wish to write
93+
..Default::default()
9594
};
9695
// Box it to prevent a copy being returned in `DataNotificationHandle`.
9796
let mut boxed_handle = Box::new(handle);
@@ -103,10 +102,15 @@ macro_rules! trait_handler {
103102
}
104103
}
105104

106-
/// Implement closures that will be called by BinaryNinja on the event of
107-
/// data modification.
105+
/// Implement closures that will be called by on the event of data modification.
106+
///
107+
/// Once dropped the closures will stop being called.
108+
///
109+
/// NOTE: Closures are not executed on the same thread as the event that occurred, you must not depend
110+
/// on any serial behavior
111+
///
112+
/// # Example
108113
///
109-
/// example:
110114
/// ```no_run
111115
/// # use binaryninja::data_notification::DataNotificationClosure;
112116
/// # use binaryninja::function::Function;
@@ -144,6 +148,7 @@ macro_rules! trait_handler {
144148
}
145149
)*
146150

151+
/// Register the closures to be notified up until the [`DataNotificationHandle`] is dropped.
147152
pub fn register(
148153
self,
149154
view: &BinaryView,

rust/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ pub mod component;
3939
pub mod confidence;
4040
pub mod custom_binary_view;
4141
pub mod data_buffer;
42-
pub mod data_renderer;
4342
pub mod data_notification;
43+
pub mod data_renderer;
4444
pub mod database;
4545
pub mod debuginfo;
4646
pub mod demangle;

0 commit comments

Comments
 (0)