#ebpf #btf

btfparse

A BTF parser library capable of navigating types

10 stable releases

Uses new Rust 2024

1.3.9 Jan 8, 2026
1.3.8 Jan 7, 2026
1.3.7 Dec 25, 2025
1.3.6 Nov 14, 2025
1.3.1 Feb 18, 2024

#188 in Development tools

Download history 346/week @ 2025-12-07 90/week @ 2025-12-14 143/week @ 2025-12-21 108/week @ 2025-12-28 44/week @ 2026-01-04 6/week @ 2026-01-11 46/week @ 2026-01-18 200/week @ 2026-01-25 2/week @ 2026-02-01 7/week @ 2026-02-08 13/week @ 2026-02-15 37/week @ 2026-02-22 93/week @ 2026-03-01

150 downloads per month

Apache-2.0

180KB
4K SLoC

btfparse

btfparse is a library that can be used to parse the BPF Type Format (BTF)

Examples

Retrieving member offsets

The full source code for this example can be found in the ./src/bin/get-type-offset.rs file.

fn main() {
    let argument_list: Vec<String> = env::args().collect();
    if argument_list.len() != 4 {
        println!("Usage:\n\tget-type-offset /path/to/btf/file <type_name> <path>\n");
        return;
    }

    let btf_file_path = Path::new(&argument_list[1]);
    let btf_type_name = &argument_list[2];
    let type_path = &argument_list[3];

    println!("Opening BTF file: {:?}", btf_file_path);

    let vmlinux_btf_file = ReadableFile::new(btf_file_path);
    let type_information = TypeInformation::new(&vmlinux_btf_file).unwrap();
    let offset = type_information
        .offset_of(type_information.id_of(btf_type_name).unwrap(), type_path)
        .unwrap();

    println!("{} => {}: {:?}", btf_type_name, type_path, offset);
}

Example output:

sh-5.2$ get-type-offset /sys/kernel/btf/vmlinux 'dentry' 'd_name.len'
Opening BTF file: "/sys/kernel/btf/vmlinux"
dentry => d_name.len: (23, ByteOffset(36))

No runtime deps

Features