-
Notifications
You must be signed in to change notification settings - Fork 57
/
hello.go
62 lines (49 loc) · 972 Bytes
/
hello.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
package main
import (
"C"
bpf "github.com/aquasecurity/tracee/libbpfgo"
)
import (
"fmt"
"os"
"os/signal"
)
func main() {
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt)
bpfModule, err := bpf.NewModuleFromFile("hello.bpf.o")
must(err)
defer bpfModule.Close()
err = bpfModule.BPFLoadObject()
must(err)
prog, err := bpfModule.GetProgram("hello")
must(err)
_, err = prog.AttachKprobe(sys_execve)
must(err)
go bpf.TracePrint()
prog, err = bpfModule.GetProgram("hello_bpftrace")
must(err)
_, err = prog.AttachRawTracepoint("sys_enter")
must(err)
e := make(chan []byte, 300)
p, err := bpfModule.InitPerfBuf("events", e, nil, 1024)
must(err)
p.Start()
counter := make(map[string]int, 350)
go func() {
for data := range e {
comm := string(data)
counter[comm]++
}
}()
<-sig
p.Stop()
for comm, n := range counter {
fmt.Printf("%s: %d\n", comm, n)
}
}
func must(err error) {
if err != nil {
panic(err)
}
}