Python 用于MPEG2-TS的Scapy层,带有用于自适应的条件字段

Python 用于MPEG2-TS的Scapy层,带有用于自适应的条件字段,python,scapy,Python,Scapy,我尝试为scapy创建一个MPEG2-TS层 我需要根据Adaption字段“添加”并解析其他字段 这是我的密码: _adapt_type = { 0x0 : 'Reserved', 0x1 : 'Payload only', 0x2 : 'Adaptation only', 0x3 : 'Adaptation and payload', } class MPEG2_TS(Packet): name = "MPEG2-TS" fields_desc=[

我尝试为scapy创建一个MPEG2-TS层

我需要根据Adaption字段“添加”并解析其他字段

这是我的密码:

_adapt_type = {
0x0 : 'Reserved',
0x1 : 'Payload only',
0x2 : 'Adaptation only',
0x3 : 'Adaptation and payload',
}

class MPEG2_TS(Packet):
    name = "MPEG2-TS"
    fields_desc=[

            ByteEnumField('sync_byte', 0x47, _sync_type),
            BitField('trans_err',0x0, 1),
            # Transport Error Indicator (TEI) if set to 1 decoder ignore packet

            BitField('start_ind',0x0, 1),
            BitField('trans_pri',0x0, 1),
            XBitField('pid', 0xA, 13),
            BitEnumField('trans_scramb', 0x0, 2, _scramble_type),
            BitEnumField('adapt_ctrl', 0x0, 2, _adapt_type),
            BitField('cont_count', 0x0, 4),
            ]
如果adapt_ctrl设置为:

0x1 : 'Payload only',
0x2 : 'Adaptation only',
0x3 : 'Adaptation and payload'
如何创建一个条件,以便能够基于此字段的结果对其进行解析? 如果设置了“Payload Only”位,则在报头之后没有自适应字段,因此我们不需要解析它。 如果设置了“自适应和有效负载”,我需要使用以下结构解析自适应字段:

_adapt_fields = [

            # Number of bytes in the adaptation field immediately following this byte
            ByteField('ada_len', 0x0),

            # Set to 1 if current TS packet is in a discontinuity state with respect to either the continuity counter or the program clock reference
            BitField('dis', 0x0, 1),

            # Set to 1 if the PES packet in this TS packet starts a video/audio sequence
            BitField('ran_acc', 0x0, 1),

            # 1 = higher priority
            BitField('ES_str_pri', 0x0, 1),

            # Set to 1 if adaptation field contains a PCR field
            BitField('PCR_fla', 0x0, 1),                

            # Set to 1 if adaptation field contains an OPCR field
            BitField('OPCR_fla', 0x0, 1),

            # Set to 1 if adaptation field contains a splice countdown field
            BitField('spl_fla', 0x0, 1),

            # Set to 1 if adaptation field contains private data bytes
            BitField('trs_pri_dat_fla', 0x0, 1),

            # Set to 1 if adaptation field contains an extension
            BitField('ada_ext_fla', 0x0, 1),                

            # variable Depends on flags
            # BitField('ada_ext_fla', 0x0, 1),              
            # PCR   33+6+9      Program clock reference, stored in 6 octets in big-endian as 33 bits base, 6 bits padding, 9 bits extension.
            # OPCR  33+6+9      Original Program clock reference. Helps when one TS is copied into another
            # Splice countdown  8       Indicates how many TS packets from this one a splicing point occurs (may be negative)
            # Stuffing bytes    variable        
            ]
我在阿尔菲尔德做了一些尝试,但到目前为止运气都不好。 谢谢你的帮助