我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用idaapi.find_tform()。
def get_init_menu(self): try: self.widget = form_to_widget(idaapi.get_current_tform()) if self.widget is None: raise Exception() except: self.widget = form_to_widget(idaapi.find_tform('Output window')) self.window = self.widget.window() self.menu = self.window.findChild(QtWidgets.QMenuBar) # add top level menu
def get_ida_bg_color_ida6(): """ Get the background color of an IDA disassembly view. (IDA 6.x) """ names = ["Enums", "Structures"] names += ["Hex View-%u" % i for i in range(5)] names += ["IDA View-%c" % chr(ord('A') + i) for i in range(5)] # find a form (eg, IDA view) to analyze colors from for window_name in names: form = idaapi.find_tform(window_name) if form: break else: raise RuntimeError("Failed to find donor View") # touch the target form so we know it is populated touch_window(form) # locate the Qt Widget for a form and take 1px image slice of it if using_pyqt5: widget = idaapi.PluginForm.FormToPyQtWidget(form) pixmap = widget.grab(QtCore.QRect(0, 10, widget.width(), 1)) else: widget = idaapi.PluginForm.FormToPySideWidget(form) region = QtCore.QRect(0, 10, widget.width(), 1) pixmap = QtGui.QPixmap.grabWidget(widget, region) # convert the raw pixmap into an image (easier to interface with) image = QtGui.QImage(pixmap.toImage()) # return the predicted background color return QtGui.QColor(predict_bg_color(image))
def run(arg): tform = idaapi.find_tform("Structure Builder") if tform: idaapi.switchto_tform(tform, True) else: Forms.StructureBuilder(Helper.temporary_structure).Show()
def activate(self, ctx): """ :param ctx: idaapi.action_activation_ctx_t :return: None """ tform = idaapi.find_tform('Classes') if not tform: class_viewer = Forms.ClassViewer() class_viewer.Show() else: idaapi.switchto_tform(tform, True)
def get_selected_funcs(): tform = idaapi.find_tform("Functions window") if not tform: idc.Warning("Unable to find 'Functions window'") return widget = idaapi.PluginForm.FormToPySideWidget(tform) table = widget.findChild(QtWidgets.QTableView) selected_funcs = [str(s.data()) for s in table.selectionModel().selectedRows()] return match_funcs(selected_funcs)
def get_selected_funcs(): """ Return the list of function names selected in the Functions window. """ # NOTE / COMPAT: if using_ida7api: import sip twidget = idaapi.find_widget("Functions window") widget = sip.wrapinstance(long(twidget), QtWidgets.QWidget) # NOTE: LOL else: tform = idaapi.find_tform("Functions window") if using_pyqt5: widget = idaapi.PluginForm.FormToPyQtWidget(tform) else: widget = idaapi.PluginForm.FormToPySideWidget(tform) # TODO: test this if not widget: idaapi.warning("Unable to find 'Functions window'") return # # locate the table widget within the Functions window that actually holds # all the visible function metadata # table = widget.findChild(QtWidgets.QTableView) # # scrape the selected function names from the Functions window table # selected_funcs = [str(s.data()) for s in table.selectionModel().selectedRows()] # # re-map the scraped names as they appear in the function table, to their true # names as they are saved in the IDB. See the match_funcs(...) function # comment for more details # return match_funcs(selected_funcs)
def eventFilter(self, source, event): # # hook the destroy event of the coverage overview widget so that we can # cleanup after ourselves in the interest of stability # if int(event.type()) == 16: # NOTE/COMPAT: QtCore.QEvent.Destroy not in IDA7? self._target.terminate() # # this is an unknown event, but it seems to fire when the widget is # being saved/restored by a QMainWidget. We use this to try and ensure # the Coverage Overview stays docked when flipping between Reversing # and Debugging states in IDA. # # See issue #16 on github for more information. # if int(event.type()) == 2002: # # if the general registers IDA View exists, we make the assumption # that the user has probably started debugging. # # NOTE / COMPAT: if using_ida7api: debug_mode = bool(idaapi.find_widget("General registers")) else: debug_mode = bool(idaapi.find_tform("General registers")) # # if this is the first time the user has started debugging, dock # the coverage overview in the debug QMainWidget workspace. its # dock status / position should persist future debugger launches. # global debugger_docked if debug_mode and not debugger_docked: idaapi.set_dock_pos(self._target._title, "Structures", idaapi.DP_TAB) debugger_docked = True return False #------------------------------------------------------------------------------ # Coverage Overview #------------------------------------------------------------------------------
def touch_window(target): """ Touch a window/widget/form to ensure it gets drawn by IDA. XXX/HACK: We need to ensure that widget we will analyze actually gets drawn so that there are colors for us to steal. To do this, we switch to it, and switch back. I tried a few different ways to trigger this from Qt, but could only trigger the full painting by going through the IDA routines. """ # get the currently active widget/form title (the form itself seems transient...) if using_ida7api: twidget = idaapi.get_current_widget() title = idaapi.get_widget_title(twidget) else: form = idaapi.get_current_tform() title = idaapi.get_tform_title(form) # touch/draw the widget by playing musical chairs if using_ida7api: # touch the target window by switching to it idaapi.activate_widget(target, True) flush_ida_sync_requests() # locate our previous selection previous_twidget = idaapi.find_widget(title) # return us to our previous selection idaapi.activate_widget(previous_twidget, True) flush_ida_sync_requests() else: # touch the target window by switching to it idaapi.switchto_tform(target, True) flush_ida_sync_requests() # locate our previous selection previous_form = idaapi.find_tform(title) # lookup our original form and switch back to it idaapi.switchto_tform(previous_form, True) flush_ida_sync_requests()