def extract_item(viewer, stripped=False): cnt = ida_kernwin.get_custom_viewer_place(viewer, True)[1] line = ida_kernwin.get_custom_viewer_curline(viewer, True) tags = [ida_lines.SCOLOR_ON, ida_lines.SCOLOR_OFF] expr = re.compile("[A-Z0-9_]") def find_pos(line, pos, inc): while 0 <= pos < len(line): if not stripped and line[pos] in tags: break if stripped and not expr.match(line[pos]): break pos += inc return pos pos = ida_lines.tag_advance(line, cnt) if pos < 0 or pos >= len(line): return while line[pos] in [ida_lines.SCOLOR_ON, ida_lines.SCOLOR_OFF]: pos += 2 if pos < 0 or pos >= len(line): return prev_pos, next_pos = find_pos(line, pos, -1), find_pos(line, pos, +1) if stripped: return None, line[prev_pos + 1:next_pos].strip() return line[prev_pos + 1], line[prev_pos + 2:next_pos].strip()
def view_dblclick(self, viewer, point): widget_type = ida_kernwin.get_widget_type(viewer) if not (widget_type == 48 or widget_type == 28): return # Decompiler or Structures window place, x, y = ida_kernwin.get_custom_viewer_place(viewer, False) line = utils.get_curline_striped_from_viewer(viewer) func_cand_name = cpp_utils.find_valid_cppname_in_line(line, x) if func_cand_name is not None: func_cand_ea = ida_name.get_name_ea(BADADDR, func_cand_name) if func_cand_ea is not None and utils.is_func(func_cand_ea): idc.jumpto(func_cand_ea)
def update_widget_b(self): # Make sure we are in the same function place_a, _, _ = ida_kernwin.get_custom_viewer_place(widget_a, False) ida_kernwin.jumpto(widget_b, place_a, -1, -1) # and that we show the right place (slightly zoomed out) widget_a_center_gli = ida_moves.graph_location_info_t() if ida_graph.viewer_get_gli(widget_a_center_gli, widget_a, ida_graph.GLICTL_CENTER): widget_b_center_gli = ida_moves.graph_location_info_t() widget_b_center_gli.orgx = widget_a_center_gli.orgx widget_b_center_gli.orgy = widget_a_center_gli.orgy widget_b_center_gli.zoom = widget_a_center_gli.zoom * 0.5 ida_graph.viewer_set_gli(widget_b, widget_b_center_gli, ida_graph.GLICTL_CENTER)
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
def view_dblclick(self, viewer, point): widget_type = ida_kernwin.get_widget_type(viewer) if not (widget_type == 48 or widget_type == 28): return # Decompiler or Structures window func_cand_name = None place, x, y = ida_kernwin.get_custom_viewer_place(viewer, False) if place.name() == "structplace_t": # Structure window: structplace = ida_kernwin.place_t_as_structplace_t(place) if structplace is not None: s = ida_struct.get_struc(ida_struct.get_struc_by_idx(structplace.idx)) if s: member = ida_struct.get_member(s, structplace.offset) if member: func_cand_name = ida_struct.get_member_name(member.id) if func_cand_name is None: line = utils.get_curline_striped_from_viewer(viewer) func_cand_name = cpp_utils.find_valid_cppname_in_line(line, x) if func_cand_name is not None: func_cand_ea = ida_name.get_name_ea(BADADDR, func_cand_name) if func_cand_ea is not None and utils.is_func_start(func_cand_ea): idc.jumpto(func_cand_ea)
def refresh_hexrays_cursor(self): """ TODO """ self._hexrays_origin = False self._hexrays_addresses = [] if not (self._sync_status and self._last_vdui): ida_kernwin.refresh_idaview_anyway() # TODO should this be here? return if not self.model.current_line or self.model.current_line.type: # special line ida_kernwin.refresh_idaview_anyway() # TODO should this be here? return vdui = self._last_vdui addr_map = self._get_vdui_address_map(vdui) current_address = self.model.current_address for line_num, addresses in addr_map.items(): if current_address in addresses: break else: self._hexrays_addresses = [] ida_kernwin.refresh_idaview_anyway() # TODO should this be here? return place, x, y = ida_kernwin.get_custom_viewer_place( self._last_vdui.ct, False) splace = ida_kernwin.place_t_as_simpleline_place_t(place) splace.n = line_num self.model.ignore_move = True ida_kernwin.jumpto(self._last_vdui.ct, splace, x, y) self.model.ignore_move = False self._hexrays_addresses = addr_map[line_num] ida_kernwin.refresh_idaview_anyway() # TODO should this be here?