def resetBlocks(): p = idaapi.node_info_t() p.bg_color = 0xFFFFCC #fname = idaapi.get_root_filename() fname = idc.eval_idc("ARGV[1]") funs_file = fname + '.funs' if not os.path.isfile(funs_file): print('No file at %s\n Creating the database files needed by RESim.' % funs_file) resimUtils.dumpFuns(fname=fname) funs_fh = open(funs_file) fun_json = json.load(funs_fh) print('funs_file %s' % funs_file) for fun in fun_json: fun_addr = int(fun) #print('fun_addr 0x%x' % fun_addr) f = idaapi.get_func(fun_addr) #print('fun addr 0x%x' % fun_addr) #print('fun is %s' % str(f)) if f is None: #print('no function found for 0x%x' % fun_addr) continue #print('doing function found for 0x%x' % fun_addr) graph = ida_gdl.FlowChart(f, flags=ida_gdl.FC_PREDS) for bb in graph: ida_graph.set_node_info( fun_addr, bb.id, p, idaapi.NIF_BG_COLOR | idaapi.NIF_FRAME_COLOR)
def color(self, value): """ Property setter for changing the color of this basic block. .. warning:: This will **not** set correctly the color for a block which color has already been change using the GUI. Probably a bug in IDA or another item on top of it ? :param value: An integer representing the color to set at the BGR format. If value is ``None`` delete the color. """ if value is None: ida_graph.clr_node_info(self.func.ea, self._id, ida_graph.NIF_BG_COLOR) ida_kernwin.refresh_idaview_anyway() return ni = ida_graph.node_info_t() ni.bg_color = value ida_graph.set_node_info(self.func.ea, self._id, ni, ida_graph.NIF_BG_COLOR) ida_kernwin.refresh_idaview_anyway()
def doColor(latest_hits_file, all_hits_file, pre_hits_file): with open(latest_hits_file) as funs_fh: latest_hits_json = json.load(funs_fh) print('loaded blocks from %s, got %d functions' % (latest_hits_file, len(latest_hits_json))) with open(all_hits_file) as funs_fh: all_hits_json = json.load(funs_fh) print('loaded blocks from %s, got %d functions' % (all_hits_file, len(all_hits_json))) with open(pre_hits_file) as funs_fh: pre_hits_json = json.load(funs_fh) print('loaded blocks from %s, got %d functions' % (pre_hits_file, len(pre_hits_json))) p = idaapi.node_info_t() ''' New hits ''' p.bg_color = new_hit_color num_new = 0 edges = OrderedDict() for fun in latest_hits_json: fun_addr = int(fun) f = idaapi.get_func(fun_addr) #print('fun addr 0x%x' % fun_addr) graph = ida_gdl.FlowChart(f, flags=ida_gdl.FC_PREDS) ''' get edges leaving all hit blocks ''' ''' edges[branch_to] = branch_from ''' ''' retain order of hits in list of branches not taken ''' for bb_addr in latest_hits_json[fun]: ''' get the BB and check its branch-to's ''' block = getBB(graph, bb_addr) if block is not None: for s in block.succs(): if s.start_ea not in latest_hits_json[fun] and not (fun in pre_hits_json and s.start_ea in pre_hits_json[fun]) and s.start_ea not in edges: #print('added edges[0%x] block 0x%x block.end_ea 0x%x bb_addr was 0x%x ' % (s.start_ea, block.start_ea, block.end_ea, bb_addr)) ''' branch from block was not hit ''' edges[s.start_ea] = block.start_ea for bb in latest_hits_json[fun]: block = getBB(graph, bb) if block is not None: bb_id = block.id if fun not in all_hits_json or bb not in all_hits_json[fun]: ''' first time bb has been hit in any data session ''' p.bg_color = new_hit_color ida_graph.set_node_info(fun_addr, bb_id, p, idaapi.NIF_BG_COLOR | idaapi.NIF_FRAME_COLOR) print('new hit fun 0x%x bb: 0x%x bb_id: %d block.start_ea 0x%x end 0x%x' % (fun_addr, bb, bb_id, block.start_ea, block.end_ea)) num_new += 1 elif bb in all_hits_json[fun]: ''' also hit in earlier data session ''' p.bg_color = old_hit_color ida_graph.set_node_info(fun_addr, bb_id, p, idaapi.NIF_BG_COLOR | idaapi.NIF_FRAME_COLOR) #print('old hit fun 0x%x bb: 0x%x' % (fun_addr, bb)) else: print('impossible') exit(1) print('Data run generated %d new hits' % num_new) print('Unhit edges') ''' Not hit on recent data session, but hit previously ''' p.bg_color = not_hit_color for fun in all_hits_json: fun_addr = int(fun) f = idaapi.get_func(fun_addr) #print('fun addr 0x%x' % fun_addr) if f is None: print('unable to get function from addr 0x%x' % fun_addr) continue graph = ida_gdl.FlowChart(f, flags=ida_gdl.FC_PREDS) for bb in all_hits_json[fun]: bb_id = getBBId(graph, bb) if bb_id is not None: if fun not in latest_hits_json or bb not in latest_hits_json[fun]: ida_graph.set_node_info(fun_addr, bb_id, p, idaapi.NIF_BG_COLOR | idaapi.NIF_FRAME_COLOR) #print('not hit fun 0x%x bb: 0x%x' % (fun_addr, bb)) ''' Hit prior to start of any data session, i.e., IO setup ''' p.bg_color = pre_hit_color for fun in pre_hits_json: fun_addr = int(fun) f = idaapi.get_func(fun_addr) #print('fun addr 0x%x' % fun_addr) graph = ida_gdl.FlowChart(f, flags=ida_gdl.FC_PREDS) for bb in pre_hits_json[fun]: bb_id = getBBId(graph, bb) if bb_id is not None: if (fun not in latest_hits_json or bb not in latest_hits_json[fun]) and (fun not in all_hits_json or bb not in all_hits_json[fun]): ida_graph.set_node_info(fun_addr, bb_id, p, idaapi.NIF_BG_COLOR | idaapi.NIF_FRAME_COLOR) #print('not hit fun 0x%x bb: 0x%x' % (fun_addr, bb)) return edges
simicsString = gdbProt.Evalx('SendGDBMonitor("%s");' % command) print('so stuff: %s' % simicsString) if ':' in simicsString: adders = simicsString.split(':')[1] start = adders.split('-')[0] try: start_hex = int(start, 16) except ValueError: print('could not get hex from %s' % start) exit(1) else: exit(1) fun_json = json.load(funs_fh) print('funs_file %s' % funs_file) for fun in fun_json: fun_addr = int(fun) + start_hex #print('fun_addr 0x%x' % fun_addr) f = idaapi.get_func(fun_addr) #print('fun addr 0x%x' % fun_addr) #print('fun is %s' % str(f)) if f is None: #print('no function found for 0x%x' % fun_addr) continue print('doing function found for 0x%x' % fun_addr) graph = ida_gdl.FlowChart(f, flags=ida_gdl.FC_PREDS) for bb in graph: ida_graph.set_node_info(fun_addr, bb.id, p, idaapi.NIF_BG_COLOR | idaapi.NIF_FRAME_COLOR) #print('funx 0x%x set bb_id %d' % (fun_addr, bb.id))
import json import idaapi import ida_graph def getBB(graph, bb): for block in graph: if block.start_ea <= bb and block.end_ea >= bb: return block.id return None fname = get_root_filename() funs_fh = open(fname + '.hits') fun_json = json.load(funs_fh) for fun in fun_json: fun_addr = int(fun) f = idaapi.get_func(fun_addr) graph = idaapi.FlowChart(f) for bb in fun_json[fun]: bb_id = getBB(graph, bb) if bb_id is not None: p = idaapi.node_info_t() p.bg_color = 0x00ff00 ida_graph.set_node_info( bb, bb_id, p, idaapi.NIF_BG_COLOR | idaapi.NIF_FRAME_COLOR) print('fun 0x%x set bb 0x%x bb_id %d' % (fun_addr, bb, bb_id))