def finish_populating_widget_popup(self, form, popup): # Or here, after the popup is done being populated by its owner. # We will attach our action to the context menu # for the 'Functions window' widget. # The action will be be inserted in a submenu of # the context menu, named 'Others'. if idaversion.get_widget_type(form) == idaapi.BWN_CALL_STACK: #line = form.GetCurrentLine() pass elif idaversion.get_widget_type(form) == idaapi.BWN_DISASM or \ idaversion.get_widget_type(form) == idaapi.BWN_DUMP: #regs =['eax', 'ebx', 'ecx', 'edx', 'esi', 'edi', 'ebp', 'esp', 'ax', 'bx', 'cx', 'dx', 'ah', 'al', 'bh', 'bl', 'ch', 'cl', 'dh', 'dl'] regs = idaapi.ph_get_regnames() idaapi.attach_action_to_popup(form, popup, "revCursor:action", 'RESim/') idaapi.attach_action_to_popup(form, popup, "dis:action", 'RESim/') highlighted = idaversion.getHighlight() if highlighted is not None: if highlighted in regs: idaapi.attach_action_to_popup(form, popup, "modReg:action", 'RESim/') else: addr = getHex(highlighted) if addr is not None or regFu.isHighlightedEffective(): idaapi.attach_action_to_popup(form, popup, "rev:action", 'RESim/') idaapi.attach_action_to_popup(form, popup, "dataWatch:action", 'RESim/') idaapi.attach_action_to_popup(form, popup, "addDataWatch:action", 'RESim/') idaapi.attach_action_to_popup(form, popup, "revData:action", 'RESim/') idaapi.attach_action_to_popup(form, popup, "modMemory:action", 'RESim/') idaapi.attach_action_to_popup(form, popup, "stringMemory:action", 'RESim/') opnum = idaapi.get_opnum() if opnum >= 0: idaapi.attach_action_to_popup(form, popup, "structField:action", 'RESim/')
def get_cursor_func_ref(): """ Get the function reference under the user cursor. Returns BADADDR or a valid function address. """ current_widget = idaapi.get_current_widget() form_type = idaapi.get_widget_type(current_widget) vu = idaapi.get_widget_vdui(current_widget) # # hexrays view is active # if vu: cursor_addr = vu.item.get_ea() # # disassembly view is active # elif form_type == idaapi.BWN_DISASM: cursor_addr = idaapi.get_screen_ea() opnum = idaapi.get_opnum() if opnum != -1: # # if the cursor is over an operand value that has a function ref, # use that as a valid rename target # op_addr = idc.get_operand_value(cursor_addr, opnum) op_func = idaapi.get_func(op_addr) if op_func and op_func.start_ea == op_addr: return op_addr # unsupported/unknown view is active else: return idaapi.BADADDR # # if the cursor is over a function definition or other reference, use that # as a valid rename target # cursor_func = idaapi.get_func(cursor_addr) if cursor_func and cursor_func.start_ea == cursor_addr: return cursor_addr # fail return idaapi.BADADDR
def get_cursor_func_ref(): """ Get the function reference under the user cursor. Returns BADADDR or a valid function address. """ current_tform = idaapi.get_current_tform() tform_type = idaapi.get_tform_type(current_tform) # get the hexrays vdui (if available) vu = idaapi.get_tform_vdui(current_tform) # # hexrays view is active # if vu: cursor_addr = vu.item.get_ea() # # disassembly view is active # elif tform_type == idaapi.BWN_DISASM: cursor_addr = idaapi.get_screen_ea() # # if the cursor is over an operand value that has a function ref, # use that as a valid rename target # op_addr = idc.GetOperandValue(cursor_addr, idaapi.get_opnum()) op_func = idaapi.get_func(op_addr) if op_func and op_func.startEA == op_addr: return op_addr # unsupported/unknown view is active else: return idaapi.BADADDR # # if the cursor is over a function definition or other reference, use that # as a valid rename target # cursor_func = idaapi.get_func(cursor_addr) if cursor_func and cursor_func.startEA == cursor_addr: return cursor_addr # fail return idaapi.BADADDR
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 get_cursor_func_ref(): current_tform = idaapi.get_current_tform() tform_type = idaapi.get_tform_type(current_tform) # get the hexrays vdui (if available) vu = idaapi.get_tform_vdui(current_tform) if vu: cursor_addr = vu.item.get_ea() elif tform_type == idaapi.BWN_DISASM: cursor_addr = idaapi.get_screen_ea() op_addr = idc.GetOperandValue(cursor_addr, idaapi.get_opnum()) op_func = idaapi.get_func(op_addr) if op_func and op_func.startEA == op_addr: return op_addr else: return idaapi.BADADDR cursor_func = idaapi.get_func(cursor_addr) if cursor_func and cursor_func.startEA == cursor_addr: return cursor_addr return idaapi.BADADDR
def opnum(cls): '''Return the currently selected operand number.''' return idaapi.get_opnum()
def opnum(cls): '''Return the currently selected operand number.''' return idaapi.get_opnum()