Exemple #1
0
def single_feedback_test_raw(maxcost,
                             rounds,
                             start,
                             stop,
                             seed,
                             actions,
                             roundAction,
                             extra="",
                             binary_suffix=""):
    """ stop is not inclusive """
    config = DiversityConfig()

    config.experiment_dir = ""  # "exploratory/feedback_driven_scripted/hipeac_revision"

    config.extend_IDA_analysis = True
    config.allowed_transforms_per_function_output_file = "allowed_transforms_per_function_output_file.base"

    # We initialize the experiment with the basic config. This will set the path. Later on we might change the config, but the experiment's path will remain.
    benchmark_0 = rounds[0].benchmark
    config.experiment_dir += "/" + str(seed) + "_" + benchmark_0.exe + extra
    experiment = experiments.Experiment(
        config, benchmark_0, diablo_iterative.binary_iteration_filename)

    config.profile_file = benchmark_0.profile_file
    config.isThumb2 = benchmark_0.isThumb2

    experiment.binary_suffix = binary_suffix

    localDir = multiplatform.asLocal(experiment.path)
    try:
        os.makedirs(localDir)
    except OSError, e:
        print "Exception: %s" % str(e)
Exemple #2
0
 def version_dir(self, version, asLocal=True):
     """The version is an integer that gets mapped to the string representation of the"""
     d = self.dir_template % self.versions[version]
     if asLocal:
         return multiplatform.asLocal(d)
     else:
         return d
Exemple #3
0
def run_Ida(exe, extend_analysis, path):
    # Analyze the new binary with ida! (but remove the idb if it exists!)
    removeTempIdaFiles(exe, multiplatform.asLocal(path), rm_idb=True)

    run_Ida_Script(exe, "auto.idc", simple_suffix, path, [".idb"])

    if extend_analysis:
        print "Extending the analysis"
        run_Ida_Script(exe, "bzip.idc", extended_suffix, path, [".idb"])
Exemple #4
0
 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)
Exemple #5
0
def match(experiment, v1, v2, matchers):
    localDir = multiplatform.asLocal(experiment.path)
    os.chdir(localDir)

    for i in [v1, v2]:
        exe = binary_iteration_filename(experiment, i)
        ida.run_Ida(exe,
                    extend_analysis=experiment.config.extend_IDA_analysis,
                    path=experiment.path)

    matchers[0].match(experiment, v1, v2)
Exemple #6
0
def python(commands, imports, pwd=None, outfile=None, append=False, logerror=True):
  scriptfile  = "\n".join(map (lambda i: "import %s" % i, imports)) + "\n"
  scriptfile += "\n".join(commands)

  if pwd is not None:
	pythonscript_f = "%s/%s" % (pwd, settings.python_scriptfile)
  else:
	pythonscript_f = settings.python_scriptfile
  pythonscript = open(multiplatform.asLocal(pythonscript_f), "w")
  pythonscript.write(scriptfile)
  pythonscript.close()
  
  
  call("python", [pythonscript_f], pwd, outfile, append, logerror, env = { "PYTHONPATH": settings.python_path })
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)
Exemple #8
0
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)
Exemple #9
0
    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
experiment_simple = experiments.Experiment(
    config_simple, benchmark_0, diablo_iterative.binary_iteration_filename)
experiment_extended = experiments.Experiment(
    config_extended, benchmark_0, diablo_iterative.binary_iteration_filename)

#experiments = [ experiment_simple, experiment_extended ]
#iterations  = range(0, 2)

### ###
experiment_extended.binary_suffix = "_bindiff_oom"

experiments = [experiment_extended]
iterations = [0, 18]  #range(18, 19)

localDir = multiplatform.asLocal(experiment_simple.path)
os.chdir(localDir)
logging.basicConfig(filename='compare_files.log',
                    format='%(asctime)s %(levelname)s %(message)s',
                    level=logging.DEBUG)


def get_round_and_fix_experiment(current_iteration, rounds, experiment):
    feedbackRound = feedback_round.getFirstMatchingFeedbackRoundFromList(
        current_iteration, rounds)
    # This is somewhat fugly ###
    experiment.benchmark = feedbackRound.benchmark
    experiment.benchmark.version = feedbackRound.benchmarkVersion

    return feedbackRound
Exemple #11
0
def selectIdaSuffix(exe, suffix, path):
    removeTempIdaFiles(exe, multiplatform.asLocal(path))
    shutil.copy(
        multiplatform.local_dir_entry(path, exe + ".idb" + suffix + ".idb"),
        multiplatform.local_dir_entry(path, exe + ".idb"))
Exemple #12
0
for setting in ["stringsfout", "stringsjuist"]:
    config_simple.experiment_dir = setting
    config_extended.experiment_dir = config_simple.experiment_dir

    experiment_simple = experiments.Experiment(config_simple, tmp_benchmark,
                                               binary_iteration_filename)
    experiment_simple.name = "Basic Disassembly"
    experiment_extended = experiments.Experiment(config_extended,
                                                 tmp_benchmark,
                                                 binary_iteration_filename)
    experiment_extended.name = "Extended Disassembly"

    experimentslist = [experiment_simple, experiment_extended]

    for experiment in experimentslist:
        localDir = multiplatform.asLocal(experiment.path)
        os.chdir(localDir)

        #for matcher in matchers:
        #logging.info("Potentially doing analysis for matcher %s on iteration %i", str(matcher), current_iteration)
        #matcher.analyze(experiment, current_iteration)

        #for orig in feedbackRound.compareWith:
        #logging.info("Matching %i with %i using %s", orig, current_iteration, str(matcher))

        #matcher.match(experiment, orig, current_iteration)

        #logging.debug("... Matched")
        #found = ida.matcher.semantic_changes_found_count_filters(helper, matcher, experiment, orig, current_iteration, matcher.filters)

        #logging.debug("... Done")