def semantic_change_instructions(self, t2o, version): insts = [] for line in open( multiplatform.dir_entry(self.version_dir(version), "semantic_changes")): insts = insts + t2o[int(line, base=16)] # This returns a list return insts
class BinDiff(ida.matcher.Matcher): matcher_suffix = ".BinDiff" def binExport(self, exe, suffix, path): logging.info("BinExport for %s" % exe) ida.run_Ida_Script("%s" % exe, "export.idc", suffix, path, [".BinExport"], options="ExporterModule:%s" % multiplatform.asLocal(path), add_idb=True) def run_BinDiff_once(self, v1, v2, out_file, suffix, path): ida.selectIdaSuffix(v1, suffix, path) ida.selectIdaSuffix(v2, suffix, path) logging.info( "Running BinDiff, comparing file %s with %s (with suffix %s)", v1, v2, suffix) self.binExport(v1, suffix, path) self.binExport(v2, suffix, path) logging.info("Diffing...") # TODO: log output? target_bindiff = "%s/%s_vs_%s.BinDiff" % (multiplatform.asLocal(path), v1, v2) try: os.remove(target_bindiff) except OSError, e: pass call([ settings.bindiff_exe, "-i%s" % multiplatform.dir_entry(path, "%s.BinExport" % v1), "-j%s" % multiplatform.dir_entry(path, "%s.BinExport" % v2), "-o%s" % multiplatform.asLocal(path) ]) logging.debug("Done") # If we didn't _move_ the file, we have twice as many .BinDiff files taking space, and if we re-run shutil.move(target_bindiff, out_file)
def runNormalization(experiment, in_binary, out_binary, suffix, useDiabloOutFile=True): try: outfilename = "%s.diablo.out" % out_binary diabloout = open(outfilename, "w") args = get_config_arguments( experiment.config) + ["-o", out_binary, in_binary] diabloout.write("# Called diablo with arguments:\n#%s\n" % " ".join(args)) print args if useDiabloOutFile: stdout = diabloout else: stdout = None try: os.remove(multiplatform.dir_entry(experiment.path, out_binary)) except OSError, e: pass diabloout.close() ### print settings.normalization_diablo onlinux.call(settings.normalization_diablo, args, pwd=experiment.path, outfile=outfilename) # shutil.move("mapping.xml", "mapping.xml.%s" % suffix) shutil.move("mapping.xml", "mapping.xml.%s" % suffix) if not os.path.isfile( multiplatform.dir_entry(experiment.path, out_binary)): raise Exception("Diablo Failed!!!!")
def generate_dynamic_info(experiment, exe): out = "%s%s.normalization_dyncfg.out" % (experiment.path, exe) xml = "%s%s.normalization_dyncfg.xml" % (experiment.path, exe) runDiota(experiment, exe, outfile=out, xml=xml, inputs="test") base = multiplatform.dir_entry(experiment.path, experiment.config.trace_prefix) tree = ElementTree() tree.parse(multiplatform.asLocal(xml)) dump_bbl(tree, base) dump_insts(tree, base) dump_edges(tree, base)
def evaluate(experiment, v1, v2, matchers): matches_v2 = matchers[0].get_instructions(experiment, v1, v2, which_version=v2) exe_v2 = binary_iteration_filename(experiment, v2) instructions_v2 = diablo.all_insts( multiplatform.dir_entry(experiment.path, "%s.xml" % exe_v2)) #full_name = "%s, %s" % (setting, experiment.name) full_name = experiment.name logging.info("===> SIZE FOR EXPERIMENT %s: %i" % (full_name, len(matches_v2))) logging.info("Instructions in binary: %i, matched: %i" % (len(instructions_v2), len(matches_v2))) logging.info( "===> PRUNING RATE FOR EXPERIMENT %s: %f (tot. abs. insts. count: %i)" % (full_name, (float(len(matches_v2)) / float(len(instructions_v2))), len(instructions_v2)))
#for chain in found: #log = "%s maps to: %i total, %i semantic changes" % (chain, found[chain].found_all, found[chain].found_changes) for i in [1, 2]: exe = binary_iteration_filename(experiment, i) ida.run_Ida(exe, extend_analysis=experiment.config.extend_IDA_analysis, path=experiment.path) matchers[0].match(experiment, 1, 2) matches_v2 = matchers[0].get_instructions(experiment, 1, 2, which_version=2) v2 = binary_iteration_filename(experiment, 2) instructions_v2 = diablo.all_insts( multiplatform.dir_entry(experiment.path, "%s.xml" % v2)) full_name = "%s, %s" % (setting, experiment.name) logging.info("===> SIZE FOR EXPERIMENT %s: %i" % (full_name, len(matches_v2))) logging.info("Instructions in binary: %i, matched: %i" % (len(instructions_v2), len(matches_v2))) logging.info( "===> PRUNING RATE FOR EXPERIMENT %s: %f (tot. abs. insts. count: %i)" % (full_name, (float(len(matches_v2)) / float(len(instructions_v2))), len(instructions_v2)))