diff options
| author | Glenn Smith <glenn@vector35.com> | 2020-10-02 20:52:15 -0400 |
|---|---|---|
| committer | Glenn Smith <glenn@vector35.com> | 2020-10-14 21:06:52 -0400 |
| commit | 0de53b97ef6cec57ab4bdfbb9a9e1b6503eecfab (patch) | |
| tree | 553a07d8233b614b771569e12a75115d69963adc /examples/uinotification/uinotification.cpp | |
| parent | 02098f30b88f25953532cb4ae20c6c1161b74603 (diff) | |
UIContext notifications (eg file open/save)
Diffstat (limited to 'examples/uinotification/uinotification.cpp')
| -rw-r--r-- | examples/uinotification/uinotification.cpp | 95 |
1 files changed, 95 insertions, 0 deletions
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 <QMessageBox> + +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; + } +} |
