Last active
October 26, 2021 10:53
-
-
Save nirizr/1a035f997e4335cf06f46e285263524e to your computer and use it in GitHub Desktop.
Force IDA's G (goto) dialog to ignore the backtick/tag marker used in windbg when one copies and pastes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
from PyQt5.QtWidgets import qApp, QTextEdit, QLineEdit, QComboBox, QPushButton | |
except ImportError: | |
from PySide.QtGui import qApp, QTextEdit, QLineEdit, QComboBox, QPushButton | |
def handle_tags(text): | |
# text handling is actually done here. | |
# we could improve this by doing something more clever than just a replace | |
# say, extend when ` are present without the full 8 bytes following, or | |
# a strict verification. | |
return text.replace('`', '') | |
def safe_disconnect(signal, slot): | |
while True: | |
try: | |
signal.disconnect(slot) | |
except TypeError: | |
break | |
class ComboBoxHandler(object): | |
def __init__(self, combobox): | |
self.text = None | |
self.combobox = combobox | |
self.window = self.combobox.window() | |
buttons = self.window.findChildren(QPushButton) | |
self.okbutton = filter(lambda b: b.text() == "O&K", buttons)[0] | |
self.okbutton.clicked.connect(self.handle_clicked) | |
self.okbutton.pressed.connect(self.handle_pressed) | |
self.okbutton.released.connect(self.handle_released) | |
def __del__(self): | |
if self.okbutton: | |
safe_disconnect(self.okbutton.clicked, self.handle_clicked) | |
safe_disconnect(self.okbutton.pressed, self.handle_pressed) | |
safe_disconnect(self.okbutton.released, self.handle_released) | |
def handle_pressed(self): | |
if self.text: | |
self.combobox.setCurrentText(self.text) | |
def handle_released(self): | |
# Release is emited just before a click, so once we get that we know we | |
# should change the text currently in the input combo box | |
# TODO: this is called before a click is sent, but also when mouse | |
# moves away from the button while pressed. I could not find a way | |
# to distinguish the two scenarios (a genuine click and a mouse moved | |
# outside the frame of the button) | |
self.text = self.combobox.currentText() | |
self.combobox.setCurrentText(handle_tags(self.text)) | |
def handle_clicked(self): | |
# Since we registered later than IDA's handling, we'll be called after | |
# IDA's handling of the text. in case of an error, for example, we'll | |
# restore the original text after any of IDA's handling | |
self.combobox.setCurrentText(self.text) | |
self.text = None | |
seen = set() | |
g = [] | |
def focusmonitor(old, new): | |
global g, seen | |
if new in seen: | |
return | |
if isinstance(new, QLineEdit): | |
# TODO: IDA's command line shell is a QLineEdit, but it does not emit | |
# returnPressed events, so I could not monitor and handle it's text | |
# this could still be useful for other QlineEdits | |
pass | |
if isinstance(new, QTextEdit): | |
pass | |
if isinstance(new, QComboBox): | |
g.append(ComboBoxHandler(new)) | |
seen.add(new) | |
qApp.focusChanged.connect(focusmonitor) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment