1+ //! Receive notifications for many types of core events.
2+
13use std:: ffi:: { c_char, c_void, CStr } ;
24use 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 } ;
129use crate :: component:: Component ;
1310use crate :: database:: undo:: UndoEntry ;
14- use crate :: disassembly:: StringType ;
1511use crate :: external_library:: { ExternalLibrary , ExternalLocation } ;
1612use crate :: function:: Function ;
1713use 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 ,
0 commit comments