Python idaapi.COLSTR Examples

The following are 22 code examples of idaapi.COLSTR(). 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: ropviewer.py    From DrGadget with MIT License 6 votes vote down vote up
def create_colored_line(self, n):
        # todo
        item = self.get_item(n)
        if item != None:
            typ = item.type

            width = self.payload.proc.get_pointer_size()
            cline = idaapi.COLSTR("%04X  " % (n * width), idaapi.SCOLOR_AUTOCMT)
            ea = item.ea
            fmt = self.payload.proc.get_data_fmt_string()
            elem = fmt % ea
            if typ == Item.TYPE_CODE:
                color = idaapi.SCOLOR_CODNAME if SegStart(ea) != BADADDR else idaapi.SCOLOR_ERROR
                elem = idaapi.COLSTR(elem, color)
            else:
                elem = idaapi.COLSTR(elem, idaapi.SCOLOR_DNUM)
            cline += elem

            comm = ""
            if len(item.comment):
                comm += " ; %s" % item.comment
            if len(comm):
                cline += idaapi.COLSTR(comm, idaapi.SCOLOR_AUTOCMT)
            return cline 
Example #2
Source File: payload.py    From DrGadget with MIT License 6 votes vote down vote up
def get_disasm(self, ea):
        disasm = []
        insns = self.get_disasm_internal(ea)

        for i in insns:
            if i != None:
                ea,ins,line,isret,strm = i
                strm = to_hex_str(strm)
                if isret:
                    color = idaapi.SCOLOR_CREFTAIL
                else:
                    color = idaapi.SCOLOR_CODNAME
                asm = idaapi.COLSTR("%s\n" % line, color)
                data = idaapi.COLSTR("%s\n" % strm, color)
            else:
                asm = idaapi.COLSTR("; invalid instruction \n", idaapi.SCOLOR_HIDNAME)
                data = ""
            disasm.append((asm, data))
        if len(disasm) == self.get_max_insn():
            cont = idaapi.COLSTR("...", idaapi.SCOLOR_HIDNAME)
            disasm.append((cont, cont))
        return disasm 
Example #3
Source File: colorizer.py    From deREferencing with GNU General Public License v3.0 5 votes vote down vote up
def as_comment(self, s):
        return idaapi.COLSTR(s, idaapi.SCOLOR_AUTOCMT) 
Example #4
Source File: colorizer.py    From deREferencing with GNU General Public License v3.0 5 votes vote down vote up
def as_value(self, s):
        return idaapi.COLSTR(s, idaapi.SCOLOR_SYMBOL) 
Example #5
Source File: colorizer.py    From deREferencing with GNU General Public License v3.0 5 votes vote down vote up
def as_rwx(self, s):
        return idaapi.COLSTR(s, idaapi.SCOLOR_MACRO) 
Example #6
Source File: colorizer.py    From deREferencing with GNU General Public License v3.0 5 votes vote down vote up
def as_data(self, s):
        return idaapi.COLSTR(s, idaapi.SCOLOR_IMPNAME) 
Example #7
Source File: colorizer.py    From deREferencing with GNU General Public License v3.0 5 votes vote down vote up
def as_code(self, s):
        return idaapi.COLSTR(s, idaapi.SCOLOR_CREFTAIL) 
Example #8
Source File: colorizer.py    From deREferencing with GNU General Public License v3.0 5 votes vote down vote up
def as_heap(self, s):
        return idaapi.COLSTR(s, idaapi.SCOLOR_VOIDOP) 
Example #9
Source File: colorizer.py    From deREferencing with GNU General Public License v3.0 5 votes vote down vote up
def as_stack(self, s):
        return idaapi.COLSTR(s, idaapi.SCOLOR_SEGNAME) 
Example #10
Source File: registers.py    From deREferencing with GNU General Public License v3.0 5 votes vote down vote up
def as_changed(self, s):
        return idaapi.COLSTR(s, idaapi.SCOLOR_CREFTAIL) 
Example #11
Source File: graph_ir.py    From miasm with GNU General Public License v2.0 5 votes vote down vote up
def color_irblock(irblock, ir_arch):
    out = []
    lbl = idaapi.COLSTR("%s:" % ir_arch.loc_db.pretty_str(irblock.loc_key), idaapi.SCOLOR_INSN)
    out.append(lbl)
    for assignblk in irblock:
        for dst, src in sorted(viewitems(assignblk)):
            dst_f = expr2colorstr(dst, loc_db=ir_arch.loc_db)
            src_f = expr2colorstr(src, loc_db=ir_arch.loc_db)
            line = idaapi.COLSTR("%s = %s" % (dst_f, src_f), idaapi.SCOLOR_INSN)
            out.append('    %s' % line)
        out.append("")
    out.pop()
    return "\n".join(out) 
Example #12
Source File: utils.py    From miasm with GNU General Public License v2.0 5 votes vote down vote up
def from_ExprSlice(self, expr):
        base = self.from_expr(expr.arg)
        start = idaapi.COLSTR(str(expr.start), idaapi.SCOLOR_RPTCMT)
        stop = idaapi.COLSTR(str(expr.stop), idaapi.SCOLOR_RPTCMT)
        out = "(%s)[%s:%s]" % (base, start, stop)
        return out 
Example #13
Source File: utils.py    From miasm with GNU General Public License v2.0 5 votes vote down vote up
def from_ExprMem(self, expr):
        ptr = self.from_expr(expr.ptr)
        size = idaapi.COLSTR('@' + str(expr.size), idaapi.SCOLOR_RPTCMT)
        out = '%s[%s]' % (size, ptr)
        return out 
Example #14
Source File: utils.py    From miasm with GNU General Public License v2.0 5 votes vote down vote up
def from_ExprLoc(self, expr):
        if self.loc_db is not None:
            out = self.loc_db.pretty_str(expr.loc_key)
        else:
            out = str(expr)
        out = idaapi.COLSTR(out, idaapi.SCOLOR_REG)
        return out 
Example #15
Source File: utils.py    From miasm with GNU General Public License v2.0 5 votes vote down vote up
def from_ExprId(self, expr):
        out = idaapi.COLSTR(str(expr), idaapi.SCOLOR_REG)
        return out 
Example #16
Source File: utils.py    From miasm with GNU General Public License v2.0 5 votes vote down vote up
def from_ExprInt(self, expr):
        return idaapi.COLSTR(str(expr), idaapi.SCOLOR_NUMBER) 
Example #17
Source File: bingraph.py    From heap-viewer with GNU General Public License v3.0 5 votes vote down vote up
def bin_info(self, node_title, chunk_addr, chunk, with_size=True):
        line =  idaapi.COLSTR("%s " % node_title, idaapi.SCOLOR_NUMBER)
        line += idaapi.COLSTR("0x%x\n\n" % chunk_addr, idaapi.SCOLOR_INSN)

        chunk_info = ""
        if with_size:
            chunk_info += "size: 0x%x\n" % chunk.size

        chunk_info += "fd: 0x%x - %s\nbk: 0x%x - %s" % (chunk.fd, \
            idc.get_segm_name(chunk.fd), chunk.bk, idc.get_segm_name(chunk.bk))

        line += idaapi.COLSTR(chunk_info, idaapi.SCOLOR_DEFAULT)
        return line 
Example #18
Source File: bingraph.py    From heap-viewer with GNU General Public License v3.0 5 votes vote down vote up
def tcache_info(self, entry_addr, chunk_addr):        
        line =  idaapi.COLSTR("entry: ", idaapi.SCOLOR_NUMBER)
        line += idaapi.COLSTR("0x%x\n" % (entry_addr), idaapi.SCOLOR_INSN)
        line += idaapi.COLSTR("chunk: ", idaapi.SCOLOR_NUMBER)
        line += idaapi.COLSTR("0x%x" % (chunk_addr), idaapi.SCOLOR_INSN)
        return line 
Example #19
Source File: bingraph.py    From heap-viewer with GNU General Public License v3.0 5 votes vote down vote up
def chunk_info(self, chunk_addr, chunk):
        line =  idaapi.COLSTR("Chunk ", idaapi.SCOLOR_NUMBER)
        line += idaapi.COLSTR("0x%x\n\n" % (chunk_addr), idaapi.SCOLOR_INSN)
        line += idaapi.COLSTR("size: 0x%x\nfd: 0x%x - %s" % \
                (chunk.size, chunk.fd, idc.get_segm_name(chunk.fd)), SCOLOR_DEFAULT)
        return line 
Example #20
Source File: bingraph.py    From heap-viewer with GNU General Public License v3.0 5 votes vote down vote up
def warning_line(self, txt):
        return idaapi.COLSTR(txt, idaapi.SCOLOR_ERROR) 
Example #21
Source File: ropviewer.py    From DrGadget with MIT License 4 votes vote down vote up
def update_content_viewers(self, n=None):
        if n is None:
            n = self.GetLineNo()

        item = self.get_item(n)

        self.dav.clear()
        self.hv.clear()
        self.iv.clear()

        if item is not None:
            if item.type == Item.TYPE_CODE:
                # get disassembly and hex stream
                dis = self.payload.da.get_disasm(item.ea)
                for line in dis:
                    self.dav.add_line(line[0])
                    self.hv.add_line(line[1])

                # get various info
                seg = idaapi.getseg(item.ea)
                if seg:
                    name = idaapi.get_true_segm_name(seg)
                    perm = seg.perm
                    ltype = "ld" if seg.is_loader_segm() else "dbg"
                    ea_start = seg.startEA
                    ea_end = seg.endEA

                    perms = ""
                    perms += "R" if perm & idaapi.SEGPERM_READ != 0 else "."
                    perms += "W" if perm & idaapi.SEGPERM_WRITE != 0 else "."
                    perms += "X" if perm & idaapi.SEGPERM_EXEC != 0 else "."
                    self.iv.add_line("<%s> [%X - %X], %s, [%s]" % (name, ea_start, ea_end, ltype, perms))
            else:
                stype = GetStringType(item.ea)
                if stype is not None:
                    scontent = GetString(item.ea, -1, stype)
                    if scontent != None and len(scontent):
                        self.dav.add_line(idaapi.COLSTR("\"%s\"" % scontent, idaapi.SCOLOR_DSTR))
                        # length = idaapi.get_max_ascii_length(item.ea, stype, idaapi.ALOPT_IGNHEADS)
                        # self.hv.add_line()
                else:
                    scontent = GetString(item.ea, -1, ASCSTR_C)
                    if scontent != None and len(scontent):
                        self.dav.add_line("\"%s\"" % scontent)

        self.dav.update()
        self.hv.update()
        self.iv.update() 
Example #22
Source File: ghida.py    From GhIDA with Apache License 2.0 4 votes vote down vote up
def color_line(self, line):
        """
        """
        lexer = CLexer()
        tokens = list(lexer.get_tokens(line))
        new_line = ""
        for t in tokens:
            ttype = t[0]
            ttext = str(t[1])
            if ttype == Token.Text:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_INSN)

            elif ttype == Token.Text.Whitespace:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_INSN)

            elif ttype == Token.Error:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_ERROR)

            elif ttype == Token.Other:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_DSTR)

            elif ttype == Token.Keyword:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_KEYWORD)

            elif ttype == Token.Name:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_LIBNAME)

            elif ttype == Token.Literal:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_LOCNAME)

            elif ttype == Token.Literal.String:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_STRING)

            elif ttype == Token.Literal.Number:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_DNUM)

            elif ttype == Token.Operator:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_ALTOP)

            elif ttype == Token.Punctuation:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_SYMBOL)

            elif ttype == Token.Comment:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_REGCMT)

            elif ttype == Token.Comment.Single:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_REGCMT)

            elif ttype == Token.Generic:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_CREFTAIL)

            else:
                new_line += idaapi.COLSTR(ttext, idaapi.SCOLOR_CREFTAIL)
        return new_line