Пример #1
0
def pp_main():
    global pp

    if pp and not pp.is_dead():
        pp.die()
        pp = None
        return
    w = ida_kernwin.get_current_widget()
    title = "IDA View-A"
    if w:
        title = ida_kernwin.get_widget_title(w)
    title = ida_kernwin.ask_str(title, 0, "Please specify title of widget")
    if title:
        path = ida_kernwin.ask_str(
            "", ida_kernwin.HIST_DIR,
            "Please specify path containing png files to play back")
        if path and os.path.exists(path):
            files = find_files(path, "*.png")
            print("found %d files" % len(files))
            if len(files):
                interval = ida_kernwin.ask_long(
                    100, "Please specify timer interval")
                if interval:
                    pp = png_player_t(title, files, interval=interval)
                    print("PNGs playing in widget %s" % title)
Пример #2
0
def show_ctree_graph(create_subgraph=False):
    w = ida_kernwin.get_current_widget()
    if ida_kernwin.get_widget_type(w) == ida_kernwin.BWN_PSEUDOCODE:
        vu = ida_hexrays.get_widget_vdui(w)
        if vu:
            vu.get_current_item(ida_hexrays.USE_MOUSE)
            focusitem = vu.item.e if vu.item.is_citem() else None
            sub = None
            if create_subgraph:
                if not focusitem:
                    return
                sub = "subgraph %x" % focusitem.obj_id
            # create graphviewer
            cg = cfunc_graph_t(focusitem,
                               HRDevHelper.config,
                               close_open=True,
                               subtitle=sub)
            # build graph for current function
            gb = graph_builder_t(cg, None if create_subgraph else vu.cfunc)
            gb.apply_to(focusitem if create_subgraph else vu.cfunc.body,
                        vu.cfunc.body)
            # show graph
            cg.Show()
            # set zoom and dock position
            cg.zoom_and_dock(w)
    return
Пример #3
0
    def touch_window(self, 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...)
        twidget = ida_kernwin.get_current_widget()
        title = ida_kernwin.get_widget_title(twidget)

        # touch the target window by switching to it
        ida_kernwin.activate_widget(target, True)
        self.flush_ida_sync_requests()

        # locate our previous selection
        previous_twidget = ida_kernwin.find_widget(title)

        # return us to our previous selection
        ida_kernwin.activate_widget(previous_twidget, True)
        self.flush_ida_sync_requests()
Пример #4
0
def get_bg_color():
    w = ida_kernwin.get_current_widget()
    if not w:
        return None
    widget = ida_kernwin.PluginForm.FormToPyQtWidget(w)
    if not widget:
        return None
    color = widget.palette().color(QtGui.QPalette.Background)
    return color
Пример #5
0
 def screen_ea_changed_ev(self, ea, prev_ea):
     # react to screen ea changes issued by PSEUDOCODE and DISASM views
     if (ida_kernwin.get_widget_type(ida_kernwin.get_current_widget()) in
     [ida_kernwin.BWN_PSEUDOCODE, ida_kernwin.BWN_DISASM]):
         self.ea = ea
         # why does refresh_idaview_anyway() work but request_refresh() doesn't?
         #ida_kernwin.clear_refresh_request(ida_kernwin.IWID_PSEUDOCODE)
         #ida_kernwin.request_refresh(ida_kernwin.IWID_PSEUDOCODE, True)
         ida_kernwin.refresh_idaview_anyway()
     return
Пример #6
0
 def zoom_and_dock(self, target):
     widget = ida_kernwin.get_current_widget()
     if widget and self.dock_position:
         gli = ida_moves.graph_location_info_t()
         if ida_graph.viewer_get_gli(gli, widget):
             gli.zoom = self.zoom
             ida_graph.viewer_set_gli(widget, gli)
         ida_kernwin.set_dock_pos(ida_kernwin.get_widget_title(widget),
                                  ida_kernwin.get_widget_title(target),
                                  self.dock_position)
         self.Refresh()
Пример #7
0
    def editor_menuaction(self):
        action_desc = ida_kernwin.action_desc_t(
            'my:editoraction',  # The action name. This acts like an ID and must be unique
            'Python Editor!',  # The action text.
            MyEditorHandler(),  # The action handler.
            'Ctrl+H',  # Optional: the action shortcut DO IT  HERE!
            'Script editor',  # Optional: the action tooltip (available in menus/toolbar)
            ida_kernwin.load_custom_icon(":/ico/python.png")  # hackish load action icon , if no custom icon use number from 1-150 from internal ida
        )

        # 3) Register the action
        ida_kernwin.register_action(action_desc)

        ida_kernwin.attach_action_to_menu(
            'Edit/Editor...',  # The relative path of where to add the action
            'my:editoraction',  # The action ID (see above)
            ida_kernwin.SETMENU_APP)  # We want to append the action after the 'Manual instruction...

        ida_kernwin.get_current_widget()
        ida_kernwin.attach_action_to_popup(form, None, "my:editoraction", None)
Пример #8
0
    def init(self):
        """
        This is called by IDA when it is loading the plugin.
        """
        # attempt plugin initialization
        try:
            self._install_plugin()

        # failed to initialize or integrate the plugin, log and skip loading
        except Exception as e:
            form = ida_kernwin.get_current_widget()
            pass

        return idaapi.PLUGIN_KEEP
Пример #9
0
def dump_ctree_to_lambda(create_subgraph=False):
    w = ida_kernwin.get_current_widget()
    if ida_kernwin.get_widget_type(w) == ida_kernwin.BWN_PSEUDOCODE:
        vu = ida_hexrays.get_widget_vdui(w)
        if vu:
            vu.get_current_item(ida_hexrays.USE_MOUSE)
            focusitem = vu.cfunc.body
            if create_subgraph:
                focusitem = vu.item.e if vu.item.is_citem() else None
            if focusitem:
                gd = graph_dumper_t()
                gd.apply_to(focusitem, vu.cfunc.body)
                lines = "(%s)" % " and\n".join(gd.lines)
                print("%s\n%x:\n%s" %
                      ("-" * 80, ida_kernwin.get_screen_ea(), lines))
Пример #10
0
    def __init__(self):
        QtCore.QObject.__init__(self)
        self.dead = False
        name = "Coffee"
        w = ida_kernwin.find_widget("IDA View-%s" % name)
        if not w:
            w = ida_kernwin.get_current_widget()
            if not w:
                name = "Coffee"
                w = ida_kernwin.open_disasm_window("IDA View-%s" % name)
        self.painting = False
        self.transform = False
        self.target = ida_kernwin.PluginForm.FormToPyQtWidget(w).viewport()
        self.pm = QtGui.QPixmap(self.target.size())

        self.target.installEventFilter(self)
        self.timer = self.timercallback_t(self.target, 2)
Пример #11
0
    def get_custom_viewer_hint(self, view, place):
        try:
            widget = ida_kernwin.get_current_widget()
            if ida_kernwin.get_widget_type(widget) != ida_kernwin.BWN_DISASM:
                return None

            curline = ida_kernwin.get_custom_viewer_curline(view, True)

            # sometimes get_custom_viewer_place() returns [x, y] and sometimes [place_t, x, y].
            # we want the place_t.
            viewer_place = ida_kernwin.get_custom_viewer_place(view, True)
            if len(viewer_place) != 3:
                return None

            _, x, y = viewer_place
            ea = place.toea()

            # "color" is a bit of misnomer: its the type of the symbol currently hinted
            color = get_color_at_char(curline, x)
            if color != ida_lines.COLOR_ADDR:
                return None

            # grab the FAR references to code (not necessarilty a branch/call/jump by itself)
            far_code_references = [
                xref.to for xref in idautils.XrefsFrom(ea, ida_xref.XREF_FAR)
                if ida_bytes.is_code(ida_bytes.get_flags(xref.to))
            ]
            if len(far_code_references) != 1:
                return None

            fva = far_code_references[0]

            # ensure its actually a function
            if not idaapi.get_func(fva):
                return None

            # this magic constant is the number of "important lines" to display by default.
            # the remaining lines get shown if you scroll down while the hint is displayed, revealing more lines.
            return render_function_hint(fva), DEFAULT_IMPORTANT_LINES_NUM
        except Exception as e:
            logger.warning(
                'unexpected exception: %s. Get in touch with @williballenthin.',
                e,
                exc_info=True)
            return None
Пример #12
0
    def run(self, arg):
        w = ida_kernwin.get_current_widget()
        if ida_kernwin.get_widget_type(w) == ida_kernwin.BWN_PSEUDOCODE:
            vu = ida_hexrays.get_widget_vdui(w)
            vu_title = ida_kernwin.get_widget_title(w)
            if vu:
                vu.get_current_item(ida_hexrays.USE_KEYBOARD)
                highlight = vu.item.e if vu.item.is_citem() else None
                # create graphviewer
                cg = cfunc_graph_t(highlight, True)
                # build graph for current function
                gb = graph_builder_t(cg)
                gb.apply_to(vu.cfunc.body, None)
                # show graph
                cg.Show()

                # set zoom and dock position
                cg.zoom_and_dock(vu_title, ZOOM, DOCK_POSITION)
Пример #13
0
 def run(self, arg):
     global tainted_pcs
     # this is called when select the plugin from the Edit>Plugins menu
     curwidget = ida_kernwin.get_current_widget()
     if (ida_kernwin.BWN_PSEUDOCODE == ida_kernwin.get_widget_type(
             curwidget)):
         reuse = HIT2_ReuseDialog.GET_NEW_PROCESS
         clear_old = False
         if (len(tainted_pcs) > 0):
             reuse = HIT2_ReuseDialog.askToReuse()
             if (HIT2_ReuseDialog.GET_NEW_PROCESS == reuse):
                 tainted_pcs.clear()
                 # need to clear old colors in case changing process on the
                 # same decompiled function that colored before
                 clear_old = True
         if (HIT2_ReuseDialog.CANCEL_REQUEST != reuse):
             self.color_pseudocode(curwidget, clear_old)
     else:
         ida_kernwin.msg("Current window is not a pseudocode window\n")
Пример #14
0
    def run(self, arg):
        w = ida_kernwin.get_current_widget()
        if ida_kernwin.get_widget_type(w) == ida_kernwin.BWN_PSEUDOCODE:
            vu = ida_hexrays.get_widget_vdui(w)
            vu_title = ida_kernwin.get_widget_title(w)
            if vu:
                vu.get_current_item(ida_hexrays.USE_KEYBOARD)
                focusitem = vu.item.e if vu.item.is_citem() else None
                # create graphviewer
                cg = cfunc_graph_t(focusitem, self.config, close_open=True)
                # build graph for current function
                gb = graph_builder_t(cg)
                gb.apply_to(vu.cfunc.body, None)
                # show graph
                cg.Show()

                # set zoom and dock position
                cg.zoom_and_dock(vu_title, self.config["options"]["zoom"],
                                 self.config["options"]["dockpos"])
Пример #15
0
def sr_main():
    global sr

    if sr:
        del sr
        sr = None
        print("Stopped recording")
    else:
        w = ida_kernwin.get_current_widget()
        title = "IDA View-A"
        if w:
            title = ida_kernwin.get_widget_title(w)
        title = ida_kernwin.ask_str(
            title, 0, "Please specify title of widget to capture")
        if title:
            path = ida_kernwin.ask_str("", ida_kernwin.HIST_DIR,
                                       "Please specify destination path")
            if path and os.path.exists(path):
                sr = screen_record_t(title, path)
                print("Started recording")
Пример #16
0
def get_ctree_graph(ea):
    """
    在当前反编译窗口中创建当前函数的 ctree 图
    """

    vu = ida_hexrays.open_pseudocode(ea, 0)
    w = ida_kernwin.get_current_widget()
    vu_title = ida_kernwin.get_widget_title(w)

    vu.get_current_item(ida_hexrays.USE_KEYBOARD)
    focusitem = vu.item.e if vu.item.is_citem() else None

    # 创建 graphviewer
    cg = cfunc_graph_t(focusitem, CONFIG, close_open=True)
    # 为当前函数创建图像
    gb = graph_builder_t(cg)
    gb.apply_to(vu.cfunc.body, None)
    # 显示图像
    cg.Show()
    # 设置窗口位置
    cg.zoom_and_dock(vu_title, CONFIG["options"]["zoom"],
                     CONFIG["options"]["dockpos"])
Пример #17
0
def get_current_widget():
    if idaapi.IDA_SDK_VERSION <= 699:
        form = idaapi.get_current_tform()
    else:
        form = ida_kernwin.get_current_widget()
    return form