def isHighlightedEffective(): ip = idaversion.get_screen_ea() instr = idc.GetDisasm(ip) if '[' in instr: val = instr.split('[', 1)[1].split(']')[0] highlighted = idaversion.getHighlight() if highlighted in val: return True else: return False
def doRevToCursor(self): cursor = idaversion.get_screen_ea() curAddr = idaversion.get_reg_value(self.PC) if cursor == curAddr: print 'attempt to go back to where you are ignored' return #doRevToAddr(cursor) command = '@cgc.revToAddr(0x%x, extra_back=%d)' % (cursor, 0) simicsString = gdbProt.Evalx('SendGDBMonitor("%s");' % command) #print('simicsString <%s>' % simicsString) if self.checkNoRev(simicsString): eip = gdbProt.getEIPWhenStopped() self.signalClient()
def getOffset(): ''' Assuming an offset, e.g., "var_11" is highlighted, and assuming bp is proper, get the calculated address. ''' retval = None ip = idaversion.get_screen_ea() print('ip is 0x%x' % ip) highlighted = idaversion.getHighlight() print('highlighted is %s' % highlighted) ov0 = idc.print_operand(ip, 0) ov1 = idc.print_operand(ip, 1) print('op0 %s op1 %s' % (ov0, ov1)) if highlighted in ov0: index = 0 want = ov0 else: index = 1 want = ov1 ''' Convert to numberic from symbol ''' idc.op_seg(ip, index) if '[' in want and '+' in want or '-' in want: op = idc.print_operand(ip, index) print('op is %s' % op) val = op.split('[', 1)[1].split(']')[0] print('val %s' % val) if '+' in val: reg, value = val.split('+') else: reg, value = val.split('-') reg_val = idaversion.get_reg_value(reg) try: value = value.strip('h') value = int(value, 16) except: print('unable to parse int from %s' % value) idc.op_stkvar(ip, 0) return retval if '+' in val: retval = reg_val + value else: retval = reg_val - value print('effective addr is 0x%x' % retval) ''' Convert back to symbol, e.g., var_11''' idc.op_stkvar(ip, index) return retval
def satisfyCondition(self): cursor = idaversion.get_screen_ea() print('Satisfy condition at instruction 0x%x' % cursor) command = "@cgc.satisfyCondition(0x%x)" % cursor simicsString = gdbProt.Evalx('SendGDBMonitor("%s");' % command) print('satisfyCondition got simicsString %s' % simicsString) eip = None if self.checkNoRev(simicsString): eip = gdbProt.getEIPWhenStopped() self.signalClient() else: return curAddr = idaversion.get_reg_value(self.PC) self.showSimicsMessage() bookmark_list = self.bookmark_view.updateBookmarkView() return eip
def getRefAddr(): ''' Get address from the operand currently under the cursor. If just a register, use that. If calculated within brackets, try decoding that. ''' retval = None ea = idaversion.get_screen_ea() flags = idaversion.get_full_flags(ea) if idaversion.is_code(flags): opnum = idaapi.get_opnum() op_type = idaversion.get_operand_type(ea, opnum) op = idc.print_operand(ea, opnum) print('is code, type %d op %s' % (op_type, op)) #if op_type == idc.o_disp: if op_type == 4: ''' displacement from reg address ''' val = op.split('[', 1)[1].split(']')[0] if ',' in val: reg = val.split(',')[0] retval = getRegOffset(ea, reg, opnum) elif '+' in val: reg = val.split('+')[0] retval = getRegOffset(ea, reg, opnum) else: try: retval = idaversion.getRegVarValue(val) except: print('%s not a reg' % reg) elif op_type == 3: retval = idaversion.get_operand_value(ea, opnum) elif op_type == 1: retval = idaversion.getRegVarValue(op) else: print('Op type %d not handled' % op_type) else: return ea return retval
def activate(self, ctx): eip = idaversion.get_screen_ea() fun_eip = self.isim.getOrigAnalysis().origFun(eip) return 1