...
1
2
3
4
5 package bpf
6
7 import "fmt"
8
9
10
11
12
13
14 func Assemble(insts []Instruction) ([]RawInstruction, error) {
15 ret := make([]RawInstruction, len(insts))
16 var err error
17 for i, inst := range insts {
18 ret[i], err = inst.Assemble()
19 if err != nil {
20 return nil, fmt.Errorf("assembling instruction %d: %s", i+1, err)
21 }
22 }
23 return ret, nil
24 }
25
26
27
28
29
30
31 func Disassemble(raw []RawInstruction) (insts []Instruction, allDecoded bool) {
32 insts = make([]Instruction, len(raw))
33 allDecoded = true
34 for i, r := range raw {
35 insts[i] = r.Disassemble()
36 if _, ok := insts[i].(RawInstruction); ok {
37 allDecoded = false
38 }
39 }
40 return insts, allDecoded
41 }
42
View as plain text