Crates.io | coffeeldr |
lib.rs | coffeeldr |
version | 0.3.1 |
created_at | 2024-10-08 14:20:23.59324+00 |
updated_at | 2025-08-23 02:55:55.292292+00 |
description | A COFF (Common Object File Format) loader written in Rust |
homepage | https://github.com/joaoviictorti/coffeeldr |
repository | https://github.com/joaoviictorti/coffeeldr |
max_upload_size | |
id | 1401255 |
size | 109,799 |
coffeeldr
is a modern and lightweight COFF (Common Object File Format) loader for Windows written in Rust, designed to run COFF files on Windows. It supports both 32-bit and 64-bit architectures and allows you to load and execute COFF files from files or memory buffers with Rustβs safety and performance guarantees.
#[no_std]
environments (with alloc
).x64
and x86
architectures.Add coffeeldr
to your project by updating your Cargo.toml
:
cargo add coffeeldr
To load a COFF file from the filesystem:
use coffeeldr::CoffeeLdr;
let mut loader = CoffeeLdr::new("path/to/coff_file.o");
match loader {
Ok(ldr) => {
println!("COFF successfully loaded from file!");
// Execute the entry point or manipulate the COFF as needed
},
Err(e) => println!("Error loading COFF: {:?}", e),
}
To load a COFF from an in-memory buffer:
use coffeeldr::CoffeeLdr;
let coff_data = include_bytes!("path/to/coff_file.o");
let mut loader = CoffeeLdr::new(coff_data);
match loader {
Ok(ldr) => {
println!("COFF successfully loaded from buffer!");
// Execute the entry point or manipulate the COFF as needed
},
Err(e) => println!("Error loading COFF: {:?}", e),
}
Once the COFF file is loaded, you can execute it by specifying the entry point:
let mut coffee = CoffeeLdr::new("path/to/coff_file.o").unwrap();
coffee.run("entry_point_function_name", None, None).unwrap();
Module stomping replaces the .text
section of a loaded module with the COFF code.
let mut coffee = CoffeeLdr::new("path/to/coff_file.o")?
.with_module_stomping("xpsservices.dll"); // specify the module to stomp
coffee.run("go", None, None)?;
coffeeldr
also provides a convenient CLI tool for interacting with COFF files directly from the command line.
Example Command:
coffee.exe --bof path/to/coff_file.o --entrypoint go
These are the types of parameters that the tool accepts for processing:
/short:<value>
: Adds a short (i16
) value./int:<value>
: Adds an integer (i32
) value./str:<value>
: Adds a string./wstr:<value>
: Adds a wide string./bin:<base64-data>
: Adds binary data decoded from base64
.Example command using ntcreatethread.o
:
coffee.exe --bof ntcreatethread.o -e go /int:4732 /bin:Y29mZmVlbGRy..
Another example using dir.o
:
coffee.exe --bof dir.o -e go /str:C:\
When using the --stomping <module>
flag, coffeeldr will identify the .text
section of the specified module and overwrite its contents with the loaded COFF payload
coffee.exe --bof whoami.o -e go --stomping xpsservices.dll
A COFF (Common Object File Format) loader written in Rust
Usage: coffee.exe [OPTIONS] --bof <BOF> [INPUTS]...
Arguments:
[INPUTS]... Multiple arguments in the format `/short:<value>`, `/int:<value>`, `/str:<value>`, `/wstr:<value>`, `/bin:<base64-data>`
Options:
-b, --bof <BOF> The command to be executed
-e, --entrypoint <ENTRYPOINT> Entrypoint to use in the execution [default: go]
--stomping <STOMPING> Enables module stomping (e.g., --stomping xpsservices.dll)
-v, --verbose... Verbose mode (-v, -vv, -vvv, etc.)
-h, --help Print help
I want to express my gratitude to these projects that inspired me to create coffeeldr
and contribute with some features:
This project is licensed under the MIT License. See the LICENSE file for details.