aboutsummaryrefslogtreecommitdiffstats
path: root/tools/syz-mutate
diff options
context:
space:
mode:
Diffstat (limited to 'tools/syz-mutate')
-rw-r--r--tools/syz-mutate/mutate.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/tools/syz-mutate/mutate.go b/tools/syz-mutate/mutate.go
new file mode 100644
index 000000000..353d60390
--- /dev/null
+++ b/tools/syz-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())
+}