-
Notifications
You must be signed in to change notification settings - Fork 43
/
main.go
65 lines (51 loc) · 1.03 KB
/
main.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
package main
import (
"fmt"
"os"
"os/exec"
"syscall"
)
func main() {
var regs syscall.PtraceRegs
var ss syscallCounter
ss = ss.init()
fmt.Printf("Run %v\n", os.Args[1:])
// Uncommenting this will cause the open syscall to return with Operation Not Permitted error
// disallow("open")
cmd := exec.Command(os.Args[1], os.Args[2:]...)
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.SysProcAttr = &syscall.SysProcAttr{
Ptrace: true,
}
cmd.Start()
err := cmd.Wait()
if err != nil {
fmt.Printf("Wait returned: %v\n", err)
}
pid := cmd.Process.Pid
exit := true
for {
if exit {
err = syscall.PtraceGetRegs(pid, ®s)
if err != nil {
break
}
// Uncomment to show each syscall as it's called
// name := ss.getName(regs.Orig_rax)
// fmt.Printf("%s\n", name)
ss.inc(regs.Orig_rax)
}
err = syscall.PtraceSyscall(pid, 0)
if err != nil {
panic(err)
}
_, err = syscall.Wait4(pid, nil, 0, nil)
if err != nil {
panic(err)
}
exit = !exit
}
ss.print()
}