Пример #1
0

if __package__ is None or __package__ == "":
    from GrammarCoverageFuzzer import GrammarCoverageFuzzer
else:
    from .GrammarCoverageFuzzer import GrammarCoverageFuzzer


if __package__ is None or __package__ == "":
    from fuzzingbook_utils import inheritance_conflicts
else:
    from .fuzzingbook_utils import inheritance_conflicts


if __name__ == "__main__":
    inheritance_conflicts(GUIFuzzer, GrammarCoverageFuzzer)


class GUICoverageFuzzer(GUIFuzzer, GrammarCoverageFuzzer):
    def __init__(self, *args, **kwargs):
        GUIFuzzer.__init__(self, *args, **kwargs)
        self.reset_coverage()

class GUICoverageFuzzer(GUICoverageFuzzer):            
    def explore_all(self, runner, max_actions=100):
        actions = 0
        while GUIGrammarMiner.UNEXPLORED_STATE in self.grammar and actions < max_actions:
            actions += 1
            if self.log_gui_exploration:
                print("Run #" + repr(actions))
            try:
if __name__ == "__main__":
    print('\n## Exercises')

# ### Exercise 1: Probabilistic Fuzzing with Coverage

if __name__ == "__main__":
    print('\n### Exercise 1: Probabilistic Fuzzing with Coverage')

if __package__ is None or __package__ == "":
    from fuzzingbook_utils import inheritance_conflicts
else:
    from .fuzzingbook_utils import inheritance_conflicts

if __name__ == "__main__":
    inheritance_conflicts(GrammarCoverageFuzzer, ProbabilisticGrammarFuzzer)


class ProbabilisticGrammarCoverageFuzzer(GrammarCoverageFuzzer,
                                         ProbabilisticGrammarFuzzer):
    # Choose uncovered expansions first
    def choose_node_expansion(self, node, possible_children):
        return GrammarCoverageFuzzer.choose_node_expansion(
            self, node, possible_children)

    # Among uncovered expansions, pick by (relative) probability
    def choose_uncovered_node_expansion(self, node, possible_children):
        return ProbabilisticGrammarFuzzer.choose_node_expansion(
            self, node, possible_children)

    # For covered nodes, pick by probability, too
if __name__ == "__main__":
    print('\n### Generators and Probabilistic Fuzzing')

if __package__ is None or __package__ == "":
    from ProbabilisticGrammarFuzzer import ProbabilisticGrammarFuzzer  # minor dependency
else:
    from .ProbabilisticGrammarFuzzer import ProbabilisticGrammarFuzzer  # minor dependency

if __package__ is None or __package__ == "":
    from fuzzingbook_utils import inheritance_conflicts
else:
    from .fuzzingbook_utils import inheritance_conflicts

if __name__ == "__main__":
    inheritance_conflicts(ProbabilisticGrammarFuzzer, GeneratorGrammarFuzzer)


class ProbabilisticGeneratorGrammarFuzzer(GeneratorGrammarFuzzer,
                                          ProbabilisticGrammarFuzzer):
    def supported_opts(self):
        return (super(GeneratorGrammarFuzzer, self).supported_opts()
                | super(ProbabilisticGrammarFuzzer, self).supported_opts())

    def __init__(self, grammar, replacement_attempts=10, **kwargs):
        super(GeneratorGrammarFuzzer, self).__init__(grammar,
                                                     replacement_attempts)
        super(ProbabilisticGrammarFuzzer, self).__init__(grammar, **kwargs)


if __name__ == "__main__":