offsetter 1.1.1

Allows to easily create structs for gamehacking/other process injection work when only some of fields are known
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented1 out of 1 items with examples
  • Size
  • Source code size: 11.79 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 246.43 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 25s Average build duration of successful builds.
  • all releases: 33s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • farvend

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 offsetter::offset;

offset!(
    pub struct Entity {
        0x0  id: u32,
        0x8  health: f32,
        0xC  max_health: f32,
        0x10 position: [f32; 3],
        0x20 team_id: u32,
    }
);

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!(
    struct Bad {
        0x0 a: u8,
        0x5 b: u32,
    }
);

Syntax

offset!(
    [attributes]
    [visibility] struct Name {
        offset [visibility] field_name: Type,
        ...
    }
);
  • 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 offsetter::offset;

offset!(
    struct UNICODE_STRING {
        0x0 length: u16,
        0x2 maximum_length: u16,
        0x8 buffer: u64,
    }
);

offset!(
    pub struct Player {
        0x0   vtable: usize,
        0x8   id: u32,
        0xDC  position: [f32; 3],
        0x168 name: [u16; 32],
        0x1BC max_health: u32,
        0x21C health: i32,
        0x250 world_position: [f32; 3],
        0x2D4 target: usize,
        0x2F4 speed: f32,
    }
);

License

MIT