From ddd7aa4e7cd5a1aa07a16c3895d1f91ebf49347b Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Tue, 24 Mar 2026 09:05:49 -0700 Subject: Add a hook to allow BinaryView subclasses to run code after snapshot data is applied Snapshot data is applied when loading from a database, rebasing the view, etc. --- rust/src/custom_binary_view.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'rust/src/custom_binary_view.rs') diff --git a/rust/src/custom_binary_view.rs b/rust/src/custom_binary_view.rs index 4d21ce89..8c880fc1 100644 --- a/rust/src/custom_binary_view.rs +++ b/rust/src/custom_binary_view.rs @@ -460,6 +460,7 @@ pub unsafe trait CustomBinaryView: 'static + BinaryViewBase + Sync + Sized { fn new(handle: &BinaryView, args: &Self::Args) -> Result; fn init(&mut self, args: Self::Args) -> Result<()>; + fn on_after_snapshot_data_applied(&mut self) {} } /// Represents a partially initialized custom `BinaryView` that should be returned to the core @@ -600,6 +601,18 @@ impl<'a, T: CustomBinaryViewType> CustomViewBuilder<'a, T> { }) } + extern "C" fn cb_on_after_snapshot_data_applied(ctxt: *mut c_void) + where + V: CustomBinaryView, + { + ffi_wrap!("BinaryViewBase::onAfterSnapshotDataApplied", unsafe { + let context = &mut *(ctxt as *mut CustomViewContext); + if let CustomViewContextState::Initialized { view } = &mut context.state { + view.on_after_snapshot_data_applied(); + } + }) + } + extern "C" fn cb_free_object(ctxt: *mut c_void) where V: CustomBinaryView, @@ -890,6 +903,7 @@ impl<'a, T: CustomBinaryViewType> CustomViewBuilder<'a, T> { isRelocatable: Some(cb_relocatable::), getAddressSize: Some(cb_address_size::), save: Some(cb_save::), + onAfterSnapshotDataApplied: Some(cb_on_after_snapshot_data_applied::), }; let view_name = view_name.to_cstr(); -- cgit v1.3.1