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 | |
| parent | 02098f30b88f25953532cb4ae20c6c1161b74603 (diff) | |
UIContext notifications (eg file open/save)
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | examples/uinotification/CMakeLists.txt | 24 | ||||
| -rw-r--r-- | examples/uinotification/uinotification.cpp | 95 | ||||
| -rw-r--r-- | examples/uinotification/uinotification.h | 22 |
4 files changed, 142 insertions, 0 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 10ff05da..764ba0c4 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -4,4 +4,5 @@ add_subdirectory(cmdline_disasm) add_subdirectory(llil_parser) add_subdirectory(mlil_parser) add_subdirectory(print_syscalls) +add_subdirectory(uinotification) add_subdirectory(x86_extension) diff --git a/examples/uinotification/CMakeLists.txt b/examples/uinotification/CMakeLists.txt new file mode 100644 index 00000000..6af09269 --- /dev/null +++ b/examples/uinotification/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 3.13 FATAL_ERROR) + +project(uinotification) + +file(GLOB SOURCES + *.cpp + *.h) + +add_library(uinotification SHARED ${SOURCES}) +target_link_libraries(uinotification binaryninjaapi binaryninjaui) + +set_target_properties(uinotification PROPERTIES + CXX_STANDARD 17 + CXX_VISIBILITY_PRESET hidden + CXX_STANDARD_REQUIRED ON + VISIBILITY_INLINES_HIDDEN ON + POSITION_INDEPENDENT_CODE ON + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../bin) + +if(BN_INTERNAL_BUILD) + ui_plugin_rpath(uinotification) +endif() + +bn_install_plugin(${PROJECT_NAME}) 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; + } +} diff --git a/examples/uinotification/uinotification.h b/examples/uinotification/uinotification.h new file mode 100644 index 00000000..a26b3de3 --- /dev/null +++ b/examples/uinotification/uinotification.h @@ -0,0 +1,22 @@ +#pragma once + +#include "uicontext.h" + +class NotificationListener: UIContextNotification +{ + static NotificationListener* m_instance; +public: + virtual void OnContextOpen(UIContext* context) override; + virtual void OnContextClose(UIContext* context) override; + virtual bool OnBeforeOpenDatabase(UIContext* context, FileMetadataRef metadata) override; + virtual bool OnAfterOpenDatabase(UIContext* context, FileMetadataRef metadata, BinaryViewRef data) override; + virtual bool OnBeforeOpenFile(UIContext* context, FileContext* file) override; + virtual void OnAfterOpenFile(UIContext* context, FileContext* file, ViewFrame* frame) override; + virtual bool OnBeforeSaveFile(UIContext* context, FileContext* file, ViewFrame* frame) override; + virtual void OnAfterSaveFile(UIContext* context, FileContext* file, ViewFrame* frame) override; + virtual bool OnBeforeCloseFile(UIContext* context, FileContext* file, ViewFrame* frame) override; + virtual void OnAfterCloseFile(UIContext* context, FileContext* file, ViewFrame* frame) override; + virtual void OnViewChange(UIContext* context, ViewFrame* frame, const QString& type) override; + + static void init(); +};
\ No newline at end of file |
