pub fn get_insn(prog: &[u8], idx: usize) -> InsnExpand description
Get the instruction at idx of an eBPF program. idx is the index (number) of the
instruction (not a byte offset). The first instruction has index 0.
§Panics
Panics if it is not possible to get the instruction (if idx is too high, or last instruction is incomplete).
§Examples
use rbpf::ebpf;
let prog = &[
0xb7, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
];
let insn = ebpf::get_insn(prog, 1);
assert_eq!(insn.opc, 0x95);The example below will panic, since the last instruction is not complete and cannot be loaded.
ⓘ
use rbpf::ebpf;
let prog = &[
0xb7, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x95, 0x00, 0x00, 0x00, 0x00, 0x00 // two bytes missing
];
let insn = ebpf::get_insn(prog, 1);