aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2015-10-16 22:00:16 +0200
committerDmitry Vyukov <dvyukov@google.com>2015-10-16 22:00:16 +0200
commit6d84c5d2d78c750299099fdfb22f694e2e1b89a6 (patch)
treebc448e4fd1b2a369f7b05d912e0cc1f8b1e7cc6e /tools
parentf8f416fb8f2ce79d0cbf980ee53ddb68fac850ca (diff)
add mutate tool that allows to manually investigate mutator behavior
Diffstat (limited to 'tools')
-rw-r--r--tools/mutate/mutate.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/tools/mutate/mutate.go b/tools/mutate/mutate.go
new file mode 100644
index 000000000..353d60390
--- /dev/null
+++ b/tools/mutate/mutate.go
@@ -0,0 +1,49 @@
+// Copyright 2015 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+// mutates mutates a given program and prints result.
+package main
+
+import (
+ "flag"
+ "fmt"
+ "io/ioutil"
+ "math/rand"
+ "os"
+ "time"
+
+ "github.com/google/syzkaller/prog"
+)
+
+var (
+ flagSeed = flag.Int("seed", -1, "prng seed")
+)
+
+func main() {
+ flag.Parse()
+ if flag.NArg() != 1 {
+ fmt.Fprintf(os.Stderr, "usage: mutate program\n")
+ os.Exit(1)
+ }
+ data, err := ioutil.ReadFile(flag.Arg(0))
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "failed to read prog file: %v\n", err)
+ os.Exit(1)
+ }
+ p, err := prog.Deserialize(data)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "failed to deserialize the program: %v\n", err)
+ os.Exit(1)
+ }
+
+ prios := prog.CalculatePriorities(nil)
+ ct := prog.BuildChoiceTable(prios, nil)
+
+ seed := time.Now().UnixNano()
+ if *flagSeed != -1 {
+ seed = int64(*flagSeed)
+ }
+ rs := rand.NewSource(seed)
+ p.Mutate(rs, len(p.Calls)+10, ct)
+ fmt.Printf("%s\n", p.Serialize())
+}