-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
main.go
54 lines (50 loc) · 1.07 KB
/
main.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"github.com/AdamKorcz/go-118-fuzz-build/coverage"
)
// reads all corpus files in a directory and converts
// them from libFuzzer format to native Go format.
func main() {
if len(os.Args) != 3 {
fmt.Println(os.Args)
log.Fatalf("need exactly two argument")
}
FUZZERNAME := os.Args[1]
CORPUS_PATH := os.Args[2]
filepath.Walk(CORPUS_PATH, func(path string, info os.FileInfo, err error) error {
if err != nil {
return nil
}
if !info.Mode().IsRegular() {
return nil
}
libFuzzerSeed, err := os.ReadFile(path)
if err != nil {
panic(err)
}
out := os.Getenv("OUT")
fuzzerContents, err := os.ReadFile(filepath.Join(out, "rawfuzzers", FUZZERNAME))
if err != nil {
panic(err)
}
goSeed := coverage.ConvertLibfuzzerSeedToGoSeed(fuzzerContents, libFuzzerSeed, FUZZERNAME)
err = os.Remove(path)
if err != nil {
panic(err)
}
f, err := os.Create(path)
if err != nil {
panic(err)
}
defer f.Close()
_, err = f.Write([]byte(goSeed))
if err != nil {
panic(err)
}
return nil
})
}