github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/tools/syz-expand/expand.go (about)

     1  // Copyright 2019 syzkaller project authors. All rights reserved.
     2  // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
     3  
     4  // Parses a program and prints it including all default values.
     5  
     6  package main
     7  
     8  import (
     9  	"flag"
    10  	"fmt"
    11  	"os"
    12  	"runtime"
    13  
    14  	"github.com/google/syzkaller/prog"
    15  	_ "github.com/google/syzkaller/sys"
    16  )
    17  
    18  var (
    19  	flagOS     = flag.String("os", runtime.GOOS, "target os")
    20  	flagArch   = flag.String("arch", runtime.GOARCH, "target arch")
    21  	flagProg   = flag.String("prog", "", "file with program to expand")
    22  	flagStrict = flag.Bool("strict", false, "parse input program in strict mode")
    23  )
    24  
    25  func main() {
    26  	flag.Parse()
    27  	if *flagProg == "" {
    28  		flag.Usage()
    29  		os.Exit(1)
    30  	}
    31  	target, err := prog.GetTarget(*flagOS, *flagArch)
    32  	if err != nil {
    33  		fmt.Fprintf(os.Stderr, "%v\n", err)
    34  		os.Exit(1)
    35  	}
    36  	data, err := os.ReadFile(*flagProg)
    37  	if err != nil {
    38  		fmt.Fprintf(os.Stderr, "failed to read prog file: %v\n", err)
    39  		os.Exit(1)
    40  	}
    41  	mode := prog.NonStrict
    42  	if *flagStrict {
    43  		mode = prog.Strict
    44  	}
    45  	p, err := target.Deserialize(data, mode)
    46  	if err != nil {
    47  		fmt.Fprintf(os.Stderr, "failed to deserialize the program: %v\n", err)
    48  		os.Exit(1)
    49  	}
    50  	fmt.Printf("%s", p.SerializeVerbose())
    51  }