<commit_before>// 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"
	"fmt"
	"io/ioutil"
	"os"
	"runtime"

	"github.com/google/syzkaller/pkg/csource"
	"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")
	flagThreaded   = flag.Bool("threaded", false, "create threaded program")
	flagCollide    = flag.Bool("collide", false, "create collide program")
	flagRepeat     = flag.Bool("repeat", false, "repeat program infinitely or not")
	flagProcs      = flag.Int("procs", 1, "number of parallel processes")
	flagSandbox    = flag.String("sandbox", "", "sandbox to use (none, setuid, namespace)")
	flagProg       = flag.String("prog", "", "file with program to convert (required)")
	flagFaultCall  = flag.Int("fault_call", -1, "inject fault into this call (0-based)")
	flagFaultNth   = flag.Int("fault_nth", 0, "inject fault on n-th operation (0-based)")
	flagEnableTun  = flag.Bool("tun", false, "set up TUN/TAP interface")
	flagUseTmpDir  = flag.Bool("tmpdir", false, "create a temporary dir and execute inside it")
	flagHandleSegv = flag.Bool("segv", false, "catch and ignore SIGSEGV")
	flagWaitRepeat = flag.Bool("waitrepeat", false, "wait for each repeat attempt")
	flagDebug      = flag.Bool("debug", false, "generate debug printfs")
)

func main() {
	flag.Parse()
	if *flagProg == "" {
		flag.PrintDefaults()
		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)
	}
	p, err := target.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,
		Repeat:     *flagRepeat,
		Procs:      *flagProcs,
		Sandbox:    *flagSandbox,
		Fault:      *flagFaultCall >= 0,
		FaultCall:  *flagFaultCall,
		FaultNth:   *flagFaultNth,
		EnableTun:  *flagEnableTun,
		UseTmpDir:  *flagUseTmpDir,
		HandleSegv: *flagHandleSegv,
		WaitRepeat: *flagWaitRepeat,
		Debug:      *flagDebug,
		Repro:      false,
	}
	src, err := csource.Write(p, opts)
	if err != nil {<commit_msg>tools/syz-prog2c: add missing csource option<commit_after>// 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"
	"fmt"
	"io/ioutil"
	"os"
	"runtime"

	"github.com/google/syzkaller/pkg/csource"
	"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")
	flagThreaded   = flag.Bool("threaded", false, "create threaded program")
	flagCollide    = flag.Bool("collide", false, "create collide program")
	flagRepeat     = flag.Bool("repeat", false, "repeat program infinitely or not")
	flagProcs      = flag.Int("procs", 1, "number of parallel processes")
	flagSandbox    = flag.String("sandbox", "", "sandbox to use (none, setuid, namespace)")
	flagProg       = flag.String("prog", "", "file with program to convert (required)")
	flagFaultCall  = flag.Int("fault_call", -1, "inject fault into this call (0-based)")
	flagFaultNth   = flag.Int("fault_nth", 0, "inject fault on n-th operation (0-based)")
	flagEnableTun  = flag.Bool("tun", false, "set up TUN/TAP interface")
	flagUseTmpDir  = flag.Bool("tmpdir", false, "create a temporary dir and execute inside it")
	flagHandleSegv = flag.Bool("segv", false, "catch and ignore SIGSEGV")
	flagWaitRepeat = flag.Bool("waitrepeat", false, "wait for each repeat attempt")
	flagCgroups = flag.Bool("cgroups", false, "enable cgroups support")
	flagDebug      = flag.Bool("debug", false, "generate debug printfs")
)

func main() {
	flag.Parse()
	if *flagProg == "" {
		flag.PrintDefaults()
		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)
	}
	p, err := target.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,
		Repeat:     *flagRepeat,
		Procs:      *flagProcs,
		Sandbox:    *flagSandbox,
		Fault:      *flagFaultCall >= 0,
		FaultCall:  *flagFaultCall,
		FaultNth:   *flagFaultNth,
		EnableTun:  *flagEnableTun,
		UseTmpDir:  *flagUseTmpDir,
		EnableCgroups: *flagCgroups,
		HandleSegv: *flagHandleSegv,
		WaitRepeat: *flagWaitRepeat,
		Debug:      *flagDebug,
		Repro:      false,
	}
	src, err := csource.Write(p, opts)
	if err != nil {
{'fraction_non_alphanumeric': 0.14454106280193238, 'fraction_numerical': 0.005990338164251208, 'mean_word_length': 3.9295238095238094, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1331280', 'n_tokens_mistral': 1976, 'n_tokens_neox': 1889, 'n_words': 484}