diff options
| -rw-r--r-- | binaryninjaapi.h | 6 | ||||
| -rw-r--r-- | binaryninjacore.h | 27 | ||||
| -rw-r--r-- | interaction.cpp | 16 | ||||
| -rw-r--r-- | python/__init__.py | 13 |
4 files changed, 62 insertions, 0 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 720a8eb6..7e496591 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -402,6 +402,9 @@ namespace BinaryNinja const std::string& defaultName = ""); bool GetDirectoryNameInput(std::string& result, const std::string& prompt, const std::string& defaultName = ""); + BNMessageBoxButtonResult ShowMessageBox(const std::string& title, const std::string& text, + BNMessageBoxButtonSet buttons = OKButtonSet, BNMessageBoxIcon icon = InformationIcon); + class DataBuffer { BNDataBuffer* m_buffer; @@ -2328,5 +2331,8 @@ namespace BinaryNinja const std::string& ext = "", const std::string& defaultName = ""); virtual bool GetDirectoryNameInput(std::string& result, const std::string& prompt, const std::string& defaultName = ""); + + virtual BNMessageBoxButtonResult ShowMessageBox(const std::string& title, const std::string& text, + BNMessageBoxButtonSet buttons = OKButtonSet, BNMessageBoxIcon icon = InformationIcon) = 0; }; } diff --git a/binaryninjacore.h b/binaryninjacore.h index 084fd34d..6339b1c3 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -1050,6 +1050,29 @@ extern "C" uint8_t mix, r, g, b, alpha; }; + enum BNMessageBoxIcon + { + InformationIcon, + QuestionIcon, + WarningIcon, + ErrorIcon + }; + + enum BNMessageBoxButtonSet + { + OKButtonSet, + YesNoButtonSet, + YesNoCancelButtonSet + }; + + enum BNMessageBoxButtonResult + { + NoButton = 0, + YesButton = 1, + OKButton = 2, + CancelButton = 3 + }; + struct BNInteractionHandlerCallbacks { void* context; @@ -1068,6 +1091,8 @@ extern "C" bool (*getSaveFileNameInput)(void* ctxt, char** result, const char* prompt, const char* ext, const char* defaultName); bool (*getDirectoryNameInput)(void* ctxt, char** result, const char* prompt, const char* defaultName); + BNMessageBoxButtonResult (*showMessageBox)(void* ctxt, const char* title, const char* text, + BNMessageBoxButtonSet buttons, BNMessageBoxIcon icon); }; struct BNObjectDestructionCallbacks @@ -2082,6 +2107,8 @@ extern "C" BINARYNINJACOREAPI bool BNGetSaveFileNameInput(char** result, const char* prompt, const char* ext, const char* defaultName); BINARYNINJACOREAPI bool BNGetDirectoryNameInput(char** result, const char* prompt, const char* defaultName); + BINARYNINJACOREAPI BNMessageBoxButtonResult BNShowMessageBox(const char* title, const char* text, + BNMessageBoxButtonSet buttons, BNMessageBoxIcon icon); #ifdef __cplusplus } diff --git a/interaction.cpp b/interaction.cpp index f7763679..432859d9 100644 --- a/interaction.cpp +++ b/interaction.cpp @@ -172,6 +172,14 @@ static bool GetDirectoryNameInputCallback(void* ctxt, char** result, const char* } +static BNMessageBoxButtonResult ShowMessageBoxCallback(void* ctxt, const char* title, const char* text, + BNMessageBoxButtonSet buttons, BNMessageBoxIcon icon) +{ + InteractionHandler* handler = (InteractionHandler*)ctxt; + return handler->ShowMessageBox(title, text, buttons, icon); +} + + void BinaryNinja::RegisterInteractionHandler(InteractionHandler* handler) { BNInteractionHandlerCallbacks cb; @@ -186,6 +194,7 @@ void BinaryNinja::RegisterInteractionHandler(InteractionHandler* handler) cb.getOpenFileNameInput = GetOpenFileNameInputCallback; cb.getSaveFileNameInput = GetSaveFileNameInputCallback; cb.getDirectoryNameInput = GetDirectoryNameInputCallback; + cb.showMessageBox = ShowMessageBoxCallback; BNRegisterInteractionHandler(&cb); } @@ -284,3 +293,10 @@ bool BinaryNinja::GetDirectoryNameInput(string& result, const string& prompt, co BNFreeString(value); return true; } + + +BNMessageBoxButtonResult BinaryNinja::ShowMessageBox(const string& title, const string& text, + BNMessageBoxButtonSet buttons, BNMessageBoxIcon icon) +{ + return BNShowMessageBox(title.c_str(), text.c_str(), buttons, icon); +} diff --git a/python/__init__.py b/python/__init__.py index 23059068..c8880648 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -10193,6 +10193,7 @@ class InteractionHandler(object): self._cb.getOpenFileNameInput = self._cb.getOpenFileNameInput.__class__(self._get_open_filename_input) self._cb.getSaveFileNameInput = self._cb.getSaveFileNameInput.__class__(self._get_save_filename_input) self._cb.getDirectoryNameInput = self._cb.getDirectoryNameInput.__class__(self._get_directory_name_input) + self._cb.showMessageBox = self._cb.showMessageBox.__class__(self._show_message_box) def register(self): self.__class__._interaction_handler = self @@ -10305,6 +10306,12 @@ class InteractionHandler(object): except: log_error(traceback.format_exc()) + def _show_message_box(self, ctxt, title, text, buttons, icon): + try: + return self.show_message_box(title, text, buttons, icon) + except: + log_error(traceback.format_exc()) + def show_plain_text_report(self, view, title, contents): pass @@ -10343,6 +10350,9 @@ class InteractionHandler(object): def get_directory_name_input(self, prompt, default_name): return get_text_line_input(title, "Select Directory") + def show_message_box(self, title, text, buttons, icon): + return CancelButton + class _DestructionCallbackHandler: def __init__(self): self._cb = core.BNObjectDestructionCallbacks() @@ -10743,6 +10753,9 @@ def get_directory_name_input(prompt, default_name = ""): core.BNFreeString(ctypes.cast(value, ctypes.POINTER(ctypes.c_byte))) return result +def show_message_box(title, text, buttons = core.OKButtonSet, icon = core.InformationIcon): + return core.BNShowMessageBox(title, text, buttons, icon) + bundled_plugin_path = core.BNGetBundledPluginDirectory() user_plugin_path = core.BNGetUserPluginDirectory() |
