Skip to content

Commit ffb7677

Browse files
authored
Add default param to ask_string API (#191)
* bump * Add default param to ask_string API
1 parent a2a7e7c commit ffb7677

7 files changed

Lines changed: 13 additions & 11 deletions

File tree

libbs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "3.3.4"
1+
__version__ = "3.4.0"
22

33

44
import logging

libbs/api/decompiler_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,9 @@ def gui_show_type(self, type_name: str) -> None:
504504
"""Show a type in the GUI"""
505505
return self._send_request({"type": "method_call", "method_name": "gui_show_type", "args": [type_name]})
506506

507-
def gui_ask_for_string(self, question: str, title: str = "Plugin Question") -> str:
507+
def gui_ask_for_string(self, question: str, title: str = "Plugin Question", default: str = "") -> str:
508508
"""Ask for a string input"""
509-
return self._send_request({"type": "method_call", "method_name": "gui_ask_for_string", "args": [question, title]})
509+
return self._send_request({"type": "method_call", "method_name": "gui_ask_for_string", "args": [question, title, default]})
510510

511511
def gui_ask_for_choice(self, question: str, choices: list, title: str = "Plugin Question") -> str:
512512
"""Ask for a choice from a list"""

libbs/api/decompiler_interface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,13 @@ def gui_show_type(self, type_name: str) -> None:
195195
def gui_register_ctx_menu(self, name, action_string, callback_func, category=None) -> bool:
196196
raise NotImplementedError
197197

198-
def gui_ask_for_string(self, question, title="Plugin Question") -> str:
198+
def gui_ask_for_string(self, question, title="Plugin Question", default="") -> str:
199199
"""
200200
Opens a GUI dialog box that asks the user for a string. If not overriden by the decompiler interface,
201201
this will default to a Qt dialog box that is based on the decompilers Qt version.
202202
"""
203203
from libbs.ui.utils import gui_ask_for_string
204-
return gui_ask_for_string(question, title=title)
204+
return gui_ask_for_string(question, title=title, default=default)
205205

206206
def gui_ask_for_choice(self, question: str, choices: list, title="Plugin Question") -> str:
207207
"""

libbs/decompilers/binja/interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def gui_register_ctx_menu(self, name, action_string, callback_func, category=Non
145145
)
146146
return True
147147

148-
def gui_ask_for_string(self, question, title="Plugin Question") -> str:
148+
def gui_ask_for_string(self, question, title="Plugin Question", default="") -> str:
149149
resp = binaryninja.get_text_line_input(question, title)
150150
return resp.decode() if resp else ""
151151

libbs/decompilers/ghidra/interface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ def callback_func_wrap(*args, **kwargs):
167167
)
168168
return True
169169

170-
def gui_ask_for_string(self, question, title="Plugin Question") -> str:
171-
answer = self.flat_api.askString(title, question)
170+
def gui_ask_for_string(self, question, title="Plugin Question", default="") -> str:
171+
answer = self.flat_api.askString(title, question, default)
172172
return answer if answer else ""
173173

174174
def gui_ask_for_choice(self, question: str, choices: list, title="Plugin Question") -> str:

libbs/decompilers/ida/interface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ def dec_version(self):
106106
# GUI
107107
#
108108

109-
def gui_ask_for_string(self, question, title="Plugin Question") -> str:
110-
resp = idaapi.ask_str("", 0, question)
109+
def gui_ask_for_string(self, question, title="Plugin Question", default="") -> str:
110+
resp = idaapi.ask_str(default, 0, question)
111111
return resp if resp else ""
112112

113113
def gui_ask_for_choice(self, question: str, choices: list, title="Plugin Question") -> str:

libbs/ui/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def gui_popup_text(text, title="Plugin Info") -> bool:
1919
return False
2020

2121

22-
def gui_ask_for_string(question, title="Plugin Question") -> str:
22+
def gui_ask_for_string(question, title="Plugin Question", default="") -> str:
2323
dialog = QDialog()
2424
dialog.setWindowTitle(title)
2525

@@ -31,6 +31,8 @@ def gui_ask_for_string(question, title="Plugin Question") -> str:
3131

3232
# Text input field
3333
text_input = QLineEdit()
34+
if default:
35+
text_input.setText(default)
3436
layout.addWidget(text_input)
3537

3638
# Submit button

0 commit comments

Comments
 (0)