Esempio n. 1
0
 def test_duplicate_files(self):
     for mode in self.mode_to_binary:
         binary = self.mode_to_binary[mode]
         with quickcov.QuickCov(binary,
                                "--dwarf-check -C -g -f -dwarf -x @@",
                                mode=mode) as q:
             # sort files by id to get the creation date
             timestamps = {}
             files = sorted(get_queue_files(QUEUE_PATH))
             for x, f in enumerate(sorted(files)):
                 timestamps[f] = x
             (plot, bitmap,
              final_coverage) = q.get_coverage(files,
                                               plot=True,
                                               time_dict=timestamps)
             including_duplicate_files = list(files)
             # duplicate files, count coverage again
             for f in files:
                 shutil.copyfile(
                     f,
                     os.path.join(os.path.dirname(f),
                                  "%s-dup" % os.path.basename(f)))
                 including_duplicate_files.append(f)
             (plot_dup, bitmap_dup, final_coverage_dup) = q.get_coverage(
                 including_duplicate_files, plot=True, time_dict=timestamps)
             self.assertEqual(final_coverage, final_coverage_dup)
Esempio n. 2
0
 def test_basic(self):
     for mode in self.mode_to_binary:
         binary = self.mode_to_binary[mode]
         with quickcov.QuickCov(binary,
                                "--dwarf-check -C -g -f -dwarf -x @@",
                                mode=mode) as q:
             plots = {}
             bitmaps = {}
             for i in range(NUM_RUNS):
                 # sort files by id to get the creation date
                 timestamps = {}
                 files = sorted(get_queue_files(QUEUE_PATH))
                 for x, f in enumerate(sorted(files)):
                     timestamps[f] = x
                 (plots[i], bitmaps[i],
                  final_coverage) = q.get_coverage(files,
                                                   plot=True,
                                                   time_dict=timestamps)
                 self.assertTrue(final_coverage > 1)
                 self.assertTrue(bitmaps[i].count() > 0)
                 self.assertEqual(len(plots[i].keys()), len(files))
                 self.assertTrue(plots[i][min(plots[i].keys())] < plots[i][
                     max(plots[i].keys())])
                 last = 0
                 for t in sorted(plots[i], key=lambda x: x):
                     self.assertTrue(last <= plots[i][t])
                     last = plots[i][t]
             for i in range(NUM_RUNS):
                 for j in range(NUM_RUNS):
                     self.assertCountEqual(plots[i].values(),
                                           plots[j].values())
Esempio n. 3
0
 def test_persistent_mode(self):
     with quickcov.QuickCov("quickcov_instrumented/boringssl-2016-02-12",
                            "@@") as q:
         plots = {}
         bitmaps = {}
         for i in range(NUM_RUNS):
             # sort files by id to get the creation date
             timestamps = {}
             files = sorted(get_queue_files(QUEUE_PATH))
             for x, f in enumerate(sorted(files)):
                 timestamps[f] = x
             (plots[i], bitmaps[i],
              final_coverage) = q.get_coverage(files,
                                               plot=True,
                                               time_dict=timestamps)
             self.assertTrue(final_coverage > 1)
             self.assertEqual(len(plots[i].keys()), len(files))
             last = 0
             for t in sorted(plots[i], key=lambda x: x):
                 self.assertTrue(last <= plots[i][t])
                 last = plots[i][t]
             # has the first input lower coverage than the last?
             self.assertTrue(plots[i][list(plots[i].keys())[0]] < plots[i][
                 list(plots[i].keys())[-1]])
         for i in range(NUM_RUNS):
             for j in range(NUM_RUNS):
                 self.assertCountEqual(plots[i].values(), plots[j].values())
Esempio n. 4
0
  def __init__(self, binary, input_file=None, q=None):
    self.set_binary(binary)
    self.config = {}
    self.directories = []
    self.start_time = get_unix_timestamp()
    self.fuzzer_manager = None

    self.id = Fuzzer.fuzzer_id
    self.sync_id = get_sync_id()
    Fuzzer.fuzzer_id += 1
    
    self.input_directory  = GLOBAL_INPUT_DIRECTORY
    self.input_file = input_file
    self._setup_input_directory()
    self.output_directory = GLOBAL_OUTPUT_DIRECTORY
    if not os.path.isdir(self.output_directory):
      os.makedirs(self.output_directory)

    self._setup_output_directory()

    if q is None:
      self.q = quickcov.QuickCov(os.path.join(QUICKCOV_PATH, self.full_binary), self.binary_arguments)
    else:
      self.q = q
    
    self.init_config()
    self.init_names()
Esempio n. 5
0
 def test_dump_basic_blocks_ptrace(self):
     plots = {}
     traces = {}
     for i in range(NUM_RUNS):
         with quickcov.QuickCov("quickcov_uninstrumented/objdump",
                                "--dwarf-check -C -g -f -dwarf -x @@",
                                mode=quickcov.ExecuterMode.PTRACE) as q:
             files = sorted(get_queue_files(QUEUE_PATH))
             (plots[i], traces[i],
              final_coverage) = q.get_coverage(files, plot=True)
             # is the main function in the trace?
             main_address = 0x5F6E0
             self.assertTrue(main_address in traces[i].trace)
             # has the first input lower coverage than the last?
             self.assertTrue(plots[i][list(plots[i].keys())[0]] < plots[i][
                 list(plots[i].keys())[-1]])
Esempio n. 6
0
 def test_nonexisting_file(self):
     for mode in self.mode_to_binary:
         binary = self.mode_to_binary[mode]
         with quickcov.QuickCov(binary,
                                "--dwarf-check -C -g -f -dwarf -x @@",
                                mode=mode) as q:
             files = get_queue_files(QUEUE_PATH)[:5] + [
                 'this_does_not_exist_145435435'
             ]
             (plot, bitmap, final_coverage) = q.get_coverage(files,
                                                             plot=True)
             self.assertTrue(final_coverage > 1)
             # assert raises error when file does not exist and ignore_missing_files is False
             self.assertRaises(Exception,
                               q.get_coverage,
                               files,
                               plot=True,
                               ignore_missing_files=False)
Esempio n. 7
0
 def test_one_file(self):
     for mode in self.mode_to_binary:
         binary = self.mode_to_binary[mode]
         with quickcov.QuickCov(binary,
                                "--dwarf-check -C -g -f -dwarf -x @@",
                                mode=mode) as q:
             final_coverages = []
             for i in range(NUM_RUNS):
                 # sort files by id to get the creation date
                 timestamps = {}
                 files = get_queue_files(QUEUE_PATH)
                 for x, f in enumerate(sorted(files)):
                     timestamps[f] = x
                 files = [os.path.join(QUEUE_PATH, "id:000000,orig:a.txt")]
                 (plot, bitmap,
                  final_coverage) = q.get_coverage(files,
                                                   plot=True,
                                                   time_dict=timestamps)
                 final_coverages.append(final_coverage)
             for c1 in final_coverages:
                 for c2 in final_coverages:
                     self.assertEqual(c1, c2)
Esempio n. 8
0
 def __init__(self,
              binary,
              input_file=None,
              time_dict=None,
              time_dict_lock=None):
     self.binary = binary
     if binaryToArguments[self.binary] == '':
         self.binary_arguments = ['@@']
     else:
         self.binary_arguments = binaryToArguments[self.binary].split(
             ' ') + ['@@']
     self.fuzzers = []
     if time_dict_lock is None:
         self.time_dict_lock = Lock()
     else:
         self.time_dict_lock = time_dict_lock
     self.input_file = input_file
     self.time_dict = time_dict
     self.start_time = get_unix_timestamp()
     (self.toolset, self.full_binary) = binaryToToolsetAndProject[binary]
     self.q = quickcov.QuickCov(
         os.path.join(QUICKCOV_PATH, self.full_binary),
         self.binary_arguments)
Esempio n. 9
0
 def test_minimum_time(self):
     for mode in self.mode_to_binary:
         binary = self.mode_to_binary[mode]
         with quickcov.QuickCov(binary,
                                "--dwarf-check -C -g -f -dwarf -x @@",
                                mode=mode) as q:
             timestamps = {}
             files = get_queue_files(QUEUE_PATH)
             for x, f in enumerate(sorted(files)):
                 timestamps[f] = x
             files = get_queue_files(QUEUE_PATH)
             # without minimum time
             (plot, bitmap,
              final_coverage) = q.get_coverage(files,
                                               plot=True,
                                               time_dict=timestamps)
             self.assertTrue(min(plot.keys()) == 0)
             # with minimum time
             (plot, bitmap,
              final_coverage) = q.get_coverage(files,
                                               plot=True,
                                               time_dict=timestamps,
                                               minimum_time=2)
             self.assertTrue(min(plot.keys()) == 2)