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 (
|
2015-12-23 12:38:31 +00:00
|
|
|
"flag"
|
2015-10-12 08:16:57 +00:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
|
2015-12-23 12:38:31 +00:00
|
|
|
"github.com/google/syzkaller/csource"
|
2015-10-12 08:16:57 +00:00
|
|
|
"github.com/google/syzkaller/prog"
|
|
|
|
)
|
|
|
|
|
2015-12-23 12:38:31 +00:00
|
|
|
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() {
|
2015-12-23 12:38:31 +00:00
|
|
|
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)
|
|
|
|
}
|
2015-12-23 12:38:31 +00:00
|
|
|
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)
|
|
|
|
}
|
2015-12-23 12:38:31 +00:00
|
|
|
opts := csource.Options{
|
|
|
|
Threaded: *flagThreaded,
|
|
|
|
Collide: *flagCollide,
|
|
|
|
}
|
|
|
|
src := csource.Write(p, opts)
|
2015-10-12 08:16:57 +00:00
|
|
|
os.Stdout.Write(src)
|
|
|
|
}
|