class ExampleStructure(destructify.Structure):
     some_number = destructify.IntegerField(default=0x13,
                                            length=4,
                                            byte_order='little',
                                            signed=True)
     length = destructify.IntegerField(length=1)
     data = destructify.FixedLengthField(length='length')
Exemple #2
0
class PngChunk_IHDR(destructify.Structure):
    width = destructify.IntegerField(4, "big")
    height = destructify.IntegerField(4, "big")
    bit_depth = destructify.IntegerField(1)
    color_type = destructify.EnumField(destructify.IntegerField(1), ColorType)
    compression_method = destructify.IntegerField(1)
    filter_method = destructify.IntegerField(1)
    interlace_method = destructify.EnumField(destructify.IntegerField(1), InterlaceMethod)
Exemple #3
0
class PngChunk(destructify.Structure):
    length = destructify.IntegerField(4, "big")
    chunk_type = destructify.EnumField(destructify.StringField(length=4, encoding="ascii"), enum=ChunkType)
    chunk_data = destructify.SwitchField(
        cases={
            ChunkType.IHDR: destructify.StructureField(PngChunk_IHDR, length='length'),
            ChunkType.IEND: destructify.ConstantField(b""),
            ChunkType.TEXT: destructify.StructureField(PngChunk_tEXt, length='length'),
            ChunkType.PHYS: destructify.StructureField(PngChunk_pHYs, length='length'),
            ChunkType.PLTE: destructify.StructureField(PngChunk_PLTE, length='length'),
        },
        switch="chunk_type",
        other=destructify.FixedLengthField("length")
    )
    crc = destructify.IntegerField(4, "big", override=lambda f, v: calculate_crc(f))

    class Meta:
        capture_raw = True
        checks = [
            lambda f: f._context.fields['chunk_data'].length == f.length,
            lambda f: calculate_crc(f) == f.crc,
        ]
Exemple #4
0
class PngChunk_pHYs(destructify.Structure):
    pixels_per_unit_x = destructify.IntegerField(4, "big")
    pixels_per_unit_y = destructify.IntegerField(4, "big")
    unit = destructify.EnumField(destructify.IntegerField(1), PhysUnit)
Exemple #5
0
class PaletteEntry(destructify.Structure):
    red = destructify.IntegerField(length=1)
    green = destructify.IntegerField(length=1)
    blue = destructify.IntegerField(length=1)