forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.go
67 lines (52 loc) · 1.17 KB
/
profile.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
package debug
import (
"context"
"strings"
"sync"
"www.velocidex.com/golang/velociraptor/json"
"www.velocidex.com/golang/vfilter"
)
type ProfileWriter func(
ctx context.Context, scope vfilter.Scope,
output_chan chan vfilter.Row)
type ProfileWriterInfo struct {
Name, Description string
ProfileWriter ProfileWriter
}
var (
mu sync.Mutex
handlers []ProfileWriterInfo
)
func RegisterProfileWriter(writer ProfileWriterInfo) {
mu.Lock()
defer mu.Unlock()
handlers = append(handlers, writer)
}
func GetProfileWriters() (result []ProfileWriterInfo) {
mu.Lock()
defer mu.Unlock()
for _, i := range handlers {
result = append(result, i)
}
return result
}
func DumpWriter(
ctx context.Context, scope vfilter.Scope, name string) string {
var rows []string
for _, w := range GetProfileWriters() {
if w.Name == name {
output_chan := make(chan vfilter.Row)
go func() {
defer close(output_chan)
for r := range output_chan {
line := json.MustMarshalString(r)
if !strings.Contains(line, "Destroyed") {
rows = append(rows, line)
}
}
}()
w.ProfileWriter(ctx, scope, output_chan)
}
}
return strings.Join(rows, "\n")
}