-
Notifications
You must be signed in to change notification settings - Fork 2
/
jset.go
113 lines (90 loc) · 2.29 KB
/
jset.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package ebpf
import "fmt"
var (
_ Instruction = (*JumpAnd)(nil)
_ Jumper = (*JumpAnd)(nil)
_ Valuer = (*JumpAnd)(nil)
)
type JumpAnd struct {
Dest Register
Offset int16
Value int32
}
func (a *JumpAnd) Raw() ([]RawInstruction, error) {
return []RawInstruction{
{Op: BPF_JSET | BPF_K | BPF_JMP, Reg: NewReg(0, a.Dest), Off: a.Offset, Imm: a.Value},
}, nil
}
func (a *JumpAnd) String() string {
return fmt.Sprintf("if r%s & %d goto %+d", a.Dest, a.Value, a.Offset)
}
func (a *JumpAnd) SetJumpTarget(relAddr int16) {
a.Offset = relAddr
}
func (a *JumpAnd) SetValue(value int32) {
a.Value = value
}
var (
_ Instruction = (*JumpAnd32)(nil)
_ Jumper = (*JumpAnd32)(nil)
_ Valuer = (*JumpAnd32)(nil)
)
type JumpAnd32 struct {
Dest Register
Offset int16
Value int32
}
func (a *JumpAnd32) Raw() ([]RawInstruction, error) {
return []RawInstruction{
{Op: BPF_JSET | BPF_K | BPF_JMP32, Reg: NewReg(0, a.Dest), Off: a.Offset, Imm: a.Value},
}, nil
}
func (a *JumpAnd32) String() string {
return fmt.Sprintf("if w%d & %d goto %+d", a.Dest, a.Value, a.Offset)
}
func (a *JumpAnd32) SetJumpTarget(relAddr int16) {
a.Offset = relAddr
}
func (a *JumpAnd32) SetValue(value int32) {
a.Value = value
}
var (
_ Instruction = (*JumpAndRegister)(nil)
_ Jumper = (*JumpAndRegister)(nil)
)
type JumpAndRegister struct {
Dest Register
Src Register
Offset int16
}
func (a *JumpAndRegister) Raw() ([]RawInstruction, error) {
return []RawInstruction{
{Op: BPF_JSET | BPF_X | BPF_JMP, Reg: NewReg(a.Src, a.Dest), Off: a.Offset},
}, nil
}
func (a *JumpAndRegister) String() string {
return fmt.Sprintf("if r%s & r%s goto %+d", a.Dest, a.Src, a.Offset)
}
func (a *JumpAndRegister) SetJumpTarget(relAddr int16) {
a.Offset = relAddr
}
var (
_ Instruction = (*JumpAndRegister32)(nil)
_ Jumper = (*JumpAndRegister32)(nil)
)
type JumpAndRegister32 struct {
Dest Register
Src Register
Offset int16
}
func (a *JumpAndRegister32) Raw() ([]RawInstruction, error) {
return []RawInstruction{
{Op: BPF_JSET | BPF_X | BPF_JMP32, Reg: NewReg(a.Src, a.Dest), Off: a.Offset},
}, nil
}
func (a *JumpAndRegister32) String() string {
return fmt.Sprintf("if w%d & w%d goto %+d", a.Dest, a.Src, a.Offset)
}
func (a *JumpAndRegister32) SetJumpTarget(relAddr int16) {
a.Offset = relAddr
}