def activate(self, ctx): f = search_strlit_form_t() f, args = f.Compile() ok = f.Execute() if ok: current_ea = ida_kernwin.get_screen_ea() patterns = ida_bytes.compiled_binpat_vec_t() encoding = ida_nalt.get_default_encoding_idx( ida_nalt.BPU_2B if f.Encoding.value else ida_nalt.BPU_1B) # string literals must be quoted. That's how parse_binpat_str # recognizes them (we want to be careful though: the user # might type in something like 'L"hello"', which should # decode to the IDB-specific wide-char set of bytes) text = f.Text.value if text.find('"') < 0: text = '"%s"' % text err = ida_bytes.parse_binpat_str( patterns, current_ea, text, 10, # radix (not that it matters though, since we're all about string literals) encoding) if not err: ea = ida_bytes.bin_search( current_ea, ida_ida.inf_get_max_ea(), patterns, ida_bytes.BIN_SEARCH_FORWARD | ida_bytes.BIN_SEARCH_NOBREAK | ida_bytes.BIN_SEARCH_NOSHOW) ok = ea != ida_idaapi.BADADDR if ok: ida_kernwin.jumpto(ea) else: print("Failed parsing binary pattern: \"%s\"" % err) return ok
def _handle_update_location(self, packet): # Notify the painter self._plugin.interface.painter.paint(packet.name, packet.color, packet.ea) followed = self._plugin.interface.followed if followed == packet.name or followed == "everyone": ida_kernwin.jumpto(packet.ea)
def item_selection_changed(self): local_item = None remote_item = None if not self.tree.selectedItems(): return item = self.tree.selectedItems()[0] if item.parent() is None: local_item = item else: local_item = item.parent() remote_item = item if local_item: ida_kernwin.jumpto(self.get_obj(local_item.api_id)['offset']) if remote_item: # TODO: change graph to a "loading..." message q = network.QueryWorker("GET", "collab/annotations/", json=True, params={ "type": "assembly", "instance": remote_item.api_id }) q.start(self.handle_display_change)
def nop(): """Nops-out the current instruction and advance the cursor to the next instruction.""" ea = idaapi.get_screen_ea() num_bytes = idc.get_item_size(ea) for i in range(num_bytes): ida_bytes.patch_byte(ea, 0x90) ea += 1 ida_kernwin.refresh_idaview_anyway() ida_kernwin.jumpto(ea)
def _handle_update_location(self, packet): # Update the users list user = self._plugin.core.get_user(packet.name) user["ea"] = packet.ea self._plugin.core.add_user(packet.name, user) followed = self._plugin.interface.followed if followed == packet.name or followed == "everyone": ida_kernwin.jumpto(packet.ea)
def OnDblClick(self, shift): line = self.GetCurrentLine() #print('line is %s' % line) parts = line.split() try: addr = int(parts[0], 16) except: print('no address found in %s' % line) return ida_kernwin.jumpto(addr)
def mouseReleaseEvent(self, event): self.prev_mouse_y = event.pos().y() self.fm.on_mb_click(event, self.get_address(), self.get_pixels_total(), self.mouseOffs) if self.get_sync_state(): ida_kernwin.jumpto(self.base + self.offs) self.activateWindow() self.setFocus() self.statechanged.emit() return
def doubleClickEvent(self, event): index = event.pos() try: item = self.model.itemFromIndex(self.view.indexAt(event.pos())) column = item.column() ea = item.ea except: return if ea != -1: ida_kernwin.jumpto(ea)
def main(): offset = ida_kernwin.ask_addr(0x0, "file offset") if not offset: return ea = ida_loader.get_fileregion_ea(offset) if ea == ida_idaapi.BADADDR: print('error: EA for file offset not found') return print('EA for file offset: 0x%x' % (ea)) ida_kernwin.jumpto(ea)
def OnDblClick(self, node_id): target_ea = self.items[node_id].ea r = ida_kernwin.get_highlight(ida_kernwin.get_current_viewer()) if r: text, _ = r # ghetto-convert hex strings to int try: target_ea = int(text, 16) except ValueError: pass ida_kernwin.jumpto(target_ea) return True
def mouseReleaseEvent(self, event): if (event.button() == Qt.LeftButton and self.is_dragging_graph): self.is_dragging_graph = False self.prev_mouse_y = event.pos().y() self.fm.on_mb_click(event, self.get_address(), self.get_pixel_qty(), self.mouseOffs) if self.get_sync_state(): ida_kernwin.jumpto(self.base + self.offs) self.activateWindow() self.setFocus() self.statechanged.emit() return
def _onFunctionClick(self, model_index): function_address = idaapi.BADADDR if model_index.column() == 1: try: function_address = int(model_index.data(), 16) except: pass elif model_index.column() == 0: function_address = idc.get_name_ea_simple(str(model_index.data())) else: return ida_kernwin.jumpto(function_address)
def OnDblClick(self, node_id): is_thread, value, label = self[node_id] if is_thread: ida_dbg.select_thread(value) self.Show() s = "SEH chain for " + hex(value) t = "-" * len(s) print(t) print(s) print(t) for handler in self.result[value]: print("%x: %s" % (handler, self.names[handler])) print(t) else: ida_kernwin.jumpto(value) return True
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 find_symbol(self): """ Find the last create symbol signature. :return: None """ with open(TEMP_SIG_FILENAME) as f: sig = hjson.load(f) results = self.find_from_sig_json(sig, decremental=False) for address in results: self.log('Search result: 0x{:x}'.format(address)) self.log('Search done') if len(results) == 1: # if remote sig has a proper name, but current one is not ida_kernwin.jumpto(results[0])
def write_reg_info(index: dict): """Write register info as line comment at instruction pointed to by the program counter and change focus to that location :param index: _index.json JSON data """ cmt = "" for reg, val in index["regs"].items(): cmt += f"{reg.ljust(6)} : {hex(val)}\n" progctr = get_pc_by_arch(index) if progctr is None: raise ArchNotSupportedError( "Architecture not fully supported, skipping register status comment" ) ida_bytes.set_cmt(progctr, cmt, 0) ida_kernwin.jumpto(progctr)
def dalAddrFromPc(): pc = ida_kernwin.ask_addr(0x00000000, "PC:") if type(pc) is not int: warning("Invalid input!") return if (pc & 0xF0000000) == 0x20000000: #MMU mapped pc -= 0x20000000 if pc >= DAL_START_IN_ROM: pc -= DAL_START_IN_ROM if pc > DAL_END_IN_ROM: warning("Not in DAL!") return ida_kernwin.jumpto(pc)
def OnDblClick(self, shift): line = self.GetCurrentLine() line = idaapi.tag_remove(line) #print('line is %s' % line) parts = line.split() branch_from = None try: branch_from = int(parts[3], 16) except: print('branch from not found in %s' % line) return command = '@cgc.goToBasicBlock(0x%x)' % branch_from #print('cmd is %s' % command) simicsString = gdbProt.Evalx('SendGDBMonitor("%s");' % command) if type(simicsString) is str and 'not in blocks' in simicsString: ida_kernwin.jumpto(branch_from) else: eip = gdbProt.getEIPWhenStopped() if eip is not None: self.isim.signalClient() return True
def wheelEvent(self, event): delta = round(event.angleDelta().y() / 120) # zoom if self.key == Qt.Key_Control: self.set_zoom_delta(delta) # width elif self.key == Qt.Key_X: if not self.lock_width: self.set_width_delta(delta) # offset (fine) elif self.key == Qt.Key_Shift: self.set_offset_delta(delta) if self.get_sync_state(): ida_kernwin.jumpto(self.base + self.offs) self.activateWindow() self.setFocus() elif self.key == Qt.Key_H: if not self.lock_width: less = delta < 0 w = -8 if less else 8 self.set_pixel_qty_per_line((self.get_pixel_qty_per_line() & 0xFFFFFFF8) + w) # offset (coarse) else: self.set_offset_delta(delta * self.get_pixel_qty_per_line()) if self.get_sync_state(): ida_kernwin.jumpto(self.base + self.offs) self.activateWindow() self.setFocus() self.statechanged.emit() self.repaint() return
def activate_pos(self, line_num, x, y): """ TODO/COMMENT """ token = self.model.mtext.get_token_at_pos(line_num, x) if isinstance(token, AddressToken): ida_kernwin.jumpto(token.target_address, -1, 0) return if isinstance( token, BlockNumberToken) or (isinstance(token, MicroOperandToken) and token.mop.t == ida_hexrays.mop_b): blk_idx = token.blk_idx if isinstance( token, BlockNumberToken) else token.mop.b blk_token = self.model.mtext.blks[blk_idx] blk_line_num, _ = self.model.mtext.get_pos_of_token( blk_token.lines[0]) self.model.current_position = (blk_line_num, 0, y) self.view._code_view.Jump(*self.model.current_position) return
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?
def navigate(self, address): # TODO fetch active view? or most recent one? i'm lazy for now... widget = ida_kernwin.find_widget("IDA View-A") # # this call can both navigate to an arbitrary address, and keep # the cursor position 'static' within the window at an (x,y) # text position # # TODO: I think it's kind of tricky to figure out the 'center' line of # the disassembly window navigation, so for now we'll just make a # navigation call always center around line 20... # CENTER_AROUND_LINE_INDEX = 20 if widget: return ida_kernwin.ea_viewer_history_push_and_jump( widget, address, 0, CENTER_AROUND_LINE_INDEX, 0) # ehh, whatever.. just let IDA navigate to yolo else: return ida_kernwin.jumpto(address)
def goto(self): """ Method which allow to move the screen to the position of this element. Wrapper on ``ida_kernwin.jumpto`` (old ``idc.Jump``). """ ida_kernwin.jumpto(self.ea)
def OnSelectLine(self, n): o = self.items[n] ida_kernwin.jumpto(o.base) return (ida_kernwin.Choose.NOTHING_CHANGED, )
def callback(): ida_kernwin.jumpto(packet.loc)
def OnSelectLine(self, n): ida_kernwin.jumpto(self.items[n].addr) return (ida_kernwin.Choose.NOTHING_CHANGED, )
def OnSelectLine(self, n): self.selcount += 1 ida_kernwin.jumpto(self.items[n][0])
def show_xrefs(ea, gco, xrefs, ndefs): title = "xrefs to %s at %08x" % (gco.name, ea) xc = xref_chooser_t(xrefs, title, ndefs, ea, gco) i = xc.Show(True) if i >= 0: ida_kernwin.jumpto(xrefs[i])
def OnSelectLine(self, n): ida_kernwin.jumpto(self.items[n].ea)
def OnSelectLine(self, n): item_ea = self.items[n].ea func_ea = self.items[n].entry ea = func_ea if item_ea == BADADDR else item_ea ida_kernwin.jumpto(ea)
def OnSelectLine(self, n): o = self.items[n] ida_kernwin.jumpto(o.base) return (ida_kernwin.Choose.NOTHING_CHANGED, )
def OnSelectLine(self, n): ida_kernwin.jumpto(self.items[n].addr) return (ida_kernwin.Choose.NOTHING_CHANGED, )
def OnSelectLine(self, n): ida_kernwin.jumpto(self.items[n].caller)