Ejemplo n.º 1
0
 def __init__(self, title):
     idaapi.simplecustviewer_t.__init__(self)
     self.ea = None
     self.query = None
     self.idx = None
     self.targets = None
     self.title = title
     self.Create(title)
     idaapi.set_code_viewer_is_source(idaapi.create_code_viewer(self.GetWidget(), 0x4))
Ejemplo n.º 2
0
 def retrieve_function_callback(self, __, ea=None):
     func_ea = idaapi.get_screen_ea() if ea is None else ea
     func_name = idaapi.get_func_name(func_ea)
     widget_title = "{} - {}".format(self.name, func_name)
     widget = idaapi.find_widget(widget_title)
     if widget:
         idaapi.activate_widget(widget, True)
         return
     targets = self.retrieve_function(func_ea, self.cfg['topk'])
     if targets is None:
         print("[{}] {} is skipped because get function feature error".format(self.name, func_name))
         return
     cv = SourceCodeViewer(func_name, targets)
     cv.Create(widget_title)
     cv.refresh()
     # CDVF_STATUSBAR 0x04, keep the status bar in the custom viewer
     cv = idaapi.create_code_viewer(cv.GetWidget(), 0x4)
     idaapi.set_code_viewer_is_source(cv)
     idaapi.display_widget(cv, idaapi.PluginForm.WOPN_DP_TAB | idaapi.PluginForm.WOPN_RESTORE)
     ida_kernwin.refresh_navband(True)
Ejemplo n.º 3
0
    def retrieve_function_callback(self, __, ea=None):
        if not self.check_before_use():
            return
        funcset_ids = [self.funcset] if not self.cfg['usepublic'] else None
        func_ea = idaapi.get_screen_ea() if ea is None else ea
        func_name = idaapi.get_func_name(func_ea)
        targets = self.retrieve_function(func_ea, self.cfg['topk'],
                                         funcset_ids)
        succ, skip, fail = 0, 0, 0
        if targets is None:
            print("[{}] {} failed because get function feature error".format(
                self.name, func_name))
            fail += 1
        else:
            if not (self.cview and self.cview.is_alive()):
                self.cview = SourceCodeViewer(self.name)
                # CDVF_STATUSBAR 0x04, keep the status bar in the custom viewer
                idaapi.set_code_viewer_is_source(
                    idaapi.create_code_viewer(self.cview.GetWidget(), 0x4))
            self.cview.set_user_data(func_ea, targets)

            widget = idaapi.get_current_widget()
            if idaapi.get_widget_title(widget) == self.name:
                skip += 1
            else:
                if idaapi.get_widget_type(widget) != idaapi.BWN_PSEUDOCODE:
                    pseudo_view = idaapi.open_pseudocode(func_ea, 1)
                    pseudo_view.refresh_view(1)
                    widget = pseudo_view.toplevel
                pseudo_title = idaapi.get_widget_title(widget)

                idaapi.display_widget(
                    self.cview.GetWidget(), idaapi.PluginForm.WOPN_DP_TAB
                    | idaapi.PluginForm.WOPN_RESTORE)
                idaapi.set_dock_pos(self.name, pseudo_title, idaapi.DP_RIGHT)
                succ += 1
        print(
            "[{}] {} functions successfully retrieved, {} functions failed, {} functions skipped"
            .format(self.name, succ, fail, skip))