Skip to main content

BpfCodec

Struct BpfCodec 

Source
pub struct BpfCodec(pub BpfVariant);
Expand description

One codec per BPF variant.

Tuple Fields§

§0: BpfVariant

Implementations§

Source§

impl BpfCodec

Source

pub const LINUX: Self

Linux eBPF (base ISA).

Source

pub const SBF_V1: Self

Solana sBPFv1.

Source

pub const SBF_V2: Self

Agave sBPFv2.

Trait Implementations§

Source§

impl ArchCodec for BpfCodec

Source§

fn encode_call( &self, source_ip: u64, target: u64, hints: EncodeHints, ) -> Result<Vec<u8>, ArchError>

Encode an intra-program call. The choice between call_local (opcode 0x8d, Linux eBPF convention) and call_internal (opcode 0x85 src=1, Solana sBPF convention) is hinted by EncodeHints::bpf_call_local: Some(true) → call_local, Some(false) → call_internal, None → default to call_internal (Solana sBPF, the dominant convention in practice; Solana programs often carry e_machine = EM_BPF (247) despite using the sBPF call form, so the EM marker alone can’t disambiguate). The imm is the slot delta from the next slot to the target, signed.

Syscalls (opcode 0x85 src=0, imm = a name hash or -1) don’t go through this method — they remain pinned in Stmt::Call.bytes because the imm depends on relocation context the codec doesn’t carry.

Source§

fn direct_call_bytes_contain_call(&self) -> bool

BPF calls are single 8-byte instructions — pinned Stmt::Call.bytes (when present) is the complete call.

Source§

fn encode_move(&self, dst: &str, src: &str) -> Result<Vec<u8>, ArchError>

Encode dst = src as one BPF instruction.

Supported shapes:

  • ("rN", "rM")mov64 rN, rM (8 bytes)
  • ("rN", "0xN")mov64 rN, imm32 (8 bytes)
  • ("rN", "[rM ± off]") (optional :uNN suffix) → ldxdw / ldxw / ldxh / ldxb rN, [rM ± off] (8 bytes)
  • ("[rN ± off]", "rM") (optional :uNN suffix on dst) → stxdw / stxw / stxh / stxb [rN ± off], rM (8 bytes)
  • ("rN", "0x<imm>:u64")lddw rN, 0x<imm> (16 bytes, two BPF slots — the second being a zero-opcode continuation slot carrying the high 32 bits)

The :u<bits> size suffix on a memory operand picks the access width (:u8 / :u16 / :u32 / :u64); the bare [rN ± off] form defaults to :u64 (BPF dw).

Source§

fn encode_return(&self, _value: Option<u64>) -> Result<Vec<u8>, ArchError>

Encode a function return. BPF returns r0 implicitly via the exit instruction; the value field is ignored.

Source§

fn encode_arith( &self, dst: &str, op: &str, src: &str, ) -> Result<Vec<u8>, ArchError>

Encode dst op src as a single 64-bit BPF ALU instruction. The op string maps to the corresponding BPF mnemonic; the src may be a register (r0..r10) or an immediate (0x<hex> / decimal).

Returns Unsupported for operators outside the lifted set (arsh, neg, 32-bit forms keep their @asm rendering for now).

Source§

fn name(&self) -> &'static str

Short stable identifier used in error messages and ArchError::Unsupported.arch. Recommended forms: "x86-64", "x86-32", "bpf-linux", "bpf-sbf-v1", "bpf-sbf-v2", "aarch64", "6502".
Source§

fn assemble_one(&self, text: &str, _addr: u64) -> Result<Vec<u8>, ArchError>

Assemble one instruction’s text into bytes at addr. Read more
Source§

fn desymbolize(&self, text: &str, addr: u64) -> String

Resolve symbolic operands in text against addr. The default is identity — arches with named-target operands (BPF’s label_<hex> / sub_<hex>) override to substitute numeric forms the assembler accepts.
Source§

fn encode_jump( &self, source_ip: u64, target: u64, _hints: EncodeHints, ) -> Result<Vec<u8>, ArchError>

Encode an unconditional jump from source_ip to target.
Source§

fn encode_cond_jump( &self, cond_text: &str, source_ip: u64, target: u64, _hints: EncodeHints, ) -> Result<Vec<u8>, ArchError>

Encode a conditional jump driven by a BPF-style text condition. Read more
Source§

fn encode_switch_dispatch( &self, _spec: &SwitchSpec<'_>, ) -> Result<Vec<u8>, ArchError>

Encode a jump-table dispatch. Default Unsupported.
Source§

fn encoded_jump_size( &self, _source_ip: u64, _target: u64, _hints: EncodeHints, ) -> usize

Predicted size of encode_jump’s output.
Source§

fn encoded_cond_jump_size( &self, _source_ip: u64, _target: u64, _hints: EncodeHints, ) -> usize

Predicted size of encode_cond_jump (text-driven).
Source§

fn encoded_call_size( &self, _source_ip: u64, _target: u64, _hints: EncodeHints, ) -> usize

Predicted size of encode_call’s output.
Source§

fn encode_cond_jump_with_code( &self, _cond_code: u8, _source_ip: u64, _target: u64, _hints: EncodeHints, ) -> Result<Vec<u8>, ArchError>

Encode a conditional jump driven by an x86-style numeric cond_code (the low nibble of the jcc opcode). Read more
Source§

impl Clone for BpfCodec

Source§

fn clone(&self) -> BpfCodec

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BpfCodec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for BpfCodec

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.