aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2015-12-28 12:49:19 +0100
committerDmitry Vyukov <dvyukov@google.com>2015-12-28 12:49:19 +0100
commit9f9ae3fcc3efc74cbcb805b44575b5c140fa97ee (patch)
tree983f66d1097c67a4785ca4a45e34f669c94e327b
parent7aee64145fe814abd8008cae3dbc24dcfc6b4e8b (diff)
tools/syz-upgrade: helper tool for corpus format upgrades
-rw-r--r--Makefile5
-rw-r--r--tools/syz-upgrade/upgrade.go59
2 files changed, 63 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index f602f8537..e0c17d33d 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@
all: manager fuzzer executor
-all-tools: execprog mutate prog2c stress repro
+all-tools: execprog mutate prog2c stress repro upgrade
manager:
go build -o ./bin/syz-manager github.com/google/syzkaller/syz-manager
@@ -31,6 +31,9 @@ prog2c:
stress:
go build -o ./bin/syz-stress github.com/google/syzkaller/tools/syz-stress
+upgrade:
+ go build -o ./bin/syz-upgrade github.com/google/syzkaller/tools/syz-upgrade
+
generate:
go run sysgen/*.go -linux=$(LINUX) sys/sys.txt
diff --git a/tools/syz-upgrade/upgrade.go b/tools/syz-upgrade/upgrade.go
new file mode 100644
index 000000000..ea2b3b6df
--- /dev/null
+++ b/tools/syz-upgrade/upgrade.go
@@ -0,0 +1,59 @@
+// 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.
+
+// upgrade upgrades corpus from an old format to a new format.
+// Upgrade is not fully automatic. You need to update prog.Serialize.
+// Run the tool. Then update prog.Deserialize. And run the tool again that
+// the corpus is not changed this time.
+package main
+
+import (
+ "bytes"
+ "crypto/sha1"
+ "encoding/hex"
+ "fmt"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+
+ "github.com/google/syzkaller/prog"
+)
+
+func main() {
+ if len(os.Args) != 2 {
+ fatalf("usage: syz-upgrage corpus_dir")
+ }
+ files, err := ioutil.ReadDir(os.Args[1])
+ if err != nil {
+ fatalf("failed to read corpus dir: %v", err)
+ }
+ for _, f := range files {
+ fname := filepath.Join(os.Args[1], f.Name())
+ data, err := ioutil.ReadFile(fname)
+ if err != nil {
+ fatalf("failed to read program: %v", err)
+ }
+ p, err := prog.Deserialize(data)
+ if err != nil {
+ fatalf("failed to deserialize program: %v", err)
+ }
+ data1 := p.Serialize()
+ if bytes.Equal(data, data1) {
+ continue
+ }
+ fmt.Printf("upgrading:\n%s\nto:\n%s\n\n", data, data1)
+ hash := sha1.Sum(data1)
+ fname1 := filepath.Join(os.Args[1], hex.EncodeToString(hash[:]))
+ if err := ioutil.WriteFile(fname1, data1, 0640); err != nil {
+ fatalf("failed to write program: %v", err)
+ }
+ if err := os.Remove(fname); err != nil {
+ fatalf("failed to remove program: %v", err)
+ }
+ }
+}
+
+func fatalf(msg string, args ...interface{}) {
+ fmt.Fprintf(os.Stderr, msg+"\n", args...)
+ os.Exit(1)
+}