aboutsummaryrefslogtreecommitdiffstats
path: root/tools/syz-trace2syz/proggen/fuzz.go
blob: 6dd902b41c1b94ad6e0d86a6dce404ab191a4967 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright 2018 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.

//go:build !codeanalysis

package proggen

import (
	"github.com/google/syzkaller/prog"
	_ "github.com/google/syzkaller/sys"
	"github.com/google/syzkaller/sys/targets"
)

var linuxTarget = func() *prog.Target {
	target, err := prog.GetTarget(targets.Linux, targets.AMD64)
	if err != nil {
		panic(err)
	}
	target.ConstMap = make(map[string]uint64)
	for _, c := range target.Consts {
		target.ConstMap[c.Name] = c.Value
	}
	return target
}()

func Fuzz(data []byte) int {
	progs, err := ParseData(data, linuxTarget)
	if err != nil {
		return 0
	}
	return len(progs)
}