Exemplo n.º 1
0
    def test_bitwise_hamming_distance(self):
        # set up some temp files
        # set up some temp files
        f1d = open(self.f1, "w")
        f2d = open(self.f2, "w")
        f1d.write("aaaaaaaaa")
        f2d.write("acaacaxac")
        f1d.close()
        f2d.close()

        self.assertEqual(bitwise_hamming_distance(self.f1, self.f2), 6)
        self.assertEqual(bitwise_hamming_distance(self.f1, self.f1), 0)
        self.assertEqual(bitwise_hamming_distance(self.f2, self.f2), 0)
Exemplo n.º 2
0
    def test_bitwise_hamming_distance(self):
        # set up some temp files
        # set up some temp files
        f1d = open(self.f1, 'w')
        f2d = open(self.f2, 'w')
        f1d.write("aaaaaaaaa")
        f2d.write("acaacaxac")
        f1d.close()
        f2d.close()

        self.assertEqual(bitwise_hamming_distance(self.f1, self.f2), 6)
        self.assertEqual(bitwise_hamming_distance(self.f1, self.f1), 0)
        self.assertEqual(bitwise_hamming_distance(self.f2, self.f2), 0)
Exemplo n.º 3
0
    def calculate_hamming_distances(self):
        # If the fuzzed file is a valid zip, then we're fuzzing zip contents,
        # not the container
        self.is_zipfile = check_zip_file(self.fuzzedfile.path)
        try:
            if self.is_zipfile:
                self.hd_bits = hamming.bitwise_zip_hamming_distance(
                    self.seedfile.path, self.fuzzedfile.path)
                self.hd_bytes = hamming.bytewise_zip_hamming_distance(
                    self.seedfile.path, self.fuzzedfile.path)
            else:
                self.hd_bits = hamming.bitwise_hamming_distance(
                    self.seedfile.path, self.fuzzedfile.path)
                self.hd_bytes = hamming.bytewise_hamming_distance(
                    self.seedfile.path, self.fuzzedfile.path)
        except KeyError:
            # one of the files wasn't defined
            logger.warning(
                'Cannot find either sf_path or minimized file to calculate Hamming Distances'
            )
        except AssertionError:
            # Some apps change the size of the file they open.  BFF-1017
            logger.warning(
                'File size changed on disk. Cannot calculate Hamming Distances'
            )
            # We'll use -1 HD as indication of unexpected size change
            self.hd_bits = -1
            self.hd_bytes = -1

        logger.info("crasher=%s bitwise_hd=%d", self.signature, self.hd_bits)
        logger.info("crasher=%s bytewise_hd=%d", self.signature, self.hd_bytes)
    def calculate_hamming_distances(self):
        # If the fuzzed file is a valid zip, then we're fuzzing zip contents,
        # not the container
        self.is_zipfile = check_zip_file(self.fuzzedfile.path)
        try:
            if self.is_zipfile:
                self.hd_bits = hamming.bitwise_zip_hamming_distance(
                    self.seedfile.path, self.fuzzedfile.path)
                self.hd_bytes = hamming.bytewise_zip_hamming_distance(
                    self.seedfile.path, self.fuzzedfile.path)
            else:
                self.hd_bits = hamming.bitwise_hamming_distance(
                    self.seedfile.path, self.fuzzedfile.path)
                self.hd_bytes = hamming.bytewise_hamming_distance(
                    self.seedfile.path, self.fuzzedfile.path)
        except KeyError:
            # one of the files wasn't defined
            logger.warning(
                'Cannot find either sf_path or minimized file to calculate Hamming Distances')
        except AssertionError:
            # Some apps change the size of the file they open.  BFF-1017
            logger.warning(
                'File size changed on disk. Cannot calculate Hamming Distances')
            # We'll use -1 HD as indication of unexpected size change
            self.hd_bits = -1
            self.hd_bytes = -1

        logger.info("crasher=%s bitwise_hd=%d", self.signature, self.hd_bits)
        logger.info("crasher=%s bytewise_hd=%d", self.signature, self.hd_bytes)
Exemplo n.º 5
0
 def calculate_hamming_distances(self):
     try:
         self.hd_bits = hamming.bitwise_hamming_distance(self.seedfile.path, self.fuzzedfile.path)
         self.hd_bytes = hamming.bytewise_hamming_distance(self.seedfile.path, self.fuzzedfile.path)
     except KeyError:
         # one of the files wasn't defined
         logger.warning('Cannot find either sf_path or minimized file to calculate Hamming Distances')
Exemplo n.º 6
0
 def calculate_hamming_distances(self):
     try:
         self.hd_bits = hamming.bitwise_hamming_distance(
             self.seedfile.path, self.fuzzedfile.path)
         self.hd_bytes = hamming.bytewise_hamming_distance(
             self.seedfile.path, self.fuzzedfile.path)
     except KeyError:
         # one of the files wasn't defined
         logger.warning(
             'Cannot find either sf_path or minimized file to calculate Hamming Distances'
         )