syzkaller/tools/syz-prog2c/prog2c.go

44 lines
1021 B
Go
Raw Normal View History

2015-10-12 08:16:57 +00:00
// 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.
package main
import (
"flag"
2015-10-12 08:16:57 +00:00
"fmt"
"io/ioutil"
"os"
"github.com/google/syzkaller/csource"
2015-10-12 08:16:57 +00:00
"github.com/google/syzkaller/prog"
)
var (
flagThreaded = flag.Bool("threaded", false, "create threaded program")
flagCollide = flag.Bool("collide", false, "create collide program")
)
2015-10-12 08:16:57 +00:00
func main() {
flag.Parse()
if len(flag.Args()) != 1 {
fmt.Fprintf(os.Stderr, "usage: prog2c [-threaded [-collide]] prog_file\n")
2015-10-12 08:16:57 +00:00
os.Exit(1)
}
data, err := ioutil.ReadFile(flag.Args()[0])
2015-10-12 08:16:57 +00:00
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)
}
opts := csource.Options{
Threaded: *flagThreaded,
Collide: *flagCollide,
}
src := csource.Write(p, opts)
2015-10-12 08:16:57 +00:00
os.Stdout.Write(src)
}