forked from florianl/bluebox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbluebox.go
61 lines (54 loc) · 1.5 KB
/
bluebox.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
package main
import "fmt"
type Bluebox struct {
Executables []string
Arguments [][]string
Environment []Environment
}
type Environment interface {
fmt.Stringer
}
// maps to https://pkg.go.dev/syscall#Mount
type Mount struct {
source string
target string
fstype string
flags int
data string
targetCreate bool
targetPerm uint32
}
func (m Mount) String() string {
if m.targetCreate {
return fmt.Sprintf(
" os.MkdirAll(%q, 0o%o)\n"+
" fmt.Println(\"[ ]\tos.MkdirAll(\\\"%s\\\", 0o%o)\")\n"+
" syscall.Mount(%q, %q, %q, uintptr(%d), %q)\n"+
" fmt.Println(\"[ ]\tsyscall.Mount(\\\"%s\\\", \\\"%s\\\", \\\"%s\\\", uintptr(%d), \\\"%s\\\")\")\n",
m.target, m.targetPerm,
m.target, m.targetPerm,
m.source, m.target, m.fstype, m.flags, m.data,
m.source, m.target, m.fstype, m.flags, m.data)
}
return fmt.Sprintf(
" syscall.Mount(%q, %q, %q, uintptr(%d), %q)\n"+
" fmt.Println(\"[ ]\tsyscall.Mount(\\\"%s\\\", \\\"%s\\\", \\\"%s\\\", uintptr(%d), \\\"%s\\\")\")\n",
m.source, m.target, m.fstype, m.flags, m.data,
m.source, m.target, m.fstype, m.flags, m.data)
}
// maps to https://pkg.go.dev/syscall#Mknod
type Nod struct {
path string
mode uint32
dev int
}
func (n Nod) String() string {
return fmt.Sprintf(
" os.Remove(%q)\n"+
" syscall.Mknod(%q, %d, 0x%x)\n"+
" fmt.Println(\"[ ]\tsyscall.Mknod(\\\"%s\\\", 0x%x, 0x%x)\")\n",
n.path,
n.path, n.mode, n.dev,
n.path, n.mode, n.dev,
)
}