From da698e7e15231ea1af75aab36cd87d03ae842424 Mon Sep 17 00:00:00 2001 From: Xusheng Date: Thu, 23 May 2024 15:52:36 +0800 Subject: [PATCH] Add a rebased callback for binary view --- binaryninjaapi.h | 14 ++++++++++++++ binaryninjacore.h | 1 + binaryview.cpp | 11 +++++++++++ 3 files changed, 26 insertions(+) diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 9eca62d44..96bb4b8cb 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -3150,6 +3150,8 @@ namespace BinaryNinja { static void UndoEntryTakenCallback(void* ctxt, BNBinaryView* data, BNUndoEntry* entry); static void RedoEntryTakenCallback(void* ctxt, BNBinaryView* data, BNUndoEntry* entry); + static void RebasedCallback(void* ctxt, BNBinaryView* oldView, BNBinaryView* newView); + public: enum NotificationType : uint64_t @@ -3206,6 +3208,7 @@ namespace BinaryNinja { UndoEntryAdded = 1ULL << 49, UndoEntryTaken = 1ULL << 50, RedoEntryTaken = 1ULL << 51, + Rebased = 1ULL << 52, BinaryDataUpdates = DataWritten | DataInserted | DataRemoved, FunctionLifetime = FunctionAdded | FunctionRemoved, @@ -3635,6 +3638,17 @@ namespace BinaryNinja { (void)data; (void)entry; } + + /*! This notification is posted whenever a binary view is rebased + + \param oldView BinaryView the old view + \param newView BinaryView the new view + */ + virtual void OnRebased(BinaryView* oldView, BinaryView* newView) + { + (void)oldView; + (void)newView; + } }; /*! diff --git a/binaryninjacore.h b/binaryninjacore.h index 9abf6d777..96ea6f5e5 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -1585,6 +1585,7 @@ extern "C" void (*undoEntryAdded)(void* ctxt, BNBinaryView* view, BNUndoEntry* entry); void (*undoEntryTaken)(void* ctxt, BNBinaryView* view, BNUndoEntry* entry); void (*redoEntryTaken)(void* ctxt, BNBinaryView* view, BNUndoEntry* entry); + void (*rebased)(void* ctxt, BNBinaryView* oldView, BNBinaryView* newView); } BNBinaryDataNotification; typedef struct BNProjectNotification diff --git a/binaryview.cpp b/binaryview.cpp index 68e6206be..0fd19d6df 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -523,6 +523,15 @@ void BinaryDataNotification::RedoEntryTakenCallback(void* ctxt, BNBinaryView* da } +void BinaryDataNotification::RebasedCallback(void *ctxt, BNBinaryView *oldView, BNBinaryView *newView) +{ + BinaryDataNotification* notify = (BinaryDataNotification*)ctxt; + Ref view1 = new BinaryView(BNNewViewReference(oldView)); + Ref view2 = new BinaryView(BNNewViewReference(newView)); + notify->OnRebased(view1, view2); +} + + BinaryDataNotification::BinaryDataNotification() { m_callbacks.context = this; @@ -578,6 +587,7 @@ BinaryDataNotification::BinaryDataNotification() m_callbacks.undoEntryAdded = UndoEntryAddedCallback; m_callbacks.undoEntryTaken = UndoEntryTakenCallback; m_callbacks.redoEntryTaken = RedoEntryTakenCallback; + m_callbacks.rebased = RebasedCallback; } @@ -636,6 +646,7 @@ BinaryDataNotification::BinaryDataNotification(NotificationTypes notifications) m_callbacks.undoEntryAdded = (notifications & NotificationType::UndoEntryAdded) ? UndoEntryAddedCallback : nullptr; m_callbacks.undoEntryTaken = (notifications & NotificationType::UndoEntryTaken) ? UndoEntryTakenCallback : nullptr; m_callbacks.redoEntryTaken = (notifications & NotificationType::RedoEntryTaken) ? RedoEntryTakenCallback : nullptr; + m_callbacks.rebased = (notifications & NotificationType::Rebased) ? RebasedCallback : nullptr; }