def test_dependencies(self): s_initialize("DEP TEST 1") s_group("group", default_value=b"0", values=[b"1", b"2"]) if s_block_start("ONE", dep="group", dep_values=[b"1"]): s_static("ONE") s_block_end() if s_block_start("TWO", dep="group", dep_values=[b"2"]): s_static("TWO") s_group("group2", default_value=b"0", values=[b"1", b"2"]) s_block_end() mutations = list(blocks.CURRENT.get_mutations()) rendered = blocks.CURRENT.render() assert b"ONE" not in rendered assert b"TWO" not in rendered rendered = blocks.CURRENT.render( MutationContext(mutations=mutations[0])) assert b"ONE" in rendered assert b"TWO" not in rendered rendered = blocks.CURRENT.render( MutationContext(mutations=mutations[1])) assert b"ONE" not in rendered assert b"TWO" in rendered assert len(mutations) == 4
def scenario_output_as(context, mutation, result): if result.startswith("0x"): result = result[2:] result = bytes(bytearray.fromhex(result)) mutation = int(mutation) assert context.req.render( MutationContext(mutation=context.mutations[mutation])) == result
def test_repeaters(self): s_initialize("REP TEST 1") if s_block_start("BLOCK"): s_delim(">", name="delim", fuzzable=False) s_string("pedram", name="string", fuzzable=False) s_byte(0xDE, name="byte", fuzzable=False) s_word(0xDEAD, name="word", fuzzable=False) s_dword(0xDEADBEEF, name="dword", fuzzable=False) s_qword(0xDEADBEEFDEADBEEF, name="qword", fuzzable=False) s_random(b"0", 5, 10, 100, name="random", fuzzable=False) s_block_end() s_repeat("BLOCK", min_reps=5, max_reps=15, step=5) data = blocks.CURRENT.render() length = len(data) self.assertEqual(23, length) expected_lengths = [length + length * 5, length + length * 10, length + length * 15] for mutation, expected_length in zip(blocks.CURRENT.get_mutations(), expected_lengths): data = blocks.CURRENT.render(MutationContext(mutation=mutation)) self.assertEqual(expected_length, len(data))
def scenario_can_render_all_mutations(context): for mutation in context.mutations: context.req.render(MutationContext(mutations=mutation))
def scenario_can_render_all_mutations(context): mutations = list(context.req.get_mutations()) for mutation in mutations: context.req.render(MutationContext(mutations=mutation))