forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilesystem.go
73 lines (63 loc) · 1.39 KB
/
filesystem.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
69
70
71
72
73
package velociraptor
import (
"context"
"www.velocidex.com/golang/velociraptor/glob"
"www.velocidex.com/golang/vfilter"
)
type GlobPlugin struct{}
func (self GlobPlugin) Call(
ctx context.Context,
scope *vfilter.Scope,
args vfilter.Dict) <-chan vfilter.Row {
globber := make(glob.Globber)
output_chan := make(chan vfilter.Row)
// Extract the glob from the args.
globs, ok := scope.Associative(args, "globs")
if ok {
switch t := globs.(type) {
case string:
globber.Add(t, "/")
case []vfilter.Any:
for _, item := range t {
switch item_t := item.(type) {
case string:
globber.Add(item_t, "/")
default:
vfilter.Debug("Unsupported arg type")
}
}
default:
vfilter.Debug("Unsupported args")
}
} else {
// If not args specified just glob *
globber.Add("*", "/")
}
go func() {
defer close(output_chan)
file_chan := globber.ExpandWithContext(
ctx, "/", glob.OSFileSystemAccessor{})
for {
select {
case <-ctx.Done():
return
case f, ok := <-file_chan:
if !ok {
return
}
output_chan <- f
}
}
}()
return output_chan
}
func (self GlobPlugin) Name() string {
return "glob"
}
func (self GlobPlugin) Info(type_map *vfilter.TypeMap) *vfilter.PluginInfo {
return &vfilter.PluginInfo{
Name: "glob",
Doc: "Retrieve files based on a list of glob expressions",
RowType: type_map.AddType(glob.OSFileInfo{}),
}
}