Пример #1
0
def get_coverage_db(dirname, bv):
    covdb_name = get_coverage_object_name(dirname)
    start = time.time()
    if os.path.exists(covdb_name):
        sys.stdout.write("[*] Loading coverage from object file %s..." %
                         covdb_name)
        sys.stdout.flush()
        covdb = coverage.CoverageDB(bv, covdb_name)
        duration = time.time() - start
        num_files = len(covdb.coverage_files)
        print(" finished (%d files) in %.02f seconds" % (num_files, duration))
    else:
        sys.stdout.write("[*] Creating coverage db from directory %s..." %
                         dirname)
        sys.stdout.flush()
        covdb = coverage.CoverageDB(bv)
        covdb.add_directory(dirname)
        duration = time.time() - start
        num_files = len(os.listdir(dirname))
        print(" finished (%d files) in %.02f seconds" % (num_files, duration))
        # Including for example, disabling to reduce surprise
        # try:
        #     import msgpack  # dependency for save_to_file
        #     sys.stdout.write("[*] Saving coverage object to file '%s'..." % covdb_name)
        #     sys.stdout.flush()
        #     start = time.time()
        #     covdb.save_to_file(covdb_name)
        #     duration = time.time() - start
        #     print(" finished in %.02f seconds" % duration)
        # except ImportError:
        #     pass
    return covdb
Пример #2
0
def get_coverage_db(dirname, bv):
    # Allow specification of covdb files directly
    if dirname.endswith(".covdb"):
        covdb_name = dirname
    else:
        covdb_name = os.path.basename(dirname + ".covdb")

    start = time.time()
    if os.path.exists(covdb_name):
        sys.stdout.write('[L] Loading coverage from object file "%s"...' % covdb_name)
        sys.stdout.flush()
        covdb = coverage.CoverageDB(bv, covdb_name)
        duration = time.time() - start
        num_files = len(covdb.coverage_files)
        print(" finished (%d files) in %.02f seconds" % (num_files, duration))
    elif os.path.isdir(dirname):
        sys.stdout.write('[C] Creating coverage db from directory "%s"...' % dirname)
        sys.stdout.flush()
        covdb = coverage.CoverageDB(bv)
        covdb.add_directory(dirname)
        duration = time.time() - start
        num_files = len(os.listdir(dirname))
        print(" finished (%d files) in %.02f seconds" % (num_files, duration))
    elif os.path.isfile(dirname):
        sys.stdout.write('[C] Creating coverage db from file "%s"...' % dirname)
        sys.stdout.flush()
        covdb = coverage.CoverageDB(bv)
        covdb.add_file(dirname)
        duration = time.time() - start
        print(" finished in %.02f seconds" % duration)
    else:
        raise Exception('[!] File "%s" not a file or directory?' % dirname)

    return covdb
Пример #3
0
def get_coverage_db(dirname, bv):
    # Allow specification of covdb files directly
    if dirname.endswith(".covdb"):
        covdb_name = dirname
    else:
        covdb_name = os.path.basename(dirname + ".covdb")

    start = time.time()
    if os.path.exists(covdb_name):
        sys.stdout.write("[L] Loading coverage from object file %s..." % covdb_name)
        sys.stdout.flush()
        covdb = coverage.CoverageDB(bv, covdb_name)
        duration = time.time() - start
        num_files = len(covdb.coverage_files)
        print(" finished (%d files) in %.02f seconds" % (num_files, duration))
    else:
        sys.stdout.write("[C] Creating coverage db from directory %s..." % dirname)
        sys.stdout.flush()
        covdb = coverage.CoverageDB(bv)
        covdb.add_directory(dirname)
        duration = time.time() - start
        num_files = len(os.listdir(dirname))
        print(" finished (%d files) in %.02f seconds" % (num_files, duration))

        try:
            import msgpack  # dependency for save_to_file
            sys.stdout.write("[S] Saving coverage object to file '%s'..." % covdb_name)
            sys.stdout.flush()
            start = time.time()
            covdb.save_to_file(covdb_name)
            duration = time.time() - start
            print(" finished in %.02f seconds" % duration)
        except ImportError:
            pass
    return covdb
Пример #4
0
    os.path.dirname(os.path.dirname(os.path.dirname(
        os.path.abspath(__file__)))))
import bncov.coverage as coverage

if __name__ == "__main__":
    if len(sys.argv) != 3:
        print("USAGE: %s <target_file> <coverage_directory>" % sys.argv[0])
        exit()
    filename = sys.argv[1]
    coverage_dir = sys.argv[2]

    bv = BinaryViewType.get_view_of_file(filename)
    bv.update_analysis_and_wait()
    print("[*] Loaded %s" % filename)

    covdb = coverage.CoverageDB(bv)
    covdb.add_directory(coverage_dir)

    print(covdb.module_name)
    print("Module base: 0x%x" % covdb.module_base)
    print("Files (%d): %s" %
          (len(covdb.coverage_files), len(covdb.trace_dict.keys())))
    print("Blocks: %d %d" % (len(covdb.block_dict), len(covdb.total_coverage)))

    frontier = covdb.get_frontier()
    print("Frontier: %s" % repr(frontier))
    print("Rare blocks: %s" % repr(covdb.get_rare_blocks()))

    rare_block = covdb.get_rare_blocks()[0]
    print("Traces for rare block: %s" %
          repr(covdb.get_traces_from_block(rare_block)))