-
Notifications
You must be signed in to change notification settings - Fork 0
/
afl.go
40 lines (32 loc) · 886 Bytes
/
afl.go
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
33
34
35
36
37
38
39
40
package main
import (
"go/ast"
"path/filepath"
"golang.org/x/exp/slices"
)
func buildAFL(pkgName string, fname string, fuzzFunc *ast.FuncDecl) {
funcName, cleanup := generateLibFuzzer(pkgName, fname, fuzzFunc)
defer cleanup()
args := getBuildArgs(aflFlags, `-func`, funcName, `-o`, getOutputFile(`afl`))
command(`go-afl-build`, args...)
}
func runAFL(args []string) {
if !slices.Contains(args, `-t`) {
panic(`must specify timeout (-t) in run_args`)
}
if !slices.Contains(args, `-o`) {
args = append(args, `-o`, `.`)
}
valid, dir := isValidCorpusDir()
if valid && !slices.Contains(args, dir.Name()) {
args = append(args, `-i`, dir.Name())
} else {
panic(`must specify valid corpus directory`)
}
filePath, err := filepath.Abs(getOutputFile(`afl`))
if err != nil {
panic(err)
}
args = append(args, `--`, filePath)
execute(true, `afl-fuzz`, args...)
}