diff options
| author | Rusty Wagner <rusty@vector35.com> | 2018-07-26 16:02:26 -0400 |
|---|---|---|
| committer | Rusty Wagner <rusty@vector35.com> | 2018-07-26 16:18:02 -0400 |
| commit | 6eb3234d924d870641ee30c4263437f1d8a8d5c7 (patch) | |
| tree | b64815c5e0a2c3b1a10a3e3dcab4c786fdd85c34 /python/interaction.py | |
| parent | c5c93fc82b8929d04f62d241ca50228de60fa5f4 (diff) | |
| parent | 1f986c2698ff9df6d42429b1b7699842223634e5 (diff) | |
Merge branch 'dev' into test_stack_adjust
Diffstat (limited to 'python/interaction.py')
| -rw-r--r-- | python/interaction.py | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/python/interaction.py b/python/interaction.py index b9aa0c2a..0170e6aa 100644 --- a/python/interaction.py +++ b/python/interaction.py @@ -22,11 +22,14 @@ import ctypes import traceback # Binary Ninja components -import _binaryninjacore as core -from enums import FormInputFieldType, MessageBoxIcon, MessageBoxButtonSet, MessageBoxButtonResult, ReportType -import binaryview -import log -import flowgraph +from binaryninja import _binaryninjacore as core +from binaryninja.enums import FormInputFieldType, MessageBoxIcon, MessageBoxButtonSet, MessageBoxButtonResult +from binaryninja import binaryview +from binaryninja import log +from binaryninja import flowgraph + +# 2-3 compatibility +from binaryninja import range class LabelField(object): @@ -152,7 +155,11 @@ class AddressField(object): class ChoiceField(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 coices array. + 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 + """ def __init__(self, prompt, choices): self.prompt = prompt @@ -163,8 +170,8 @@ class ChoiceField(object): value.type = FormInputFieldType.ChoiceFormField value.prompt = self.prompt choice_buf = (ctypes.c_char_p * len(self.choices))() - for i in xrange(0, len(self.choices)): - choice_buf[i] = str(self.choices[i]) + for i in range(0, len(self.choices)): + choice_buf[i] = self.choices[i].encode('charmap') value.choices = choice_buf value.count = len(self.choices) @@ -349,7 +356,7 @@ class InteractionHandler(object): def _get_choice_input(self, ctxt, result, prompt, title, choice_buf, count): try: choices = [] - for i in xrange(0, count): + for i in range(0, count): choices.append(choice_buf[i]) value = self.get_choice_input(prompt, title, choices) if value is None: @@ -392,7 +399,7 @@ class InteractionHandler(object): def _get_form_input(self, ctxt, fields, count, title): try: field_objs = [] - for i in xrange(0, count): + for i in range(0, count): if fields[i].type == FormInputFieldType.LabelFormField: field_objs.append(LabelField(fields[i].prompt)) elif fields[i].type == FormInputFieldType.SeparatorFormField: @@ -410,7 +417,7 @@ class InteractionHandler(object): field_objs.append(AddressField(fields[i].prompt, view, fields[i].currentAddress)) elif fields[i].type == FormInputFieldType.ChoiceFormField: choices = [] - for j in xrange(0, fields[i].count): + for j in range(0, fields[i].count): choices.append(fields[i].choices[j]) field_objs.append(ChoiceField(fields[i].prompt, choices)) elif fields[i].type == FormInputFieldType.OpenFileNameFormField: @@ -423,7 +430,7 @@ class InteractionHandler(object): field_objs.append(LabelField(fields[i].prompt)) if not self.get_form_input(field_objs, title): return False - for i in xrange(0, count): + for i in range(0, count): field_objs[i]._fill_core_result(fields[i]) return True except: @@ -783,8 +790,8 @@ def get_choice_input(prompt, title, choices): 0L """ choice_buf = (ctypes.c_char_p * len(choices))() - for i in xrange(0, len(choices)): - choice_buf[i] = str(choices[i]) + for i in range(0, len(choices)): + choice_buf[i] = str(choices[i]).encode('charmap') value = ctypes.c_ulonglong() if not core.BNGetChoiceInput(value, prompt, title, choice_buf, len(choices)): return None @@ -839,11 +846,9 @@ def get_save_filename_input(prompt, ext="", default_name=""): def get_directory_name_input(prompt, default_name=""): """ - ``get_directory_name_input`` prompts the user for a directory name to save as, optionally providing and - default_name. + ``get_directory_name_input`` prompts the user for a directory name to save as, optionally providing a default_name. - Note: This API function differently on the command line vs. the UI. In the UI a popup is used. On the commandline - a simple text prompt is used. The ui uses the native window popup for file selection. + Note: This API function differently on the command line vs. the UI. In the UI a popup is used. On the commandline a simple text prompt is used. The ui uses the native window popup for file selection. :param str prompt: Prompt to display. :param str default_name: Optional, default directory name. @@ -896,11 +901,11 @@ def get_form_input(fields, title): 3) Maybe Options 1 >>> True - >>> print tex_f.result, int_f.result, choice_f.result + >>> print(tex_f.result, int_f.result, choice_f.result) Peter 1337 0 """ value = (core.BNFormInputField * len(fields))() - for i in xrange(0, len(fields)): + for i in range(0, len(fields)): if isinstance(fields[i], str): LabelField(fields[i])._fill_core_struct(value[i]) elif fields[i] is None: @@ -909,7 +914,7 @@ def get_form_input(fields, title): fields[i]._fill_core_struct(value[i]) if not core.BNGetFormInput(value, len(fields), title): return False - for i in xrange(0, len(fields)): + for i in range(0, len(fields)): if not (isinstance(fields[i], str) or (fields[i] is None)): fields[i]._get_result(value[i]) core.BNFreeFormInputResults(value, len(fields)) |
