Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple changes; python 2 support, dictionary, mutator refactor #26

Merged
merged 15 commits into from Jan 19, 2020
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Add the operation type to the mutator types; add a dictionary append.

Knowing which type of mutators are in use helps to favour certain
kinds of operations. In particular, if you start with a small dictionary
of words and wish to generate longer strings, using just an option
that appends to the dictionary is useful.

The dictionary append operation has been added which allows the
values from the dictionary to be strung together in increasingly
longer sequences. It doesn't offer the option of appending multiple
values from the dictionary so the operation my end up in a local
minima, but such mutators could be added in the future.
  • Loading branch information
gerph committed Jan 7, 2020
commit beb0ce3b78032c838f884a304c4e2b6df5497b4b
@@ -78,7 +78,7 @@ def mutate(self, res):
@register_mutator
class MutatorRemoveRange(Mutator):
name = 'Remove a range of bytes'
types = set(['byte'])
types = set(['byte', 'remove'])

def mutate(self, res):
if len(res) < 2:
@@ -95,7 +95,7 @@ def mutate(self, res):
@register_mutator
class MutatorInsertBytes(Mutator):
name = 'Insert a range of random bytes'
types = set(['byte'])
types = set(['byte', 'insert'])

def mutate(self, res):
pos = self._rand(len(res) + 1)
@@ -111,7 +111,7 @@ def mutate(self, res):
@register_mutator
class MutatorDuplicateBytes(Mutator):
name = 'Duplicate a range of bytes'
types = set(['byte'])
types = set(['byte', 'duplicate'])

def mutate(self, res):
if len(res) <= 1:
@@ -134,7 +134,7 @@ def mutate(self, res):
@register_mutator
class MutatorCopyBytes(Mutator):
name = 'Copy a range of bytes'
types = set(['byte'])
types = set(['byte', 'copy'])

def mutate(self, res):
if len(res) <= 1:
@@ -151,7 +151,7 @@ def mutate(self, res):
@register_mutator
class MutatorBitFlip(Mutator):
name = 'Bit flip'
types = set(['bit'])
types = set(['bit', 'replace'])

def mutate(self, res):
if len(res) == 0:
@@ -164,7 +164,7 @@ def mutate(self, res):
@register_mutator
class MutatorRandomiseByte(Mutator):
name = 'Set a byte to a random value.'
types = set(['byte'])
types = set(['byte', 'replace'])

def mutate(self, res):
if len(res) == 0:
@@ -177,7 +177,7 @@ def mutate(self, res):
@register_mutator
class MutatorSwapBytes(Mutator):
name = 'Swap 2 bytes'
types = set(['byte'])
types = set(['byte', 'swap'])

def mutate(self, res):
if len(res) <= 1:
@@ -193,7 +193,7 @@ def mutate(self, res):
@register_mutator
class MutatorAddSubByte(Mutator):
name = 'Add/subtract from a byte'
types = set(['byte'])
types = set(['byte', 'addsub'])

def mutate(self, res):
if len(res) == 0:
@@ -210,7 +210,7 @@ def mutate(self, res):
@register_mutator
class MutatorAddSubShort(Mutator):
name = 'Add/subtract from a uint16'
types = set(['short'])
types = set(['short', 'addsub'])

def mutate(self, res):
if len(res) < 2:
@@ -232,7 +232,7 @@ def mutate(self, res):
@register_mutator
class MutatorAddSubLong(Mutator):
name = 'Add/subtract from a uint32'
types = set(['long'])
types = set(['long', 'addsub'])

def mutate(self, res):
if len(res) < 4:
@@ -254,7 +254,7 @@ def mutate(self, res):
@register_mutator
class MutatorAddSubLongLong(Mutator):
name = 'Add/subtract from a uint64'
types = set(['longlong'])
types = set(['longlong', 'addsub'])

def mutate(self, res):
if len(res) < 8:
@@ -276,7 +276,7 @@ def mutate(self, res):
@register_mutator
class MutatorReplaceByte(Mutator):
name = 'Replace a byte with an interesting value'
types = set(['byte'])
types = set(['byte', 'replace'])

def mutate(self, res):
if len(res) == 0:
@@ -289,7 +289,7 @@ def mutate(self, res):
@register_mutator
class MutatorReplaceShort(Mutator):
name = 'Replace an uint16 with an interesting value'
types = set(['short'])
types = set(['short', 'replace'])

def mutate(self, res):
if len(res) < 2:
@@ -309,7 +309,7 @@ def mutate(self, res):
@register_mutator
class MutatorReplaceLong(Mutator):
name = 'Replace an uint32 with an interesting value'
types = set(['long'])
types = set(['long', 'replace'])

def mutate(self, res):
if len(res) < 4:
@@ -329,7 +329,7 @@ def mutate(self, res):
@register_mutator
class MutatorReplaceDigit(Mutator):
name = 'Replace an ascii digit with another digit'
types = set(['byte', 'ascii'])
types = set(['byte', 'ascii', 'replace'])

def mutate(self, res):
digits = []
@@ -365,6 +365,19 @@ def mutate(self, res):
return res


@register_mutator
class MutatorDictionaryWordAppend(Mutator):
name = 'Append a word'
types = set(['dictionary', 'append'])

def mutate(self, res):
word = self.corpus._dict.get_word()
if not word:
return None
res.extend(word)
return res


class CorpusError(Exception):
pass

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.