I'm working on a dll that attaches to a program and reads some data from the target program. I do this by finding the struct address and casting that address to a pointer of the respective struct in my code.
Example:
class Structure {
char pad_1[0x30];
float val1;
float val2
char pad_2[0x20];
Structure* next;
}
Here if I find the address of the structure to be 0x1234 I can just do (Structure*)0x1234 and I have access to it, notice that there are some padding values, those values I simply don't know what they are or I don't need them.
I want to write this struct in my code (for maintainability purposes) as following:
class Structure {
Offset(0x30)
float val1;
float val2;
Offset(0x58) /// 0x30 + 2x floats + 0x20 padding
Structure* next;
}
This Offset macro should add padding automatically, basically with Offset(num) u specify the offset of the field in the class, this macro should add this padding automatically.
I have no idea if this is possible with C macros, right now I'm defining my models in YAML and using a python script to generate them, there are some disadvantages to this however...