def export(self, filename): print('export %s' % filename) try: binkit = idaapi.load_plugin('BinKit') if binkit: idc_command = ("SaveBinKitAnalysis(\"%s\");" % (filename)).replace("\\", "\\\\") print(idc_command) idc.eval_idc(str(idc_command)) except: traceback.print_exc() pass
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 getOffset(self): retval = None #fname = idaapi.get_root_filename() fname = idc.eval_idc("ARGV[1]") command = "@cgc.getSOFromFile('%s')" % fname simicsString = gdbProt.Evalx('SendGDBMonitor("%s");' % command) print('so stuff: %s' % simicsString) if ':' in simicsString: adders = simicsString.split(':')[1] start = adders.split('-')[0] try: retval = int(start,16) except ValueError: print('could not get hex from %s' % start) return retval
def getEdges(): ''' return list of branches not taken ''' resim_ida_data = os.getenv('RESIM_IDA_DATA') if resim_ida_data is None: print('RESIM_IDA_DATA not defined.') else: #in_path = idaapi.get_root_filename() in_path = idc.eval_idc("ARGV[1]") base = os.path.basename(in_path) fname = os.path.join(resim_ida_data, base, base) latest_hits_file = fname + '.hits' if not os.path.isfile(latest_hits_file): ''' maybe a symbolic link, ask monitor for name ''' cmd = '@cgc.getCoverageFile()' latest_hits_file = gdbProt.Evalx('SendGDBMonitor("%s");' % cmd).strip() if not os.path.isfile(latest_hits_file): print('No hits file found %s' % latest_hits_file) return command = "@cgc.getSOFromFile('%s')" % fname simicsString = gdbProt.Evalx('SendGDBMonitor("%s");' % command) #print('command: %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) return all_hits_file = fname + '.all.hits' pre_hits_file = fname + '.pre.hits' edges = doEdges(latest_hits_file, all_hits_file, pre_hits_file, start_hex, in_path) return edges
''' import sys import os import idc import ida_dbg here = os.path.join(os.getenv('RESIM_DIR'), 'simics', 'ida') sys.path.append(here) import colorBlocks import resetBlocks import rev import time import reHooks import subprocess ok = True arg_count = idc.eval_idc("ARGV.count") target_path = idc.eval_idc("ARGV[1]") print('in runsFirst target_path %s' % target_path) if arg_count > 2: arg1 = idc.eval_idc("ARGV[2]") if arg1 == 'color': print('did color') ''' if arg_count > 3: remote = idc.eval_idc("ARGV[3]") cmd = 'ssh %s "echo \$RESIM_IDA_DATA"' % (remote) ps = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE) ida_data = ps.communicate()[0].decode('utf-8').strip() print('ida_data at %s' % ida_data) in_path = idaapi.get_root_filename() infile = os.path.basename(in_path)