def testNumMutations(self): field = String(name='padded', value='abc') uut = Pad(self.pad_length, fields=field, name='uut') field_num_mutations = field.num_mutations() uut_num_mutations = uut.num_mutations() self.assertEqual(uut_num_mutations, field_num_mutations) self.assertGreater(uut_num_mutations, 0) actual_num_mutations = 0 while uut.mutate(): actual_num_mutations += 1 self.assertEqual(actual_num_mutations, uut_num_mutations)
def testFixedWithoutPad(self): data = 'abcdefghijklmnop' expected = Bits(bytes=data) uut = Pad(pad_length=10 * 8, fields=Static(data), pad_data='\xff') uut_num_mutations = uut.num_mutations() self.assertEqual(uut_num_mutations, 0) actual_num_mutations = 0 while uut.mutate(): actual_num_mutations += 1 self.assertEqual(actual_num_mutations, uut_num_mutations) self.assertEqual(uut.render(), expected)
def testNumMutations(self): field = String(name='padded', value='abc') uut = Pad(self.pad_length, fields=field, name=self.uut_name) field_num_mutations = field.num_mutations() uut_num_mutations = uut.num_mutations() self.assertEqual(uut_num_mutations, field_num_mutations) self.assertGreater(uut_num_mutations, 0) actual_num_mutations = 0 while uut.mutate(): actual_num_mutations += 1 self.assertEqual(actual_num_mutations, uut_num_mutations)
def testPadWhenNotFuzzable(self): field = String(name='padded', value='abc') uut = Pad(self.pad_length, fields=field, name=self.uut_name, fuzzable=False) self._testValuePadded(field, uut, self.pad_length, '\x00')
def testMultipleDependenciesDefaultValue(self): expected_data = ( '\x00\x00\x00\x74' + 'HAMBURGER' + '\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa' + '\xf3\xfe\xa2g8\xd6\xc1\xc2K\xef\x89\xe3\xd7\xcfh\xbaH\xf8\x83\x08JS\x82\xa5\x86f\x82\x9b\x18\xc5r\xa9' ) uut = Template(name='uut', fields=[ SizeInBytes(sized_field='uut', length=32, name='size'), Pad(name='content', fields=[ String(value='HAMBURGER'), ], pad_length=640, pad_data='\xaa'), Sha256(depends_on='content', name='hash'), ]) self.assertEqual(uut.render().tobytes(), expected_data) uut.mutate() uut.reset() self.assertEqual(uut.render().tobytes(), expected_data)
def testDifferentHashIfPadDataIsDifferend(self): pad1 = Pad(pad_length=10 * 8, fields=String('abc'), pad_data='\x00') pad2 = Pad(pad_length=10 * 8, fields=String('abc'), pad_data='\xff') self.assertNotEqual(pad1.hash(), pad2.hash())
def testHashTheSameAfterReset(self): container = Pad(pad_length=10 * 8, fields=String('abc'), pad_data='\xff') hash_after_creation = container.hash() container.mutate() hash_after_mutate = container.hash() self.assertEqual(hash_after_creation, hash_after_mutate) container.reset() hash_after_reset = container.hash() self.assertEqual(hash_after_creation, hash_after_reset) while container.mutate(): hash_after_mutate_all = container.hash() self.assertEqual(hash_after_creation, hash_after_mutate_all) container.render() hash_after_render_all = container.hash() self.assertEqual(hash_after_creation, hash_after_render_all)
def testHashTheSameForTwoSimilarObjects(self): pad1 = Pad(pad_length=10 * 8, fields=String('abc'), pad_data='\xff') pad2 = Pad(pad_length=10 * 8, fields=String('abc'), pad_data='\xff') self.assertEqual(pad1.hash(), pad2.hash())
def testPadWhenFuzzable(self): field = String(name='padded', value='abc') uut = Pad(self.pad_length, fields=field, name='uut') self._testValuePadded(field, uut, self.pad_length, '\x00') while uut.mutate(): self._testValuePadded(field, uut, self.pad_length, '\x00')
def testPadWhenFuzzable(self): field = String(name='padded', value='abc') uut = Pad(self.pad_length, fields=field, name=self.uut_name) self._testValuePadded(field, uut, self.pad_length, '\x00') while uut.mutate(): self._testValuePadded(field, uut, self.pad_length, '\x00')