def color_eas(self, cfunc, tainted_pcs):
     # the plugins/bap/utils/hexrays.py file found at
     # https://github.com/BinaryAnalysisPlatform/bap-ida-python/ was
     # invaluable in determining how to extract the effective addresses
     # from each pseudocode line
     sv = cfunc.get_pseudocode()
     anchor = ida_hexrays.ctree_anchor_t()
     for i in range(len(sv)):
         curline = copy(sv[i].line)
         while (len(curline) > 0):
             skipcode_index = ida_lines.tag_skipcode(curline)
             if (0 == skipcode_index):
                 # no code found, go to next character
                 curline = curline[1:]
             else:
                 if (self.tag_addrcode(curline)):
                     addr_tag = int(curline[2:skipcode_index], 16)
                     anchor.value = addr_tag
                     if (anchor.is_citem_anchor()
                             and not anchor.is_blkcmt_anchor()):
                         address = cfunc.treeitems.at(addr_tag).ea
                         if (address != ida_idaapi.BADADDR):
                             if (address in tainted_pcs):
                                 sv[i].bgcolor = INST_COLOR
                 curline = curline[skipcode_index:]
Example #2
0
def replace_addr_tags(cfunc, s):
    tag = "%c%c" % (il.COLOR_ON, il.COLOR_ADDR)
    tag_size = len(tag)
    ti = {}
    p = s.find(tag)
    while p != -1:
        ti[s[p+tag_size:p+tag_size+il.COLOR_ADDR_SIZE]] = 0
        p = s.find(tag, p+tag_size+il.COLOR_ADDR_SIZE)
    for addr in ti.keys():
        idx = int(addr, 16)
        a = ida_hexrays.ctree_anchor_t()
        a.value = idx
        if a.is_valid_anchor() and a.is_citem_anchor():
            item = cfunc.treeitems.at(a.get_index())
            if item:
                ctype_name = ida_hexrays.get_ctype_name(item.op)
                s = s.replace(tag+addr, il.COLSTR("<%s>" % ctype_name, il.SCOLOR_AUTOCMT)+tag+addr)
    return s
Example #3
0
def get_obj_ids(vdui, lnnum):
    obj_ids = []
    pc = vdui.cfunc.get_pseudocode()
    if lnnum >= len(pc):
        return obj_ids
    line = pc[lnnum].line
    tag = ida_lines.COLOR_ON + chr(ida_lines.COLOR_ADDR)
    pos = line.find(tag)
    while pos != -1 and len(
            line[pos + len(tag):]) >= ida_lines.COLOR_ADDR_SIZE:
        addr = line[pos + len(tag):pos + len(tag) + ida_lines.COLOR_ADDR_SIZE]
        idx = int(addr, 16)
        a = ida_hexrays.ctree_anchor_t()
        a.value = idx
        if a.is_valid_anchor() and a.is_citem_anchor():
            item = vdui.cfunc.treeitems.at(a.get_index())
            if item:
                obj_ids.append(item.obj_id)
        pos = line.find(tag, pos + len(tag) + ida_lines.COLOR_ADDR_SIZE)
    return obj_ids