Skip to content

Commit

Permalink
Add a rebased callback for binary view
Browse files Browse the repository at this point in the history
  • Loading branch information
xusheng6 committed Jun 19, 2024
1 parent ed4effd commit da698e7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions binaryninjaapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
};

/*!
Expand Down
1 change: 1 addition & 0 deletions binaryninjacore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions binaryview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BinaryView> view1 = new BinaryView(BNNewViewReference(oldView));
Ref<BinaryView> view2 = new BinaryView(BNNewViewReference(newView));
notify->OnRebased(view1, view2);
}


BinaryDataNotification::BinaryDataNotification()
{
m_callbacks.context = this;
Expand Down Expand Up @@ -578,6 +587,7 @@ BinaryDataNotification::BinaryDataNotification()
m_callbacks.undoEntryAdded = UndoEntryAddedCallback;
m_callbacks.undoEntryTaken = UndoEntryTakenCallback;
m_callbacks.redoEntryTaken = RedoEntryTakenCallback;
m_callbacks.rebased = RebasedCallback;
}


Expand Down Expand Up @@ -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;
}


Expand Down

0 comments on commit da698e7

Please sign in to comment.