-
Notifications
You must be signed in to change notification settings - Fork 2
/
jeq.go
113 lines (90 loc) · 2.35 KB
/
jeq.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 = (*JumpEqual)(nil)
_ Jumper = (*JumpEqual)(nil)
_ Valuer = (*JumpEqual)(nil)
)
type JumpEqual struct {
Dest Register
Offset int16
Value int32
}
func (a *JumpEqual) Raw() ([]RawInstruction, error) {
return []RawInstruction{
{Op: BPF_JEQ | BPF_K | BPF_JMP, Reg: NewReg(0, a.Dest), Off: a.Offset, Imm: a.Value},
}, nil
}
func (a *JumpEqual) String() string {
return fmt.Sprintf("if r%s == %d goto %+d", a.Dest, a.Value, a.Offset)
}
func (a *JumpEqual) SetJumpTarget(relAddr int16) {
a.Offset = relAddr
}
func (a *JumpEqual) SetValue(value int32) {
a.Value = value
}
var (
_ Instruction = (*JumpEqual32)(nil)
_ Jumper = (*JumpEqual32)(nil)
_ Valuer = (*JumpEqual32)(nil)
)
type JumpEqual32 struct {
Dest Register
Offset int16
Value int32
}
func (a *JumpEqual32) Raw() ([]RawInstruction, error) {
return []RawInstruction{
{Op: BPF_JEQ | BPF_K | BPF_JMP32, Reg: NewReg(0, a.Dest), Off: a.Offset, Imm: a.Value},
}, nil
}
func (a *JumpEqual32) String() string {
return fmt.Sprintf("if w%s == %d goto %+d", a.Dest, a.Value, a.Offset)
}
func (a *JumpEqual32) SetJumpTarget(relAddr int16) {
a.Offset = relAddr
}
func (a *JumpEqual32) SetValue(value int32) {
a.Value = value
}
var (
_ Instruction = (*JumpEqualRegister)(nil)
_ Jumper = (*JumpEqualRegister)(nil)
)
type JumpEqualRegister struct {
Dest Register
Src Register
Offset int16
}
func (a *JumpEqualRegister) Raw() ([]RawInstruction, error) {
return []RawInstruction{
{Op: BPF_JEQ | BPF_X | BPF_JMP, Reg: NewReg(a.Src, a.Dest), Off: a.Offset},
}, nil
}
func (a *JumpEqualRegister) String() string {
return fmt.Sprintf("if r%s == r%s goto %+d", a.Dest, a.Src, a.Offset)
}
func (a *JumpEqualRegister) SetJumpTarget(relAddr int16) {
a.Offset = relAddr
}
var (
_ Instruction = (*JumpEqualRegister32)(nil)
_ Jumper = (*JumpEqualRegister32)(nil)
)
type JumpEqualRegister32 struct {
Dest Register
Src Register
Offset int16
}
func (a *JumpEqualRegister32) Raw() ([]RawInstruction, error) {
return []RawInstruction{
{Op: BPF_JEQ | BPF_X | BPF_JMP32, Reg: NewReg(a.Src, a.Dest), Off: a.Offset},
}, nil
}
func (a *JumpEqualRegister32) String() string {
return fmt.Sprintf("if w%s == w%s goto %+d", a.Dest, a.Src, a.Offset)
}
func (a *JumpEqualRegister32) SetJumpTarget(relAddr int16) {
a.Offset = relAddr
}