Skip to content

Commit

Permalink
Various fixes for recently added BinaryDataNotifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
bpotchik committed Apr 10, 2024
1 parent 6a30286 commit cb4f924
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 21 deletions.
20 changes: 12 additions & 8 deletions binaryninjaapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -3160,11 +3160,11 @@ namespace BinaryNinja {
ComponentDataVariableAdded = 1ULL << 37,
ComponentDataVariableRemoved = 1ULL << 38,
ExternalLibraryAdded = 1ULL << 39,
ExternalLibraryUpdated = 1ULL << 40,
ExternalLibraryRemoved = 1ULL << 41,
ExternalLibraryRemoved = 1ULL << 40,
ExternalLibraryUpdated = 1ULL << 41,
ExternalLocationAdded = 1ULL << 42,
ExternalLocationUpdated = 1ULL << 43,
ExternalLocationRemoved = 1ULL << 44,
ExternalLocationRemoved = 1ULL << 43,
ExternalLocationUpdated = 1ULL << 44,
TypeArchiveAttached = 1ULL << 45,
TypeArchiveDetached = 1ULL << 46,
TypeArchiveConnected = 1ULL << 47,
Expand All @@ -3187,6 +3187,10 @@ namespace BinaryNinja {
SectionLifetime = SectionAdded | SectionRemoved,
SectionUpdates = SectionLifetime | SectionUpdated,
ComponentUpdates = ComponentNameUpdated | ComponentAdded | ComponentRemoved | ComponentMoved | ComponentFunctionAdded | ComponentFunctionRemoved | ComponentDataVariableAdded | ComponentDataVariableRemoved,
ExternalLibraryLifetime = ExternalLibraryAdded | ExternalLibraryRemoved,
ExternalLibraryUpdates = ExternalLibraryLifetime | ExternalLibraryUpdated,
ExternalLocationLifetime = ExternalLocationAdded | ExternalLocationRemoved,
ExternalLocationUpdates = ExternalLocationLifetime | ExternalLocationUpdated,
TypeArchiveUpdates = TypeArchiveAttached | TypeArchiveDetached | TypeArchiveConnected | TypeArchiveDisconnected
};

Expand Down Expand Up @@ -3483,13 +3487,13 @@ namespace BinaryNinja {
(void)library;
}

virtual void OnExternalLibraryUpdated(BinaryView* data, ExternalLibrary* library)
virtual void OnExternalLibraryRemoved(BinaryView* data, ExternalLibrary* library)
{
(void)data;
(void)library;
}

virtual void OnExternalLibraryRemoved(BinaryView* data, ExternalLibrary* library)
virtual void OnExternalLibraryUpdated(BinaryView* data, ExternalLibrary* library)
{
(void)data;
(void)library;
Expand All @@ -3501,13 +3505,13 @@ namespace BinaryNinja {
(void)location;
}

virtual void OnExternalLocationUpdated(BinaryView* data, ExternalLocation* location)
virtual void OnExternalLocationRemoved(BinaryView* data, ExternalLocation* location)
{
(void)data;
(void)location;
}

virtual void OnExternalLocationRemoved(BinaryView* data, ExternalLocation* location)
virtual void OnExternalLocationUpdated(BinaryView* data, ExternalLocation* location)
{
(void)data;
(void)location;
Expand Down
4 changes: 2 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 58
#define BN_CURRENT_CORE_ABI_VERSION 59

// 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 58
#define BN_MINIMUM_CORE_ABI_VERSION 59

#ifdef __GNUC__
#ifdef BINARYNINJACORE_LIBRARY
Expand Down
23 changes: 17 additions & 6 deletions python/binaryview.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,17 @@ class NotificationType(IntFlag):
ComponentFunctionRemoved = 1 << 36
ComponentDataVariableAdded = 1 << 37
ComponentDataVariableRemoved = 1 << 38
TypeArchiveAttached = 1 << 39
TypeArchiveDetached = 1 << 40
TypeArchiveConnected = 1 << 41
TypeArchiveDisconnected = 1 << 42
ExternalLibraryAdded = 1 << 39
ExternalLibraryRemoved = 1 << 40
ExternalLibraryUpdated = 1 << 41
ExternalLocationAdded = 1 << 42
ExternalLocationRemoved = 1 << 43
ExternalLocationUpdated = 1 << 44
TypeArchiveAttached = 1 << 45
TypeArchiveDetached = 1 << 46
TypeArchiveConnected = 1 << 47
TypeArchiveDisconnected = 1 << 48

BinaryDataUpdates = DataWritten | DataInserted | DataRemoved
FunctionLifetime = FunctionAdded | FunctionRemoved
FunctionUpdates = FunctionLifetime | FunctionUpdated
Expand All @@ -195,8 +202,12 @@ class NotificationType(IntFlag):
SegmentUpdates = SegmentLifetime | SegmentUpdated
SectionLifetime = SectionAdded | SectionRemoved
SectionUpdates = SectionLifetime | SectionUpdated
ComponentUpdates = (ComponentAdded | ComponentRemoved | ComponentMoved | ComponentFunctionAdded | ComponentFunctionRemoved | ComponentDataVariableAdded | ComponentDataVariableRemoved)
TypeArchiveUpdates = (TypeArchiveAttached | TypeArchiveDetached | TypeArchiveConnected | TypeArchiveDisconnected)
ComponentUpdates = ComponentAdded | ComponentRemoved | ComponentMoved | ComponentFunctionAdded | ComponentFunctionRemoved | ComponentDataVariableAdded | ComponentDataVariableRemoved
ExternalLibraryLifetime = ExternalLibraryAdded | ExternalLibraryRemoved
ExternalLibraryUpdates = ExternalLibraryLifetime | ExternalLibraryUpdated
ExternalLocationLifetime = ExternalLocationAdded | ExternalLocationRemoved
ExternalLocationUpdates = ExternalLocationLifetime | ExternalLocationUpdated
TypeArchiveUpdates = TypeArchiveAttached | TypeArchiveDetached | TypeArchiveConnected | TypeArchiveDisconnected


class BinaryDataNotification:
Expand Down
37 changes: 32 additions & 5 deletions ui/notificationsdispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ class NotificationEvent
ComponentInfo(BinaryNinja::Component* component, const BinaryNinja::DataVariable& dataVar) : component(component), dataVar(dataVar) {};
};

struct TypeArchiveInfo
{
std::string id;
std::string path;

TypeArchiveInfo() {};
TypeArchiveInfo(const std::string& id, const std::string& path) : id(id), path(path) {};
};

private:
using NotificationType = BinaryNinja::BinaryDataNotification::NotificationType;
using NotificationTypes = BinaryNinja::BinaryDataNotification::NotificationTypes;
Expand All @@ -117,21 +126,26 @@ class NotificationEvent
SymbolRef m_symbol;
std::unique_ptr<SymbolInfo> m_symbolInfo;
std::variant<std::monostate, BinaryDataChangeInfo, FunctionRef, BinaryNinja::DataVariable, TagTypeRef,
BinaryNinja::TagReference, StringInfo, TypeChangeInfo, SegmentRef, SectionRef, ComponentInfo> m_object;
BinaryNinja::TagReference, StringInfo, TypeChangeInfo, SegmentRef, SectionRef, ComponentInfo,
ExternalLibraryRef, ExternalLocationRef, TypeArchiveInfo, TypeArchiveRef> m_object;

public:
NotificationEvent(NotificationType source): m_source(source) { }
NotificationEvent(NotificationType source, BinaryNinja::Symbol* symbol): m_source(source), m_symbol(symbol) { }
NotificationEvent(NotificationType source, const BinaryDataChangeInfo& binaryDataChange): m_source(source), m_object(binaryDataChange) { }
NotificationEvent(NotificationType source, BinaryDataChangeInfo&& binaryDataChange): m_source(source), m_object(std::move(binaryDataChange)) { }
NotificationEvent(NotificationType source, BinaryNinja::Function* function): m_source(source), m_object(function) { }
NotificationEvent(NotificationType source, const BinaryNinja::DataVariable& dataVariable): m_source(source), m_object(dataVariable) { }
NotificationEvent(NotificationType source, BinaryNinja::TagType* tagType): m_source(source), m_object(tagType) { }
NotificationEvent(NotificationType source, const BinaryNinja::TagReference& tagRef): m_source(source), m_object(tagRef) { }
NotificationEvent(NotificationType source, const StringInfo& stringInfo): m_source(source), m_object(stringInfo) { }
NotificationEvent(NotificationType source, const TypeChangeInfo& typeChangeInfo): m_source(source), m_object(typeChangeInfo) { }
NotificationEvent(NotificationType source, StringInfo&& stringInfo): m_source(source), m_object(std::move(stringInfo)) { }
NotificationEvent(NotificationType source, TypeChangeInfo&& typeChangeInfo): m_source(source), m_object(std::move(typeChangeInfo)) { }
NotificationEvent(NotificationType source, BinaryNinja::Segment* segment): m_source(source), m_object(segment) { }
NotificationEvent(NotificationType source, BinaryNinja::Section* section): m_source(source), m_object(section) { }
NotificationEvent(NotificationType source, const ComponentInfo& componentInfo): m_source(source), m_object(componentInfo) { }
NotificationEvent(NotificationType source, ComponentInfo&& componentInfo): m_source(source), m_object(std::move(componentInfo)) { }
NotificationEvent(NotificationType source, BinaryNinja::ExternalLibrary* library): m_source(source), m_object(library) { }
NotificationEvent(NotificationType source, BinaryNinja::ExternalLocation* location): m_source(source), m_object(location) { }
NotificationEvent(NotificationType source, TypeArchiveInfo&& typeArchiveInfo): m_source(source), m_object(std::move(typeArchiveInfo)) { }
NotificationEvent(NotificationType source, BinaryNinja::TypeArchive* archive): m_source(source), m_object(archive) { }

void cacheSymbolInfo();
SymbolInfo* getSymbolInfo() const { return m_symbolInfo.get(); }
Expand Down Expand Up @@ -270,6 +284,19 @@ class NotificationsWorker: public QThread, public BinaryNinja::BinaryDataNotific
void OnComponentFunctionRemoved(BinaryNinja::BinaryView* view, BinaryNinja::Component* component, BinaryNinja::Function* func) override;
void OnComponentDataVariableAdded(BinaryNinja::BinaryView* view, BinaryNinja::Component* component, const BinaryNinja::DataVariable& var) override;
void OnComponentDataVariableRemoved(BinaryNinja::BinaryView* view, BinaryNinja::Component* component, const BinaryNinja::DataVariable& var) override;

void OnExternalLibraryAdded(BinaryNinja::BinaryView* data, BinaryNinja::ExternalLibrary* library) override;
void OnExternalLibraryRemoved(BinaryNinja::BinaryView* data, BinaryNinja::ExternalLibrary* library) override;
void OnExternalLibraryUpdated(BinaryNinja::BinaryView* data, BinaryNinja::ExternalLibrary* library) override;

void OnExternalLocationAdded(BinaryNinja::BinaryView* data, BinaryNinja::ExternalLocation* location) override;
void OnExternalLocationRemoved(BinaryNinja::BinaryView* data, BinaryNinja::ExternalLocation* location) override;
void OnExternalLocationUpdated(BinaryNinja::BinaryView* data, BinaryNinja::ExternalLocation* location) override;

void OnTypeArchiveAttached(BinaryNinja::BinaryView* data, const std::string& id, const std::string& path) override;
void OnTypeArchiveDetached(BinaryNinja::BinaryView* data, const std::string& id, const std::string& path) override;
void OnTypeArchiveConnected(BinaryNinja::BinaryView* data, BinaryNinja::TypeArchive* archive) override;
void OnTypeArchiveDisconnected(BinaryNinja::BinaryView* data, BinaryNinja::TypeArchive* archive) override;
};


Expand Down

0 comments on commit cb4f924

Please sign in to comment.