Skip to content

jermainlaforce/rustbof

 
 

Repository files navigation

rustbof

Rust License

This project enables the development of BOFs using Rust with full no_std support. It leverages Rust's safety features and modern tooling while producing small, efficient COFF objects.

The framework provides everything needed for BOF development. The build process compiles your code to a static library, which boflink then links into a COFF object with proper relocations and imports for Beacon's dynamic function resolution.

Requirements

Quick Start

The easiest way to get started is using the project template with cargo-generate. This will create a new BOF project with all the necessary configuration already set up:

cargo generate --git https://github.com/joaoviictorti/rustbof .template
cd <project-name>
cargo make

Alternatively, you can clone the repository and explore the examples/ directory, which contains working BOF implementations demonstrating various use cases. These examples serve as practical references for building your own BOFs.

git clone https://github.com/joaoviictorti/rustbof
cd rustbof/examples/whoami
cargo make

You can also use Docker to build without installing the toolchain locally:

git clone https://github.com/joaoviictorti/rustbof
cd rustbof
docker build -t rustbof .
docker run -it rustbof

Usage

The #[rustbof::main] attribute macro generates the entry point required by BOF loaders. Your main function can be simple with no arguments, or receive raw argument data for parsing.

A basic BOF that prints a message:

#![no_std]

use rustbof::println;

#[rustbof::main]
fn main() {
    println!("Hello from Rust BOF!");
}

For BOFs that need to receive arguments, use DataParser to extract typed values from the raw argument buffer:

#![no_std]

use rustbof::println; 
use rustbof::data::DataParser;

#[rustbof::main]
fn main(args: *mut u8, len: usize) {
    let mut parser = DataParser::new(args, len);
    let name = parser.get_str();
    println!("Hello, {name}!");
}

Examples

The examples directory contains working BOFs: whoami, ipconfig and env.

License

rustbof is licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in rustbof by you, as defined in the Apache-2.0 license, shall be dually licensed as above, without any additional terms or conditions.

About

A Rust template for writing Beacon Object Files (BOFs)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Rust 95.5%
  • Dockerfile 2.8%
  • Liquid 1.7%