Python idaapi.tag_remove() Examples

The following are 8 code examples of idaapi.tag_remove(). 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 idaapi , or try the search function .
Example #1
Source File: ghida.py    From GhIDA with Apache License 2.0 6 votes vote down vote up
def add_comments(self, comment_list):
        """
        Updated the view with the available comments
        """
        for item in comment_list:
            lineno = item[0]
            comment = item[1]
            if len(comment) == 0:
                continue
            line = self.GetLine(lineno)
            if not line:
                print("GhIDA:: [!] line not found")
                continue
            line_text = line[0]
            if not line_text:
                print("GhIDA:: [!] line-text not found")
                continue
            line_text = idaapi.tag_remove(line_text) + comment
            new_line = self.color_line(line_text)
            self.EditLine(lineno, new_line)

        self.Refresh()
        print("GhIDA:: [DEBUG] updated comments terminated")
        return 
Example #2
Source File: LazyIDA.py    From LazyIDA with MIT License 6 votes vote down vote up
def callback(self, event, *args):
        if event == idaapi.hxe_populating_popup:
            form, phandle, vu = args
            if vu.item.citype == idaapi.VDI_FUNC or (vu.item.citype == idaapi.VDI_EXPR and vu.item.e.is_expr() and vu.item.e.type.is_funcptr()):
                idaapi.attach_action_to_popup(form, phandle, ACTION_HX_REMOVERETTYPE, None)
        elif event == idaapi.hxe_double_click:
            vu, shift_state = args
            # auto jump to target if clicked item is xxx->func();
            if vu.item.citype == idaapi.VDI_EXPR and vu.item.e.is_expr():
                expr = idaapi.tag_remove(vu.item.e.print1(None))
                if "->" in expr:
                    # find target function
                    name = expr.split("->")[-1]
                    addr = idc.get_name_ea_simple(name)
                    if addr == idaapi.BADADDR:
                        # try class::function
                        e = vu.item.e
                        while e.x:
                            e = e.x
                        addr = idc.get_name_ea_simple("%s::%s" % (str(e.type).split()[0], name))

                    if addr != idaapi.BADADDR:
                        idc.jumpto(addr)
                        return 1
        return 0 
Example #3
Source File: function.py    From ida-minsc with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def decompile(cls, ea):
        '''(UNSTABLE) Returns the decompiled code of the basic block at the address `ea`.'''
        source = idaapi.decompile(ea)

        res = itertools.imap(functools.partial(operator.__getitem__, source.eamap), cls.iterate(ea))
        res = itertools.chain(*res)
        formatted = reduce(lambda t, c: t if t[-1].ea == c.ea else t+[c], res, [next(res)])

        res = []
        # FIXME: This has been pretty damn unstable in my tests.
        try:
            for fmt in formatted:
                res.append( fmt.print1(source.__deref__()) )
        except TypeError: pass
        res = itertools.imap(idaapi.tag_remove, res)
        return '\n'.join(map(utils.string.of, res)) 
Example #4
Source File: registers.py    From deREferencing with GNU General Public License v3.0 6 votes vote down vote up
def switch_value(self):
        lineno = self.GetLineNo()
        if lineno > len(dbg.registers.flags):
            return

        line = self.GetLine(lineno)
        line = idaapi.tag_remove(line[0])
        flag = line[:4].strip()
        new_val = not self.flag_vals[flag]

        rc = idc.set_reg_value(int(new_val), flag)
        if not rc:
            idaapi.warning("Unable to update the register value")
            return

        self.parent.reload_view() 
Example #5
Source File: instruction.py    From ida-minsc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def op_repr(ea, opnum):
    '''Returns the representation for the operand `opnum` belonging to the instruction at the address `ea`.'''
    insn = at(ea)
    oppr = idaapi.ua_outop2 if idaapi.__version__ < 7.0 else idaapi.print_operand
    outop = utils.fcompose(idaapi.ua_outop2, idaapi.tag_remove) if idaapi.__version__ < 7.0 else utils.fcompose(idaapi.print_operand, idaapi.tag_remove)
    try:
        res = outop(insn.ea, opnum) or "{:s}".format(op(insn.ea, opnum))
    except:
        logging.warn(u"{:s}({:#x}, {:d}) : Unable to strip tags from operand \"{:s}\". Returning the result from {:s} instead.".format('.'.join((__name__, 'op_repr')), ea, opnum, utils.string.escape(oppr(insn.ea, opnum), '"'), '.'.join((__name__, 'op'))))
        return u"{!s}".format(op(insn.ea, opnum))
    return utils.string.of(res) 
Example #6
Source File: custom.py    From deREferencing with GNU General Public License v3.0 5 votes vote down vote up
def get_current_word(self):
        word = self.GetCurrentWord()
        if word:
            word = idaapi.tag_remove(word)
        return word 
Example #7
Source File: registers.py    From deREferencing with GNU General Public License v3.0 5 votes vote down vote up
def get_selected_reg(self):
        reg = None
        lineno = self.GetLineNo()
        if lineno > len(dbg.registers)-1:
            return reg

        line = self.GetLine(lineno)
        if line and len(line) > 0:
            line_str = idaapi.tag_remove(line[0])
            reg = line_str[1:dbg.registers.max_len+2].strip()
        return reg 
Example #8
Source File: ghida.py    From GhIDA with Apache License 2.0 4 votes vote down vote up
def add_comment(self):
        """
        Add a commment to the selected line
        """
        print("GhIDA:: [DEBUG] add_comment called")
        colored_line = self.GetCurrentLine(notags=1)
        if not colored_line:
            idaapi.warning("Select a line")
            return False

        # Use pygments to parse the line to check if there are comments
        line = idaapi.tag_remove(colored_line)
        lexer = CLexer()
        tokens = list(lexer.get_tokens(line))
        text = ""
        text_comment = ""
        for t in tokens:
            ttype = t[0]
            ttext = str(t[1])
            if ttype == Token.Comment.Single:
                text_comment = ttext.replace('//', '').strip()
            else:
                text += ttext

        # Get the new comment
        comment = gl.display_comment_form(text_comment)
        if not comment or len(comment) == 0:
            return False
        comment = comment.replace("//", "").replace("\n", " ")
        comment = comment.strip()

        # Create the new text
        full_comment = "\t// %s" % comment
        text = text.rstrip()
        new_text = text + full_comment
        text_colored = self.color_line(new_text)

        num_line = self.GetLineNo()
        self.EditLine(num_line, text_colored)
        self.RefreshCurrent()

        # Add comment to cache
        COMMENTS_CACHE.add_comment_to_cache(self.__ea, num_line, full_comment)

        print("GhIDA:: [DEBUG] Added comment to #line: %d (%s)" %
              (num_line, new_text))
        return