About this project
pybpf_asm is a Python implementation of the BPF assembler originally found in the Linux kernel sources. It allows developers to write BPF assembly code and assemble it into executable BPF bytecode.
Installation can be done via pre‑built wheels from PyPI, or by building from source. Building requires a recent version of Flex and Bison. On Windows users can install winflexbison, while macOS (and older Linux) users can obtain the tools through Homebrew and ensure they appear early in the PATH.
Typical usage involves importing the bpf_asm module and calling its assemble function with a string containing BPF assembly instructions. For example:
import bpf_asm
ASM = """
ldh [12]
jeq #0x800, accept, drop
accept:
ret #65536
drop:
ret #0
"""
print(bpf_asm.assemble(ASM))
The project also provides a command‑line utility named pybpf_asm that can be invoked directly. Detailed documentation is available on the project's GitHub Pages.
The software is released under the GPL‑2.0‑only license, which requires that derivative works also be distributed under the same license.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.