offsetter
A lightweight Rust macro for defining structs with explicit field offsets and automatic padding generation.
Useful for game hacking, reverse engineering, process memory manipulation, and FFI work where struct layouts are known only partially.
Disclaimer
This is not my original idea and I didn't come up with the name. All credit goes to the author of this post, who for some reason deleted the crate from crates.io.
Usage
use offset;
offset!;
This expands into a #[repr(C)] struct with hidden _padN: [u8; ...] fields between your fields, ensuring each field sits at the exact byte offset you specified.
Alignment checking
Offsets are validated at compile time. Misaligned offsets produce a clear error:
// compile error: "field `b` at offset 0x5 violates alignment of type `u32`"
offset!;
Syntax
offset!;
offset— hex or decimal byte offset (e.g.0x10,16)- Field visibility is optional — fields are always generated as
pub - The struct is always
#[repr(C)]
Example
use offset;
offset!;
offset!;
License
MIT