memflow / memflow-py

Python support for memflow
https://pypi.org/project/memflow/
MIT License
13 stars 4 forks source link

Optional explicit sizing of structure #22

Open emesare opened 1 year ago

emesare commented 1 year ago
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.