Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions binaryninjaapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -5773,13 +5773,23 @@ namespace BinaryNinja {
void PerformDefineRelocation(Architecture* arch, BNRelocationInfo& info, uint64_t target, uint64_t reloc);
void PerformDefineRelocation(Architecture* arch, BNRelocationInfo& info, Ref<Symbol> sym, uint64_t reloc);

/*! DidApplySnapshotData is called when loading a view from a database, after snapshot data has been applied to it.

\note This method **may** be overridden by custom BinaryViews.

\warning This method **must not** be called directly.

*/
virtual void DidApplySnapshotData() {}

public:
void NotifyDataWritten(uint64_t offset, size_t len);
void NotifyDataInserted(uint64_t offset, size_t len);
void NotifyDataRemoved(uint64_t offset, uint64_t len);

private:
static bool InitCallback(void* ctxt);
static void DidApplySnapshotDataCallback(void* ctxt);
static void FreeCallback(void* ctxt);
static size_t ReadCallback(void* ctxt, void* dest, uint64_t offset, size_t len);
static size_t WriteCallback(void* ctxt, uint64_t offset, const void* src, size_t len);
Expand Down
5 changes: 3 additions & 2 deletions binaryninjacore.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
// Current ABI version for linking to the core. This is incremented any time
// there are changes to the API that affect linking, including new functions,
// new types, or modifications to existing functions or types.
#define BN_CURRENT_CORE_ABI_VERSION 162
#define BN_CURRENT_CORE_ABI_VERSION 163

// Minimum ABI version that is supported for loading of plugins. Plugins that
// are linked to an ABI version less than this will not be able to load and
// will require rebuilding. The minimum version is increased when there are
// incompatible changes that break binary compatibility, such as changes to
// existing types or functions.
#define BN_MINIMUM_CORE_ABI_VERSION 161
#define BN_MINIMUM_CORE_ABI_VERSION 163

#ifdef __GNUC__
#ifdef BINARYNINJACORE_LIBRARY
Expand Down Expand Up @@ -1847,6 +1847,7 @@ extern "C"
bool (*isRelocatable)(void* ctxt);
size_t (*getAddressSize)(void* ctxt);
bool (*save)(void* ctxt, BNFileAccessor* accessor);
void (*didApplySnapshotData)(void* ctxt);
} BNCustomBinaryView;

typedef struct BNCustomBinaryViewType
Expand Down
8 changes: 8 additions & 0 deletions binaryview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,7 @@ BinaryView::BinaryView(const std::string& typeName, FileMetadata* file, BinaryVi
view.isRelocatable = IsRelocatableCallback;
view.getAddressSize = GetAddressSizeCallback;
view.save = SaveCallback;
view.didApplySnapshotData = DidApplySnapshotDataCallback;
m_file = file;
AddRefForRegistration();
m_object = BNCreateCustomBinaryView(
Expand All @@ -1388,6 +1389,13 @@ bool BinaryView::InitCallback(void* ctxt)
}


void BinaryView::DidApplySnapshotDataCallback(void* ctxt)
{
CallbackRef<BinaryView> view(ctxt);
view->DidApplySnapshotData();
}


void BinaryView::FreeCallback(void* ctxt)
{
BinaryView* view = (BinaryView*)ctxt;
Expand Down
10 changes: 10 additions & 0 deletions python/binaryview.py
Original file line number Diff line number Diff line change
Expand Up @@ -3173,6 +3173,7 @@ def __init__(
self._cb.isRelocatable = self._cb.isRelocatable.__class__(self._is_relocatable)
self._cb.getAddressSize = self._cb.getAddressSize.__class__(self._get_address_size)
self._cb.save = self._cb.save.__class__(self._save)
self._cb.didApplySnapshotData = self._cb.didApplySnapshotData.__class__(self._did_apply_snapshot_data)
if file_metadata is None:
raise Exception("Attempting to create a BinaryView with FileMetadata which is None")
self._file = file_metadata
Expand Down Expand Up @@ -4482,6 +4483,15 @@ def _save(self, ctxt, file_accessor):
log_error_for_exception("Unhandled Python exception in BinaryView._save")
return False

def _did_apply_snapshot_data(self, ctxt):
try:
self.perform_did_apply_snapshot_data()
except:
log_error_for_exception("Unhandled Python exception in BinaryView._did_apply_snapshot_data")

def perform_did_apply_snapshot_data(self) -> None:
pass

def init(self) -> bool:
return True

Expand Down
14 changes: 14 additions & 0 deletions rust/src/custom_binary_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ pub unsafe trait CustomBinaryView: 'static + BinaryViewBase + Sync + Sized {

fn new(handle: &BinaryView, args: &Self::Args) -> Result<Self>;
fn init(&mut self, args: Self::Args) -> Result<()>;
fn did_apply_snapshot_data(&mut self) {}
}

/// Represents a partially initialized custom `BinaryView` that should be returned to the core
Expand Down Expand Up @@ -600,6 +601,18 @@ impl<'a, T: CustomBinaryViewType> CustomViewBuilder<'a, T> {
})
}

extern "C" fn cb_did_apply_snapshot_data<V>(ctxt: *mut c_void)
where
V: CustomBinaryView,
{
ffi_wrap!("BinaryViewBase::didApplySnapshotData", unsafe {
let context = &mut *(ctxt as *mut CustomViewContext<V>);
if let CustomViewContextState::Initialized { view } = &mut context.state {
view.did_apply_snapshot_data();
}
})
}

extern "C" fn cb_free_object<V>(ctxt: *mut c_void)
where
V: CustomBinaryView,
Expand Down Expand Up @@ -890,6 +903,7 @@ impl<'a, T: CustomBinaryViewType> CustomViewBuilder<'a, T> {
isRelocatable: Some(cb_relocatable::<V>),
getAddressSize: Some(cb_address_size::<V>),
save: Some(cb_save::<V>),
didApplySnapshotData: Some(cb_did_apply_snapshot_data::<V>),
};

let view_name = view_name.to_cstr();
Expand Down
Loading