forked from mhsh68y/hashcat.launcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan.go
68 lines (58 loc) · 1.23 KB
/
scan.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
64
65
66
67
68
package hashcatlauncher
import (
"errors"
"os"
"path/filepath"
)
const MaxRecursiveFileWalk = 1000
func fileWalk(dir string, level *int) ([]string, error) {
if level == nil {
level = new(int)
*level = 0
} else {
*level++
}
if *level > MaxRecursiveFileWalk {
return nil, errors.New("Too many recursive file walk (cyclic import?)")
}
files := []string{}
err := filepath.Walk(dir, func(path string, f os.FileInfo, err error) error {
if f == nil {
return nil
}
if f.IsDir() {
return nil
}
if f.Mode()&os.ModeSymlink != 0 {
realPath, err := filepath.EvalSymlinks(path)
if err != nil {
return err
}
realPathFiles, err := fileWalk(realPath, level)
if err != nil {
return err
}
files = append(files, realPathFiles...)
} else {
files = append(files, path)
}
return nil
})
return files, err
}
func (a *App) ScanHashes() (err error) {
a.Hashes, err = fileWalk(a.HashesDir, nil)
return
}
func (a *App) ScanDictionaries() (err error) {
a.Dictionaries, err = fileWalk(a.DictionariesDir, nil)
return
}
func (a *App) ScanRules() (err error) {
a.Rules, err = fileWalk(a.RulesDir, nil)
return
}
func (a *App) ScanMasks() (err error) {
a.Masks, err = fileWalk(a.MasksDir, nil)
return
}