class SystemAttributeMagic(pyndata.Struct): magic = pyndata.bytestring(length=4) layout = pyndata.uint8() unknown1 = pyndata.uint8() unknown2 = pyndata.padding(length=2) unknown3 = pyndata.bytestring( length=lambda s, x=None: 8 if s.unknown1 == 8 else 0)
class DNode(Struct): __ENDIAN__ = 'little' node_type = uint8(enum=constants.ObjectType) indirect_blockshift = uint8() indirect_levels = uint8() num_blockptrs = uint8() bonustype = uint8(enum=constants.ObjectType) checksum_type = uint8(enum=constants.Checksum) compression_type = uint8(enum=constants.Compression) _dnode_flags = uint8() # TODO: dnode flag bitfields used_bytes = BitField(_dnode_flags, 1, 0) userused = BitField(_dnode_flags, 1, 1) spill_blkptr = BitField(_dnode_flags, 1, 3) data_sectors = uint16() bonuslen = uint16() _pad = padding(length=4) max_block_id = uint64() used = uint64() _pad2 = padding(length=4 * 8) blkptr = array(Blockptr(), length=num_blockptrs) def bonus_length(self, o=None): if self.bonuslen != 0 and self.node_type != constants.ObjectType.NONE: return self.bonuslen elif self.node_type == constants.ObjectType.NONE: return 320 else: return self.bonuslen bonus = bytestring(length=bonus_length) # TODO: finish _final_pad = padding(length=64)
class ArrayWithFunctionLength(pyndata.Struct): def __init__(self, *a, **kw): super(ArrayWithFunctionLength, self).__init__(*a, **kw) self.real_length = 3 def length(self, length=None): if length: self.real_length = length else: return self.real_length a = pyndata.array(pyndata.uint8(), length=length)
class Header(pyndata.Struct): msg_type = pyndata.uint8()
class padded(pyndata.Struct): f = pyndata.uint8(default=0xff) pad = pyndata.padding(3)
class Header(pyndata.Struct): msg_len = pyndata.uint8()
class Message(pyndata.Struct): msg_type = pyndata.uint8() msg_length = pyndata.uint16(endian='big') payload = pyndata.bytestring(length=msg_length)
class S(pyndata.Struct): a = pyndata.uint8() b = pyndata.uint8() c = pyndata.uint8()
class ArrayWithBitfieldLength(pyndata.Struct): a = pyndata.uint8() b = pyndata.BitField(a, 8, 0) c = pyndata.array(pyndata.uint8(), length=b)
class VariableArray(pyndata.Struct): l = pyndata.uint8() a = pyndata.array(pyndata.uint8(), length=l)
class FixedArrayTests(pyndata.Struct): arr = pyndata.array(pyndata.uint8(), 3)
class S1(pyndata.Struct): f = pyndata.uint8()
class SubStruct(pyndata.Struct): x = pyndata.uint8()
class s(pyndata.Struct): first = pyndata.uint8() second = pyndata.uint8(default=5)
class S(pyndata.Struct): _a = pyndata.uint8() b = pyndata.uint8() c = pyndata.BitField(b, 1) _d = pyndata.BitField(b, 1)
class VariableBytestring(pyndata.Struct): l = pyndata.uint8() s = pyndata.bytestring(length=l)