Source code for binaryninja.interaction

# Copyright (c) 2015-2019 Vector 35 Inc## Permission is hereby granted, free of charge, to any person obtaining a copy# of this software and associated documentation files (the "Software"), to# deal in the Software without restriction, including without limitation the# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or# sell copies of the Software, and to permit persons to whom the Software is# furnished to do so, subject to the following conditions:## The above copyright notice and this permission notice shall be included in# all copies or substantial portions of the Software.## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS# IN THE SOFTWARE.importctypesimporttraceback# Binary Ninja componentsfrombinaryninjaimport_binaryninjacoreascorefrombinaryninja.enumsimportFormInputFieldType,MessageBoxIcon,MessageBoxButtonSet,MessageBoxButtonResult,ReportTypefrombinaryninjaimportbinaryviewfrombinaryninjaimportlogfrombinaryninjaimportflowgraph# 2-3 compatibilityfrombinaryninjaimportrange

[docs]classLabelField(object):""" ``LabelField`` adds a text label to the display. """

[docs]classMultilineTextField(object):""" ``MultilineTextField`` add multi-line text string input field. Result is stored in self.result as a string. This option is not supported on the command-line. """

[docs]classAddressField(object):""" ``AddressField`` prompts the user for an address. By passing the optional view and current_address parameters offsets can be used instead of just an address. The result is stored as in int in self.result. Note: This API currently functions differently on the command-line, as the view and current_address are disregarded. Additionally where as in the UI the result defaults to hexadecimal on the command-line 0x must be specified. """

[docs]classChoiceField(object):""" ``ChoiceField`` prompts the user to choose from the list of strings provided in ``choices``. Result is stored in self.result as an index in to the choices array. :attr str prompt: prompt to be presented to the user :attr list(str) choices: list of choices to choose from """

[docs]defshow_plain_text_report(title,contents):""" ``show_plain_text_report`` displays contents to the user in the UI or on the command-line. Note: This API function differently on the command-line vs the UI. In the UI a pop-up is used. On the command-line a simple text prompt is used. :param str title: title to display in the UI pop-up. :param str contents: plaintext contents to display :rtype: None :Example: >>> show_plain_text_report("title", "contents") contents """core.BNShowPlainTextReport(None,title,contents)

[docs]defshow_markdown_report(title,contents,plaintext=""):""" ``show_markdown_report`` displays the markdown contents in UI applications and plaintext in command-line applications. This API doesn't support hyperlinking into the BinaryView, use the BinaryView.show_markdown_report if hyperlinking is needed. Note: This API function differently on the command-line vs the UI. In the UI a pop-up is used. On the command-line a simple text prompt is used. :param str contents: markdown contents to display :param str plaintext: Plain text version to display (used on the command-line) :rtype: None :Example: >>> show_markdown_report("title", "##Contents", "Plain text contents") Plain text contents """core.BNShowMarkdownReport(None,title,contents,plaintext)

[docs]defshow_html_report(title,contents,plaintext=""):""" ``show_html_report`` displays the HTML contents in UI applications and plaintext in command-line applications. This API doesn't support hyperlinking into the BinaryView, use the BinaryView.show_html_report if hyperlinking is needed. Note: This API function differently on the command-line vs the UI. In the UI a pop-up is used. On the command-line a simple text prompt is used. :param str contents: HTML contents to display :param str plaintext: Plain text version to display (used on the command-line) :rtype: None :Example: >>> show_html_report("title", "<h1>Contents</h1>", "Plain text contents") Plain text contents """core.BNShowHTMLReport(None,title,contents,plaintext)

[docs]defget_text_line_input(prompt,title):""" ``get_text_line_input`` prompts the user to input a string with the given prompt and title. Note: This API function differently on the command-line vs the UI. In the UI a pop-up is used. On the command-line a simple text prompt is used. :param str prompt: String to prompt with. :param str title: Title of the window when executed in the UI. :rtype: string containing the input without trailing newline character. :Example: >>> get_text_line_input("PROMPT>", "getinfo") PROMPT> Input! 'Input!' """value=ctypes.c_char_p()ifnotcore.BNGetTextLineInput(value,prompt,title):returnNoneresult=value.valuecore.BNFreeString(ctypes.cast(value,ctypes.POINTER(ctypes.c_byte)))returnresult

[docs]defget_int_input(prompt,title):""" ``get_int_input`` prompts the user to input a integer with the given prompt and title. Note: This API function differently on the command-line vs the UI. In the UI a pop-up is used. On the command-line a simple text prompt is used. :param str prompt: String to prompt with. :param str title: Title of the window when executed in the UI. :rtype: integer value input by the user. :Example: >>> get_int_input("PROMPT>", "getinfo") PROMPT> 10 10 """value=ctypes.c_longlong()ifnotcore.BNGetIntegerInput(value,prompt,title):returnNonereturnvalue.value

[docs]defget_address_input(prompt,title):""" ``get_address_input`` prompts the user for an address with the given prompt and title. Note: This API function differently on the command-line vs the UI. In the UI a pop-up is used. On the command-line a simple text prompt is used. :param str prompt: String to prompt with. :param str title: Title of the window when executed in the UI. :rtype: integer value input by the user. :Example: >>> get_address_input("PROMPT>", "getinfo") PROMPT> 10 10L """value=ctypes.c_ulonglong()ifnotcore.BNGetAddressInput(value,prompt,title,None,0):returnNonereturnvalue.value

[docs]defget_choice_input(prompt,title,choices):""" ``get_choice_input`` prompts the user to select the one of the provided choices. Note: This API function differently on the command-line vs the UI. In the UI a pop-up is used. On the command-line a simple text prompt is used. The UI uses a combo box. :param str prompt: String to prompt with. :param str title: Title of the window when executed in the UI. :param list choices: A list of strings for the user to choose from. :rtype: integer array index of the selected option :Example: >>> get_choice_input("PROMPT>", "choices", ["Yes", "No", "Maybe"]) choices 1) Yes 2) No 3) Maybe PROMPT> 1 0L """choice_buf=(ctypes.c_char_p*len(choices))()foriinrange(0,len(choices)):choice_buf[i]=str(choices[i]).encode('charmap')value=ctypes.c_ulonglong()ifnotcore.BNGetChoiceInput(value,prompt,title,choice_buf,len(choices)):returnNonereturnvalue.value

[docs]defget_open_filename_input(prompt,ext=""):""" ``get_open_filename_input`` prompts the user for a file name to open. Note: This API function differently on the command-line vs the UI. In the UI a pop-up is used. On the command-line a simple text prompt is used. The UI uses the native window pop-up for file selection. :param str prompt: Prompt to display. :param str ext: Optional, file extension :Example: >>> get_open_filename_input("filename:", "exe") filename: foo.exe 'foo.exe' """value=ctypes.c_char_p()ifnotcore.BNGetOpenFileNameInput(value,prompt,ext):returnNoneresult=value.valuecore.BNFreeString(ctypes.cast(value,ctypes.POINTER(ctypes.c_byte)))returnresult

[docs]defshow_message_box(title,text,buttons=MessageBoxButtonSet.OKButtonSet,icon=MessageBoxIcon.InformationIcon):""" ``show_message_box`` Displays a configurable message box in the UI, or prompts on the console as appropriate retrieves a list of all Symbol objects of the provided symbol type in the optionally provided range. :param str title: Text title for the message box. :param str text: Text for the main body of the message box. :param MessageBoxButtonSet buttons: One of :py:class:`MessageBoxButtonSet` :param MessageBoxIcon icon: One of :py:class:`MessageBoxIcon` :return: Which button was selected :rtype: MessageBoxButtonResult """returncore.BNShowMessageBox(title,text,buttons,icon)