From 0de53b97ef6cec57ab4bdfbb9a9e1b6503eecfab Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Fri, 2 Oct 2020 20:52:15 -0400 Subject: UIContext notifications (eg file open/save) --- examples/uinotification/uinotification.cpp | 95 ++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 examples/uinotification/uinotification.cpp (limited to 'examples/uinotification/uinotification.cpp') diff --git a/examples/uinotification/uinotification.cpp b/examples/uinotification/uinotification.cpp new file mode 100644 index 00000000..f9d1da39 --- /dev/null +++ b/examples/uinotification/uinotification.cpp @@ -0,0 +1,95 @@ +#include "uinotification.h" +#include "filecontext.h" +#include "viewframe.h" +#include + +using namespace BinaryNinja; + +NotificationListener* NotificationListener::m_instance = nullptr; + +void NotificationListener::init() +{ + m_instance = new NotificationListener; + UIContext::registerNotification(m_instance); +} + + +void NotificationListener::OnContextOpen(UIContext* context) +{ + LogInfo("OnContextOpen"); +} + + +void NotificationListener::OnContextClose(UIContext* context) +{ + LogInfo("OnContextClose"); +} + + +bool NotificationListener::OnBeforeOpenDatabase(UIContext* context, FileMetadataRef metadata) +{ + LogInfo("OnBeforeOpenDatabase"); + return QMessageBox::question(context->mainWindow(), "OnBeforeOpenDatabase", "OnBeforeOpenDatabase") == QMessageBox::StandardButton::Yes; +} + + +bool NotificationListener::OnAfterOpenDatabase(UIContext* context, FileMetadataRef metadata, BinaryViewRef data) +{ + LogInfo("OnAfterOpenDatabase"); + return QMessageBox::question(context->mainWindow(), "OnAfterOpenDatabase", "OnAfterOpenDatabase") == QMessageBox::StandardButton::Yes; +} + + +bool NotificationListener::OnBeforeOpenFile(UIContext* context, FileContext* file) +{ + LogInfo("OnBeforeOpenFile"); + return QMessageBox::question(context->mainWindow(), "OnBeforeOpenFile", "OnBeforeOpenFile") == QMessageBox::StandardButton::Yes; +} + + +void NotificationListener::OnAfterOpenFile(UIContext* context, FileContext* file, ViewFrame* frame) +{ + LogInfo("OnAfterOpenFile"); +} + + +bool NotificationListener::OnBeforeSaveFile(UIContext* context, FileContext* file, ViewFrame* frame) +{ + LogInfo("OnBeforeSaveFile"); + return QMessageBox::question(context->mainWindow(), "OnBeforeSaveFile", "OnBeforeSaveFile") == QMessageBox::StandardButton::Yes; +} + + +void NotificationListener::OnAfterSaveFile(UIContext* context, FileContext* file, ViewFrame* frame) +{ + LogInfo("OnAfterSaveFile"); +} + + +bool NotificationListener::OnBeforeCloseFile(UIContext* context, FileContext* file, ViewFrame* frame) +{ + LogInfo("OnBeforeCloseFile"); + return QMessageBox::question(context->mainWindow(), "OnBeforeCloseFile", "OnBeforeCloseFile") == QMessageBox::StandardButton::Yes; +} + + +void NotificationListener::OnAfterCloseFile(UIContext* context, FileContext* file, ViewFrame* frame) +{ + LogInfo("OnAfterCloseFile"); +} + + +void NotificationListener::OnViewChange(UIContext* context, ViewFrame* frame, const QString& type) +{ + LogInfo("OnViewChange"); +} + + +extern "C" +{ + BINARYNINJAPLUGIN bool UIPluginInit() + { + NotificationListener::init(); + return true; + } +} -- cgit v1.3.1