diff options
| author | Andrey Konovalov <andreyknvl@google.com> | 2019-09-23 15:34:59 +0200 |
|---|---|---|
| committer | Andrey Konovalov <andreyknvl@gmail.com> | 2019-09-23 17:13:23 +0200 |
| commit | 2b854f96b1a7be5c5c563fe798aaa2f6835ad2c6 (patch) | |
| tree | 8fe736742849104c860be93b989f4b7cddc28bc2 /tools/syz-expand | |
| parent | 1e9788a0d9bd8fca36978810fd3fc50b6c4f060b (diff) | |
tools: add syz-expand
The syz-expand tools allows to parse a program and print it including all
the default values. This is mainly useful for debugging, like doing manual
program modifications while trying to come up with a reproducer for some
particular kernel behavior.
Diffstat (limited to 'tools/syz-expand')
| -rw-r--r-- | tools/syz-expand/expand.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tools/syz-expand/expand.go b/tools/syz-expand/expand.go new file mode 100644 index 000000000..d90053d9d --- /dev/null +++ b/tools/syz-expand/expand.go @@ -0,0 +1,52 @@ +// Copyright 2019 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. + +// Parses a program and prints it including all default values. + +package main + +import ( + "flag" + "fmt" + "io/ioutil" + "os" + "runtime" + + "github.com/google/syzkaller/prog" + _ "github.com/google/syzkaller/sys" +) + +var ( + flagOS = flag.String("os", runtime.GOOS, "target os") + flagArch = flag.String("arch", runtime.GOARCH, "target arch") + flagProg = flag.String("prog", "", "file with program to expand") + flagStrict = flag.Bool("strict", false, "parse input program in strict mode") +) + +func main() { + flag.Parse() + if *flagProg == "" { + flag.Usage() + os.Exit(1) + } + target, err := prog.GetTarget(*flagOS, *flagArch) + if err != nil { + fmt.Fprintf(os.Stderr, "%v", err) + os.Exit(1) + } + data, err := ioutil.ReadFile(*flagProg) + if err != nil { + fmt.Fprintf(os.Stderr, "failed to read prog file: %v\n", err) + os.Exit(1) + } + mode := prog.NonStrict + if *flagStrict { + mode = prog.Strict + } + p, err := target.Deserialize(data, mode) + if err != nil { + fmt.Fprintf(os.Stderr, "failed to deserialize the program: %v\n", err) + os.Exit(1) + } + fmt.Printf("%s", p.SerializeVerbose()) +} |
