Python ida_idaapi.BADADDR Examples

The following are 8 code examples of ida_idaapi.BADADDR(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module ida_idaapi , or try the search function .
Example #1
Source File: actions.py    From IDArling with GNU General Public License v3.0 6 votes vote down vote up
def uninstall(self):
        action_name = self.__class__.__name__

        # Detach the action from the chosen menu
        result = ida_kernwin.detach_action_from_menu(
            self._menu, self._ACTION_ID
        )
        if not result:
            return False

        # Un-register the action using its id
        result = ida_kernwin.unregister_action(self._ACTION_ID)
        if not result:
            return False

        # Free the custom icon using its id
        ida_kernwin.free_custom_icon(self._icon_id)
        self._icon_id = ida_idaapi.BADADDR

        self._plugin.logger.debug("Uninstalled action %s" % action_name)
        return True 
Example #2
Source File: goto_file_offset.py    From idawilli with Apache License 2.0 5 votes vote down vote up
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) 
Example #3
Source File: actions.py    From IDArling with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, plugin, menu, text, tooltip, icon, handler):
        super(Action, self).__init__()
        self._plugin = plugin

        self._menu = menu
        self._text = text
        self._tooltip = tooltip
        self._icon = icon
        self._icon_id = ida_idaapi.BADADDR
        self._handler = handler 
Example #4
Source File: hooks.py    From IDArling with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, plugin):
        super(HexRaysHooks, self).__init__(plugin)
        self._available = None
        self._installed = False
        self._func_ea = ida_idaapi.BADADDR
        self._labels = {}
        self._cmts = {}
        self._iflags = {}
        self._lvar_settings = {}
        self._numforms = {} 
Example #5
Source File: assembly.py    From rematch with GNU General Public License v3.0 5 votes vote down vote up
def data(self):
    func = ida_funcs.get_func(self.offset)

    def clean(asm):
      """This removes markers of function offsets, including hidden variable
      length offsets that are of different length on 32 and 64 bit address IDA.
      Otherwise, IDA of different offset lengths will truncate incorrect number
      of bytes"""
      hex_chars = int(log(ida_idaapi.BADADDR + 1, 2) / 4)
      pattern = "\x01\\([0-9a-zA-Z]{%s}(.*?)\x02\\)" % hex_chars
      replace = r"\g<1>"
      return re.sub(pattern, replace, asm)

    # make sure only nodes inside the function are accounted for
    # this solves cascaded functions (when multiple functions share same ends)
    def node_contained(node):
      return (ida_funcs.func_contains(func, node.startEA) and
              ida_funcs.func_contains(func, node.endEA - 1))
    nodes = filter(node_contained, ida_gdl.FlowChart(func))
    node_ids = map(lambda n: n.id, nodes)

    nodes_data = []
    for node in nodes:
      assembly = [clean(ida_lines.generate_disasm_line(ea))
                    for ea in idautils.Heads(node.startEA, node.endEA)]
      successive_nodes = [succ.id
                            for succ in node.succs()
                            if succ.id in node_ids]
      serialized_node = {'id': node.id, 'type': node.type,
                         'start': node.startEA, 'end': node.endEA,
                         'successive': successive_nodes, 'assembly': assembly}
      nodes_data.append(serialized_node)

    return nodes_data 
Example #6
Source File: idacyber.py    From IDACyber with MIT License 5 votes vote down vote up
def get_base(self, ea):
        base = ida_idaapi.BADADDR
        qty = ida_segment.get_segm_qty()
        for i in range(qty):
            seg = ida_segment.getnseg(i)
            if seg and seg.contains(ea):
                base = seg.start_ea
                break
        return base

# ----------------------------------------------------------------------- 
Example #7
Source File: ida_processor_drv_vm.py    From ida_haru with Apache License 2.0 4 votes vote down vote up
def handle_operand(self, insn, op, isRead):
      flags     = ida_bytes.get_flags(insn.ea)
      is_offs   = ida_bytes.is_off(flags, op.n)
      dref_flag = ida_xref.dr_R if isRead else ida_xref.dr_W
      def_arg   = ida_bytes.is_defarg(flags, op.n)
      optype    = op.type

      itype = insn.itype
      # create code xrefs
      if optype == ida_ua.o_imm:        
        makeoff = False
        if itype in [self.itype_ncall, self.itype_call]:
          insn.add_cref(op.value, op.offb, ida_xref.fl_CN)
          makeoff = True
        #elif itype == self.itype_mov: # e.g., mov #addr, PC
        #  insn.add_cref(op.value, op.offb, ida_xref.fl_JN)
        #  makeoff = True        
        if makeoff and not def_arg:
          otype = ida_offset.get_default_reftype(insn.ea)
          ida_offset.op_offset(insn.ea, op.n, otype, ida_idaapi.BADADDR, insn.cs)
          is_offs = True
        if is_offs:
          insn.add_off_drefs(op, ida_xref.dr_O, 0)
      elif optype == ida_ua.o_near:
        if insn.itype in [self.itype_ncall, self.itype_call]:
            fl = ida_xref.fl_CN
        else:
            fl = ida_xref.fl_JN
        insn.add_cref(op.addr, op.offb, fl)
      # create data xrefs
      elif optype == ida_ua.o_mem:
        insn.create_op_data(op.addr, op.offb, op.dtype)
        insn.add_dref(op.addr, op.offb, dref_flag)
        '''
        ds = ida_segment.get_segm_by_name('VM_DATA')        
        start = ds.start_ea
        insn.create_op_data(start + op.addr, op.offb, op.dtype)
        insn.add_dref(start + op.addr, op.offb, dref_flag)
        '''

    # ----------------------------------------------------------------------
    # The following callbacks are mandatory
    # 
Example #8
Source File: ida_processor_drv_vm.py    From ida_haru with Apache License 2.0 4 votes vote down vote up
def notify_out_operand(self, ctx, op):
      """
        Generate text representation of an instructon operand.
        This function shouldn't change the database, flags or anything else.
        All these actions should be performed only by the emu() function.
        This function uses out_...() functions from ua.hpp to generate the operand text
        Returns: 1-ok, 0-operand is hidden.
      """
      optype = op.type
      dtype = op.dtype
      signed = 0

      if optype == ida_ua.o_reg:
        if dtype == ida_ua.dt_byte:          
          #ctx.out_register('b')
          ctx.out_keyword('byte ')
        elif dtype == ida_ua.dt_word:          
          #ctx.out_register('w')
          ctx.out_keyword('word ')
        ctx.out_register(self.reg_names[op.reg])
      elif optype == ida_ua.o_phrase:
        if dtype == ida_ua.dt_dword:          
          ctx.out_keyword('dword ptr ')
        elif dtype == ida_ua.dt_byte:
          ctx.out_keyword('byte ptr ')
        elif dtype == ida_ua.dt_word:          
          ctx.out_keyword('word ptr ')
        ctx.out_symbol('[')
        ctx.out_register(self.reg_names[op.reg])
        ctx.out_symbol(']')
      elif optype == ida_ua.o_imm:
        ctx.out_symbol('#')
        ctx.out_value(op, ida_ua.OOFW_IMM | signed )
      elif optype in [ida_ua.o_near, ida_ua.o_mem]:
        r = ctx.out_name_expr(op, op.addr, ida_idaapi.BADADDR)
        if not r:
          ctx.out_tagon(ida_lines.COLOR_ERROR)
          ctx.out_long(op.addr, 16)
          ctx.out_tagoff(ida_lines.COLOR_ERROR)
          ida_problems.remember_problem(ida_problems.PR_NONAME, ctx.insn.ea)
      else:
        return False
        
      # for Op2 of mov instruction
      #if op.specflag1:
      #  ctx.out_keyword(' as ptr')

      return True

    # ----------------------------------------------------------------------