memflow-py icon indicating copy to clipboard operation
memflow-py copied to clipboard

Optional explicit sizing of structure

Open emesare opened this issue 2 years ago • 0 comments

class SizedStruct(Structure):
  _size_ = 0x4
  _fields_ = [("len", c_int16)]

_size_ will bound _fields_ & _offsets_ to be at most, >= _size_, while also ensuring that the structures size in memory is respected so that if the fields defined are less than _size_ (in bytes) the subsequent associated reads are starting at _size_. i.e.

class Test(Structure):
  _fields_ = [("sized", SizedStruct), ("num", c_int32)]

The field num should be at offset 0x4 of the structure Test, instead of 0x2.

emesare avatar Apr 03 '23 01:04 emesare