-
Notifications
You must be signed in to change notification settings - Fork 12
/
mutate_dict.go
63 lines (52 loc) · 1.24 KB
/
mutate_dict.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
55
56
57
58
59
60
61
62
63
package main
import (
"log"
"io/ioutil"
"os"
"path/filepath"
)
// ***** local chosers *****
type localMeta struct {
// Ressource management
killerChan chan func()
freeer func()
}
func (locC *localMeta) free() {
if locC.freeer != nil {
locC.freeer()
}
}
func makeDictWords(dictPath string) (words [][]byte) {
if len(dictPath) == 0 { // No dictionnary given by user.
return
}
stat, err := os.Stat(dictPath)
if err != nil {
log.Printf("Problem while reading dictionary path: %v.\n", err)
return words
}
if !stat.IsDir() {
log.Print("Sorry, dictionary file format not implemented yet")
return words
}
fileInfos, err := ioutil.ReadDir(dictPath)
if err != nil {
log.Printf("Problem reading dictionary directory: %v.\n", err)
return words
}
knownWords := make(map[string]struct{})
for _, info := range fileInfos {
path := filepath.Join(dictPath, info.Name())
fileContent, err := ioutil.ReadFile(path)
if err != nil {
log.Printf("Problem reading a file for dict: %v.\n", err)
continue
}
if _, ok := knownWords[string(fileContent)]; !ok {
knownWords[string(fileContent)] = struct{}{}
words = append(words, fileContent)
}
}
dbgPr("Parsed %d extras for dictionary fuzzing.\n", len(words))
return words
}