raw_struct is a Rust procedural macro for easily declaring C-style structs that reference local or external memory, based on your memory implementation. It generates appropiate getter methods for easy access. This crate has support for no_std environments.
To use raw_struct, simply define a struct with the raw_struct attribute as following:
#[raw_struct(size = 0x10)]structMyStruct{#[field(offset = 0x00)]pubfield_a:u32,#[field(offset = 0x04)]pubfield_b:u32,#[field(offset = 0x08)]pubfield_c:[u8;0x8],}To reference the declared struct in memory you can ether do so by Reference or Copy:
let memory = [0u8;0x10];{let object = Reference::<MyStruct>::new(0x00,Arc::new(memory.clone()));println!("field_a = {:X}", object.read_field(MyStruct::field_a)?);println!("field_b = {:X}", object.read_field(MyStruct::field_b)?);}{let object = Copy::<MyStruct>::new(memory);println!("field_a = {:X}", object.read_field(MyStruct::field_a)?);println!("field_b = {:X}", object.read_field(MyStruct::field_b)?);}Examples can be found within the examples directory of this repository. These examples demonstrate how to use raw_struct in various contexts.
To run the examples, clone the repository and use the following command:
cargo run --bin <example_name>