def render_img(self, buffers, addr, mouse_offs): colors = [] head = ida_idaapi.BADADDR tail = ida_idaapi.BADADDR goffs = 0 for mapped, buf in buffers: if mapped: if mouse_offs is not None: if self.switch == 0: # data head = get_item_head(addr + mouse_offs) tail = get_item_end(addr + mouse_offs) else: # code f = get_func(addr + mouse_offs) if f: head = f.startEA tail = f.endEA for pos in xrange(len(buf)): c = ord(buf[pos]) & 0xFF highlight = False if mouse_offs is not None: if addr + pos + goffs >= head and addr + pos + goffs < tail: highlight = True if highlight: colors.append((True, qRgb(c, 0xFF, self.hl_color))) else: colors.append((True, qRgb(c, 0, 0))) else: for pos in xrange(len(buf)): colors.append((False, 0)) goffs += len(buf) return colors
def on_process_buffer(self, buffers, addr, size, mouse_offs): colors = [] goffs = 0 if mouse_offs is not None: head = get_item_head(addr + mouse_offs) tail = get_item_end(addr + mouse_offs) for mapped, buf in buffers: if mapped: for i in range(len(buf)): c = buf[i] if addr + i + goffs >= head and addr + i + goffs < tail: col = self.red[1] else: col = self.colormap[int( c / (0xff / (len(self.colormap) - 1)))] colors.append((True, col)) else: for i in range(len(buf)): if addr + i + goffs >= head and addr + i + goffs < tail: colors.append((False, self.red[0])) else: colors.append((False, None)) goffs += len(buf) return colors
def _convert_address_to_function(func): """Convert an address that IDA has classified incorrectly into a proper function.""" # If everything goes wrong, we'll try to restore this function. orig = idc.first_func_chunk(func) # If the address is not code, let's undefine whatever it is. if not ida_bytes.is_code(ida_bytes.get_full_flags(func)): if not is_mapped(func): # Well, that's awkward. return False item = ida_bytes.get_item_head(func) itemend = ida_bytes.get_item_end(func) if item != idc.BADADDR: _log(1, 'Undefining item {:#x} - {:#x}', item, itemend) ida_bytes.del_items(item, ida_bytes.DELIT_EXPAND) idc.create_insn(func) # Give IDA a chance to analyze the new code or else we won't be able to create a # function. #ida_auto.auto_wait() autoanalyze() idc.plan_and_wait(item, itemend) else: # Just try removing the chunk from its current function. IDA can add it to another function # automatically, so make sure it's removed from all functions by doing it in loop until it # fails. for i in range(1024): if not idc.remove_fchunk(func, func): break # Now try making a function. if ida_funcs.add_func(func) != 0: return True # This is a stubborn chunk. Try recording the list of chunks, deleting the original function, # creating the new function, then re-creating the original function. if orig != idc.BADADDR: chunks = list(idautils.Chunks(orig)) if ida_funcs.del_func(orig) != 0: # Ok, now let's create the new function, and recreate the original. if ida_funcs.add_func(func) != 0: if ida_funcs.add_func(orig) != 0: # Ok, so we created the functions! Now, if any of the original chunks are not # contained in a function, we'll abort and undo. if all(idaapi.get_func(start) for start, end in chunks): return True # Try to undo the damage. for start, _ in chunks: ida_funcs.del_func(start) # Everything we've tried so far has failed. If there was originally a function, try to restore # it. if orig != idc.BADADDR: _log(0, 'Trying to restore original function {:#x}', orig) ida_funcs.add_func(orig) return False
def on_process_buffer(self, buffers, addr, size, mouse_offs): colors = [] head = BADADDR tail = BADADDR goffs = 0 for mapped, buf in buffers: if mapped: if mouse_offs is not None: if self.switch == 0: # data head = get_item_head(addr + mouse_offs) tail = get_item_end(addr + mouse_offs) else: # code f = get_func(addr + mouse_offs) if f: head = f.startEA tail = f.endEA for pos in xrange(len(buf)): c = ord(buf[pos]) & 0xFF highlight = False if mouse_offs is not None: if addr + pos + goffs >= head and addr + pos + goffs < tail: highlight = True if self.last_sel: lhead, lsize = self.last_sel if addr + pos + goffs >= lhead and addr + pos + goffs < lhead+lsize: highlight = True if highlight: colors.append((True, qRgb(c, 0xFF, self.hl_color))) else: colors.append((True, qRgb(c, 0, 0))) else: for pos in xrange(len(buf)): colors.append((False, None)) goffs += len(buf) return colors