class TStructTest(cst.TContainerMixin): type_int: int = cst.sfield(cs.Computed(lambda ctx: 50)) type_float: float = cst.sfield(cs.Computed(lambda ctx: 80.0)) type_bool: bool = cst.sfield(cs.Computed(lambda ctx: True)) type_bytes: bytes = cst.sfield( cs.Computed(lambda ctx: bytes([0x00, 0xAB]))) type_bytearray: bytearray = cst.sfield( cs.Computed(lambda ctx: bytearray([0x00, 0xAB, 0xFF])))
def ClassEntry_(): return Struct( "_type" / Int16ul, "isInstance" / C.Computed(lambda this: this._type & 1), "Class_Index" / C.Computed(lambda this: this._type >> 1), "_valid" / C.Computed(lambda this: this._type < len(this._root.defs)), "index" / Int16ul, "content" / C.If( this.isInstance, C.LazyBound(lambda: PrefixedOffset( Int64ul, ClassImplementation(this._._.Class_Index), -8))))
def ClassImpl(id): return C.FocusedSeq( "classes", "_class" / C.Computed(lambda this: this._root.defs[evaluate(id, this)]), "classes" / C.FocusedSeq( "entries", "_index" / C.Index, "_member" / C.Computed(lambda this: this._._class.members[this._index]), "entries" / C.Sequence(C.Computed(this._._member.name), DataEntry(lambda this: this._._._member.type)))[C.len_( this._class.members)])
class TStructTest(cst.TContainerMixin): @dataclasses.dataclass class Entry(cst.TContainerMixin): id: int = cst.sfield(cs.Int8sb) width: int = cst.sfield(cs.Int8sb) height: int = cst.sfield(cs.Int8sb) entries: t.List[Entry] = cst.sfield(cs.GreedyRange(cst.TStruct(Entry))) cnt: int = cst.sfield(cs.Computed(lambda ctx: len(ctx.entries)))
"TONE_AMPLITUDE" / c.Byte, ) SpeechPCMPacket = c.Struct( "FIELD_ID" / c.Const(b'\x40'), "SPEECHD" / c.Optional(SpeechPCM), "CMODE" / c.Optional(SpeechCMODE), "TONE" / c.Optional(SpeechTONE), ) SpeechPCMResp = c.Struct( "FIELD_ID" / c.Const(b'\x00'), "NUM_SAMPLES" / c.Byte, # 156 - 164 "DATA" / c.Array(c.this.NUM_SAMPLES, c.Int16ub), "BYTES" / c.Computed(lambda this: struct.pack('H' * this.NUM_SAMPLES, *this.DATA)), "CMODE" / c.Optional(SpeechDCMODE)) ############################################################################### # Channel Messages ChannelCMODE = c.Struct( "FIELD_ID" / c.Const(b'\x02'), "CMODE_IN" / c.FlagsEnum( c.Int16ub, LOST_FRAME=0x0004, CNI_FRAME=0x0008, TS_ENABLE=0x4000, )) ChannelECMODE = c.Struct("FIELD_ID" / c.Const(b'\x02'), "ECMODE_OUT" / ECMODE_OUT)
from streaming import convertStreaming #from tex_math import (ruD,ulog2,bitCount,linearize,dotDivide,hypersize,#deswizzle, # squareWidth,squareHeight,blockWidth,blockHeight,packetSize, # capSuperBlock) from tex_math import deswizzle, ruD, packetSize, ulog2 from debugging import DEBUG mipData = C.Struct( "mipOffset" / C.Int64ul, "compressedSize" / C.Int32ul, "uncompressedSize" / C.Int32ul, ) swizzleData = C.Struct( "swizzleHeightDepth" / C.Int8ul, "swizzleHeight" / C.Computed(C.this.swizzleHeightDepth & 0xF), "swizzleDepth" / C.Computed(C.this.swizzleHeightDepth & 0xF0 >> 4), "swizzleWidth" / C.Int8ul, "NULL1" / C.Int16ul, "SEVEN" / C.Const(7, C.Int16ul), "ONE_1" / C.Const(1, C.Int16ul), ) swizzleNull = C.Struct( "swizzleHeightDepth" / C.Int8ul, "swizzleHeight" / C.Computed(C.this.swizzleHeightDepth & 0xF), "swizzleDepth" / C.Computed(C.this.swizzleHeightDepth & 0xF0 >> 4), "swizzleWidth" / C.Int8ul, "NULL1" / C.Int16ul, "SEVEN" / C.Const(0, C.Int16ul), "ONE_1" / C.Const(0, C.Int16ul),
class TestContainer(cst.TContainerBase): _1: int = cst.TStructField(cs.Computed(7)) _2: cst.Opt[bytes] = cst.TStructField(cs.Const(b"JPEG")) _3: None = cst.TStructField(cs.Pass) _4: None = cst.TStructField(cs.Terminated)
mac_header_t = ct.Struct( "fcf" / fcf_t, "seqnum" / ct.Hex(ct.Int8ul), "dst_addr" / ct.Switch( lambda ctx: int(ctx.fcf.dst_addressing_mode), { int(addressing_mode_t.SHORT): short_addr_t, int(addressing_mode_t.LONG): long_addr_t, }), "src_addr" / ct.If( lambda ctx: is_address_present(ctx.fcf.src_addressing_mode), ct.Struct( "pan_id" / ct.IfThenElse( lambda ctx: ctx._.fcf.pan_id_comp and is_address_present( ctx._.fcf.dst_addressing_mode), ct.Computed(ct.this._.dst_addr.pan_id), ct.Hex(ct.Int16ul)), "addr" / ct.Switch( lambda ctx: int(ctx._.fcf.src_addressing_mode), { int(addressing_mode_t.SHORT): ct.Hex(ct.Int16ul), int(addressing_mode_t.LONG): ct.Hex(ct.Int64ul) }))), ) mpdu_t = ct.Struct( "mac" / mac_header_t, "pdu_offset" / ct.Tell, "pdu" / ct.ExprAdapter(ct.HexDump(ct.GreedyBytes), ct.obj_[:-2], ct.obj_ + "AA"), ct.Seek(-2, ct.io.SEEK_CUR), "fcs_offset" / ct.Tell, ct.If(ct.this.pdu_offset > ct.this.fcs_offset, ct.Error), "fcs" / ct.Hex(ct.Int16ul)) phr_t = ct.BitStruct("reserved" / ct.Bit, "size" / ct.BitsInteger(7))
"frame_width" / construct.Int16ul, # + 0x14 "frame_height" / construct.Int16ul, # + 0x16 "end_gdv_header" / construct.Tell, ) # # GDV file # gdv_file = construct.Struct( "gdv_header" / gdv_header, # 768-byte palette if the video is palettized (image type indicates 8 bits/pixel) "palette" / construct.If(lambda ctx: ctx.gdv_header.image_type.video_depth == "PIXEL_8_BITS", construct.OnDemandPointer(lambda ctx: ctx.gdv_header.end_gdv_header, construct.Array(0x300, "palette" / construct.Int8ul))), "start_chunks" / construct.IfThenElse(lambda ctx: ctx.gdv_header.image_type.video_depth == "PIXEL_8_BITS", construct.Computed(lambda ctx: ctx.gdv_header.end_gdv_header + 0x300), construct.Computed(lambda ctx: ctx.gdv_header.end_gdv_header)), "chunks" / construct.OnDemandPointer(lambda ctx: ctx.start_chunks, construct.Array(lambda ctx: ctx.gdv_header.nb_frames, gdv_chunk) ), ) ########################## # # Video decoder # ########################## # # 32-bit bit queue & stream reader #
CCCC = "CCCC" NULL = "\x00\x00\x00\x00" #Int version of "DXT1", ..., "DX10" #dwResourceDimension D3D10_RESOURCE_DIMENSION_UNKNOWN = 0 D3D10_RESOURCE_DIMENSION_BUFFER = 1 D3D10_RESOURCE_DIMENSION_TEXTURE1D = 2 D3D10_RESOURCE_DIMENSION_TEXTURE2D = 3 D3D10_RESOURCE_DIMENSION_TEXTURE3D = 4 DDS_PIXELFORMAT = C.Struct( "dwSize" / C.Const(32, C.Int32ul), "dwFlags" / C.Int32ul, #RGB #PixelFlags "dwFourCC" / C.PascalString( C.Computed(4), "utf-8"), #CCCC if compressed, DXT1 to DXT5 for DXTn Compression "dwRGBBitCount" / C.Int32ul, "dwRBitMask" / C.Int32ul, "dwGBitMask" / C.Int32ul, "dwBBitMask" / C.Int32ul, "dwABitMask" / C.Int32ul, ) DX10_Header = C.Struct( "dxgiFormat" / C.Int32ul, "resourceDimension" / C.Int32ul, "miscFlag" / C.Int32ul, "arraySize" / C.Int32ul, "miscFlags2" / C.Int32ul, )
class TestContainer(DataclassMixin): _1: int = csfield(cs.Computed(7)) _2: t.Optional[bytes] = csfield(cs.Const(b"JPEG")) _3: None = csfield(cs.Pass) _4: None = csfield(cs.Terminated)