diff options
| author | Veronica Radu <veronicaradu@google.com> | 2019-08-12 17:41:25 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2019-09-03 16:30:45 +0200 |
| commit | dbd627eb61743340cb565ce41308beb4383a77be (patch) | |
| tree | 065a277c6b4dd3bd2798b5cba36fe744c8027b42 /tools/syz-mutate | |
| parent | 8d48456885907439825fa265e0c375da5fdf1ecd (diff) | |
prog: add implementation for resource centric
Diffstat (limited to 'tools/syz-mutate')
| -rw-r--r-- | tools/syz-mutate/mutate.go | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/tools/syz-mutate/mutate.go b/tools/syz-mutate/mutate.go index b0361a20b..56aab8ee1 100644 --- a/tools/syz-mutate/mutate.go +++ b/tools/syz-mutate/mutate.go @@ -14,6 +14,7 @@ import ( "strings" "time" + "github.com/google/syzkaller/pkg/db" "github.com/google/syzkaller/pkg/mgrconfig" "github.com/google/syzkaller/prog" _ "github.com/google/syzkaller/sys" @@ -25,6 +26,7 @@ var ( flagSeed = flag.Int("seed", -1, "prng seed") flagLen = flag.Int("len", 30, "number of calls in programs") flagEnable = flag.String("enable", "", "comma-separated list of enabled syscalls") + flagCorpus = flag.String("corpus", "", "name of the corpus file") ) func main() { @@ -56,8 +58,12 @@ func main() { if *flagSeed != -1 { seed = int64(*flagSeed) } + var corpus []*prog.Prog + if *flagCorpus != "" { + corpus = readCorpus(*flagCorpus, target) + } rs := rand.NewSource(seed) - prios := target.CalculatePriorities(nil) + prios := target.CalculatePriorities(corpus) ct := target.BuildChoiceTable(prios, syscalls) var p *prog.Prog if flag.NArg() == 0 { @@ -73,7 +79,24 @@ func main() { fmt.Fprintf(os.Stderr, "failed to deserialize the program: %v\n", err) os.Exit(1) } - p.Mutate(rs, *flagLen, ct, nil) + p.Mutate(rs, *flagLen, ct, corpus) } fmt.Printf("%s\n", p.Serialize()) } + +func readCorpus(filename string, target *prog.Target) (corpus []*prog.Prog) { + dbObj, err := db.Open(filename) + if err != nil { + fmt.Fprintf(os.Stderr, "failed to open the corpus file: %v\n", err) + os.Exit(1) + } + for _, v := range dbObj.Records { + p, err := target.Deserialize(v.Val, prog.NonStrict) + if err != nil { + fmt.Fprintf(os.Stderr, "failed to deserialize the program: %v\n", err) + os.Exit(1) + } + corpus = append(corpus, p) + } + return corpus +} |
