예제 #1
0
 def createFields(self):
     yield Bits(self, "ts_32_30", 3)
     yield Bit(self, "sync[]")  # =True
     yield Bits(self, "ts_29_15", 15)
     yield Bit(self, "sync[]")  # =True
     yield Bits(self, "ts_14_0", 15)
     yield Bit(self, "sync[]")  # =True
예제 #2
0
 def createFields(self):
     yield Bits(self, "unused", 2)
     yield Bit(self, "is_tonable")
     yield Bit(self, "16bits")
     yield Bit(self, "loop_bidir")
     yield Bit(self, "loop")
     yield Enum(Bits(self, "origin", 2), self.TYPES)
예제 #3
0
    def createFields(self):
        # Signature + version
        yield String(self, "header", 3, "Header (ID3)", charset="ASCII")
        yield UInt8(self, "ver_major", "Version (major)")
        yield UInt8(self, "ver_minor", "Version (minor)")

        # Check format
        if self["header"].value != "ID3":
            raise MatchError("Signature error, should be \"ID3\".")
        if self["ver_major"].value not in self.VALID_MAJOR_VERSIONS \
                or self["ver_minor"].value != 0:
            raise MatchError(
                "Unknown ID3 metadata version (2.%u.%u)" %
                (self["ver_major"].value, self["ver_minor"].value))

        # Flags
        yield Bit(self, "unsync", "Unsynchronisation is used?")
        yield Bit(self, "ext", "Extended header is used?")
        yield Bit(self, "exp", "Experimental indicator")
        yield NullBits(self, "padding[]", 5)

        # Size
        yield ID3_Size(self, "size")

        # All tags
        while self.current_size < self._size:
            field = ID3_Chunk(self, "field[]")
            yield field
            if field["size"].value == 0:
                break

        # Search first byte of the MPEG file
        padding = self.seekBit(self._size)
        if padding:
            yield padding
예제 #4
0
 def createFields(self):
     yield Bit(self, "reference_type")
     yield Bits(self, "referenced_size", 31)
     yield UInt32(self, "subsegment_duration")
     yield Bit(self, "starts_with_SAP")
     yield Bits(self, "SAP_type", 3)
     yield Bits(self, "SAP_delta_time", 28)
예제 #5
0
    def createFields(self):
        if self._m2ts:
            yield Bits(self, "c", 2)
            yield Bits(self, "ats", 32 - 2)
        yield textHandler(UInt8(self, "sync", 8), hexadecimal)
        if self["sync"].value != 0x47:
            raise ParserError("MPEG-2 TS: Invalid synchronization byte")
        yield Bit(self, "has_error")
        yield Bit(self, "payload_unit_start")
        yield Bit(self, "priority")
        yield Enum(
            textHandler(Bits(self, "pid", 13, "Program identifier"),
                        hexadecimal), self.PID)
        yield Bits(self, "scrambling_control", 2)
        yield Bit(self, "has_adaptation")
        yield Bit(self, "has_payload")
        yield Bits(self, "counter", 4)

        if self["has_adaptation"].value:
            yield AdaptationField(self, "adaptation_field")
        if self["has_payload"].value:
            size = 188
            if self._m2ts:
                size += 4
            size -= (self.current_size // 8)
            yield RawBytes(self, "payload", size)
        if self["has_error"].value:
            yield RawBytes(self, "error_correction", 16)
예제 #6
0
 def parseFrame(self):
     yield UInt16(self, 'size')
     yield Bits(self, 'protocol', 12)  # 1024
     yield Bit(self, 'addressable')  # 1
     yield Bit(self, 'tagged')  # 1
     yield Bits(self, 'origin', 2)
     yield UInt32(self, 'source')
예제 #7
0
 def createFields(self):
     yield ABCMultinameIndex(self, "name_index")
     yield Enum(Bits(self, "kind", 4), self.TRAIT_KIND)
     yield Enum(Bit(self, "is_final"), {True: 'final', False: 'virtual'})
     yield Enum(Bit(self, "is_override"), {True: 'override', False: 'new'})
     yield Bit(self, "has_metadata")
     yield Bits(self, "unused", 1)
     kind = self["kind"].value
     if kind in (0, 6):  # slot, const
         yield FlashU30(self, "slot_id")
         yield ABCMultinameIndex(self, "type_index")
         ### TODO reference appropriate constant pool using value_kind
         yield FlashU30(self, "value_index")
         if self['value_index'].value != 0:
             yield UInt8(self, "value_kind")
     elif kind in (1, 2, 3):  # method, getter, setter
         yield FlashU30(self, "disp_id")
         yield ABCMethodIndex(self, "method_info")
     elif kind == 4:  # class
         yield FlashU30(self, "disp_id")
         yield FlashU30(self, "class_info")
     elif kind == 5:  # function
         yield FlashU30(self, "disp_id")
         yield ABCMethodIndex(self, "method_info")
     if self['has_metadata'].value:
         yield ABCObjectArray(self, "metadata", FlashU30)
예제 #8
0
    def createFields(self):
        yield UInt8(self, "id_length", "Length of the image ID field")
        yield UInt8(self, "palette_type", "Colormap present?")
        yield Enum(UInt8(self, "codec", "Pixels encoding"), self.CODEC_NAME)
        yield UInt16(self, "palette_ofs", "Palette absolute file offset")
        yield UInt16(self, "nb_color", "Number of colors in the palette")
        yield UInt8(self, "color_map_size", "Size of each palette entry")
        yield UInt16(self, "x_min")
        yield UInt16(self, "y_min")
        yield UInt16(self, "width")
        yield UInt16(self, "height")
        yield UInt8(self, "bpp", "Bits per pixel")
        yield Bits(self, "alpha_depth", 4, "Alpha channel depth")
        yield Bit(
            self, "x_flip",
            "Flip across the X-axis? (If set, columns run right-to-left)")
        yield Bit(self, "y_flip",
                  "Flip across the Y-axis? (If set, rows run top-to-bottom)")
        yield RawBits(self, "reserved_flags", 2)

        if self["id_length"].value:
            yield RawBytes(self, "image_id", self["id_length"].value)

        if self["palette_type"].value == 1:
            yield PaletteRGB(self, "palette", 1 << self["bpp"].value)

        if self["codec"] in (1, 2, 3):
            yield Pixels(self, "pixels")
        else:
            size = (self.size - self.current_size) // 8
            if size:
                yield RawBytes(self, "raw_pixels", size)
예제 #9
0
    def createFields(self):
        if self["/have_debug"].value:
            yield String(self, "signature", 32)
            if not self['signature'].value.startswith("***POIStart"):
                raise ValueError

        yield IntVbe(self, "lat_diff")
        yield IntVbe(self, "lon_diff")
        yield Bits(self, "layer", 4)
        yield Bits(self, "num_tags", 4)

        for i in range(self["num_tags"].value):
            yield UIntVbe(self, "tag_id[]")

        yield Bit(self, "have_name")
        yield Bit(self, "have_house_number")
        yield Bit(self, "have_ele")
        yield PaddingBits(self, "pad[]", 5)

        if self["have_name"].value:
            yield VbeString(self, "name")
        if self["have_house_number"].value:
            yield VbeString(self, "house_number")
        if self["have_ele"].value:
            yield IntVbe(self, "ele")
예제 #10
0
 def parseFrameAddress(self):
     yield textHandler(Bytes(self, 'target', 8), formatTargetField)  # MAC or Zeroes
     yield NullBits(self, 'reserved[]', 48)
     yield NullBits(self, 'reserved[]', 6)
     yield Bit(self, 'ack_required')
     yield Bit(self, 'res_required')
     yield UInt8(self, 'sequence')
예제 #11
0
    def createFields(self):
        yield Bits(self, "version", 4, "Version")
        yield Bits(self, "hdr_size", 4, "Header size divided by 5")

        # Type of service
        yield Enum(Bits(self, "precedence", 3, "Precedence"),
                   self.precedence_name)
        yield Bit(self, "low_delay", "If set, low delay, else normal delay")
        yield Bit(self, "high_throu",
                  "If set, high throughput, else normal throughput")
        yield Bit(self, "high_rel", "If set, high relibility, else normal")
        yield NullBits(self, "reserved[]", 2, "(reserved for future use)")

        yield UInt16(self, "length")
        yield UInt16(self, "id")

        yield NullBits(self, "reserved[]", 1)
        yield Bit(self, "df", "Don't fragment")
        yield Bit(self, "more_frag",
                  "There are more fragments? if not set, it's the last one")
        yield Bits(self, "frag_ofst_lo", 5)
        yield UInt8(self, "frag_ofst_hi")
        yield UInt8(self, "ttl", "Type to live")
        yield Enum(UInt8(self, "protocol"), self.PROTOCOL_NAME)
        yield textHandler(UInt16(self, "checksum"), hexadecimal)
        yield IPv4_Address(self, "src")
        yield IPv4_Address(self, "dst")

        size = (self.size - self.current_size) // 8
        if size:
            yield RawBytes(self, "options", size)
예제 #12
0
파일: xm.py 프로젝트: markchipman/SickGear
 def createFields(self):
     yield String(self, "signature", 17, "XM signature", charset="ASCII")
     yield String(self, "title", 20, "XM title", charset="ASCII", strip=' ')
     yield UInt8(self, "marker", "Marker (0x1A)")
     yield String(self,
                  "tracker_name",
                  20,
                  "XM tracker name",
                  charset="ASCII",
                  strip=' ')
     yield UInt8(self, "format_minor")
     yield UInt8(self, "format_major")
     yield filesizeHandler(UInt32(self, "header_size", "Header size (276)"))
     yield UInt16(self, "song_length", "Length in patten order table")
     yield UInt16(self, "restart", "Restart position")
     yield UInt16(self, "channels",
                  "Number of channels (2,4,6,8,10,...,32)")
     yield UInt16(self, "patterns", "Number of patterns (max 256)")
     yield UInt16(self, "instruments", "Number of instruments (max 128)")
     yield Bit(self, "amiga_ftable", "Amiga frequency table")
     yield Bit(self, "linear_ftable", "Linear frequency table")
     yield Bits(self, "unused", 14)
     yield UInt16(self, "tempo", "Default tempo")
     yield UInt16(self, "bpm", "Default BPM")
     yield GenericVector(self, "pattern_order", 256, UInt8, "order")
예제 #13
0
 def createFields(self):
     yield Bits(self, "start_length", 5)
     length = self["start_length"].value
     lengths = []
     for i in range(self.symbols):
         while True:
             bit = Bit(self, "change_length[%i][]" % i,
                       "Should the length be changed for symbol %i?" % i)
             yield bit
             if not bit.value:
                 break
             else:
                 bit = Enum(
                     Bit(self, "length_decrement[%i][]" % i,
                         "Decrement the value?"), {
                             True: "Decrement",
                             False: "Increment"
                         })
                 yield bit
                 if bit.value:
                     length -= 1
                 else:
                     length += 1
         lengths.append(length)
     self.final_length = length
     self.tree = build_tree(lengths)
예제 #14
0
    def createFields(self):
        yield UInt16(self, "left", "Left")
        yield UInt16(self, "top", "Top")
        yield UInt16(self, "width", "Width")
        yield UInt16(self, "height", "Height")

        yield Bits(self, "size_local_map", 3,
                   "log2(size of local map) minus one")
        yield NullBits(self, "reserved", 2)
        yield Bit(self, "sort_flag",
                  "Is the local map sorted by decreasing importance?")
        yield Bit(self, "interlaced", "Interlaced?")
        yield Bit(self, "has_local_map", "Use local color map?")

        if self["has_local_map"].value:
            nb_color = 1 << (1 + self["size_local_map"].value)
            yield PaletteRGB(self, "local_map", nb_color, "Local color map")

        yield UInt8(self, "lzw_min_code_size", "LZW Minimum Code Size")
        group = None
        while True:
            size = UInt8(self, "block_size")
            if size.value == 0:
                break
            block = CustomFragment(self, "image_block[]", None, GifImageBlock,
                                   "GIF Image Block", group)
            group = block.group
            yield block
        yield NullBytes(self, "terminator", 1, "Terminator (0)")
예제 #15
0
    def createFields(self):
        yield Unsigned(self, 'track')
        yield Int16(self, 'timecode')

        if self.parent._name == 'Block':
            yield NullBits(self, 'reserved[]', 4)
            yield Bit(self, 'invisible')
            yield self.lacing()
            yield NullBits(self, 'reserved[]', 1)
        elif self.parent._name.startswith('SimpleBlock'):
            yield Bit(self, 'keyframe')
            yield NullBits(self, 'reserved', 3)
            yield Bit(self, 'invisible')
            yield self.lacing()
            yield Bit(self, 'discardable')
        else:
            yield NullBits(self, 'reserved', 8)
            return

        size = (self._size - self.current_size) // 8
        lacing = self['lacing'].value
        if lacing:
            yield textHandler(GenericInteger(self, 'n_frames', False, 8),
                              lambda chunk: str(chunk.value + 1))
            yield Lace(self, lacing - 1, size - 1)
        else:
            yield RawBytes(self, 'frame', size)
예제 #16
0
    def createFields(self):
        # Header
        yield PaddingBits(self,
                          "sync",
                          11,
                          "Synchronize bits (set to 1)",
                          pattern=1)
        yield Enum(Bits(self, "version", 2, "MPEG audio version"),
                   self.VERSION_NAME)
        yield Enum(Bits(self, "layer", 2, "MPEG audio layer"), self.LAYER_NAME)
        yield Bit(self, "crc16", "No CRC16 protection?")

        # Rates and padding
        yield Bits(self, "bit_rate", 4, "Bit rate")
        yield Bits(self, "sampling_rate", 2, "Sampling rate")
        yield Bit(self, "use_padding", "Stream field use padding?")
        yield Bit(self, "extension", "Extension")

        # Channel mode, mode extension, copyright, ...
        yield Enum(Bits(self, "channel_mode", 2, "Channel mode"),
                   self.CHANNEL_MODE_NAME)
        yield Bits(self, "mode_ext", 2, "Mode extension")
        yield Bit(self, "copyright", "Is copyrighted?")
        yield Bit(self, "original", "Is original?")
        yield Enum(Bits(self, "emphasis", 2, "Emphasis"), self.EMPHASIS_NAME)

        size = (self.size - self.current_size) // 8
        if size:
            yield RawBytes(self, "data", size)
예제 #17
0
 def createFields(self):
     if self.stream.readBits(self.absolute_address, 2, self.endian) == 1:
         # MPEG version 2
         yield Bits(self, "sync[]", 2)
         yield SCR(self, "scr")
         yield Bit(self, "sync[]")
         yield Bits(self, "scr_ext", 9)
         yield Bit(self, "sync[]")
         yield Bits(self, "mux_rate", 22)
         yield Bits(self, "sync[]", 2)
         yield PaddingBits(self, "reserved", 5, pattern=1)
         yield Bits(self, "stuffing_length", 3)
         count = self["stuffing_length"].value
         if count:
             yield PaddingBytes(self, "stuffing", count, pattern="\xff")
     else:
         # MPEG version 1
         yield Bits(self, "sync[]", 4)
         yield Bits(self, "scr_a", 3)
         yield Bit(self, "sync[]")
         yield Bits(self, "scr_b", 15)
         yield Bit(self, "sync[]")
         yield Bits(self, "scr_c", 15)
         yield Bits(self, "sync[]", 2)
         yield Bits(self, "mux_rate", 22)
         yield Bit(self, "sync[]")
예제 #18
0
 def createFields(self):
     yield Bits(self, "c", 3)
     yield Bit(self, "sync[]")  # =True
     yield Bits(self, "b", 15)
     yield Bit(self, "sync[]")  # =True
     yield Bits(self, "a", 15)
     yield Bit(self, "sync[]")  # =True
예제 #19
0
 def createFields(self):
     yield Bit(self, "negative")
     yield FloatExponent(self, "exponent", exponent_bits)
     if 64 <= mantissa_bits:
         yield Bit(self, "one")
         yield FloatMantissa(self, "mantissa", mantissa_bits - 1)
     else:
         yield FloatMantissa(self, "mantissa", mantissa_bits)
예제 #20
0
파일: elf.py 프로젝트: keithzg/SickGear
 def createFields(self):
     if self.root.endian == BIG_ENDIAN:
         yield NullBits(self, "padding[]", 29)
         for fld, desc in self.FLAGS:
             yield Bit(self, fld, "Segment is " + desc)
     else:
         for fld, desc in reversed(self.FLAGS):
             yield Bit(self, fld, "Segment is " + desc)
         yield NullBits(self, "padding[]", 29)
예제 #21
0
 def createFields(self):
     yield Bits(self, "scr_32_30", 3)
     yield Bit(self, "sync[]")  # =True
     yield Bits(self, "scr_29_15", 15)
     yield Bit(self, "sync[]")  # =True
     yield Bits(self, "scr_14_0", 15)
     yield Bit(self, "sync[]")  # =True
     yield Bits(self, "scr_ext", 9)
     yield Bit(self, "sync[]")  # =True
예제 #22
0
 def createFields(self):
     yield Bits(self, "sync", 14, "Sync code: 11111111111110")
     yield Bit(self, "reserved[]")
     yield Bit(self, "blocking_strategy")
     yield Bits(self, "block_size", 4)
     yield Enum(Bits(self, "sample_rate", 4), self.SAMPLE_RATES)
     yield Bits(self, "channel_assign", 4)
     yield Bits(self, "sample_size", 3)
     yield Bit(self, "reserved[]")
예제 #23
0
 def createFields(self):
     yield textHandler(Bits(self, "unused[]", 8, "Unused flag bits"),
                       hexadecimal)
     yield Bit(self, "has_added_size",
               "Additional field indicating additional size")
     yield Bit(
         self, "is_ignorable",
         "Old versions of RAR should ignore this block when copying data")
     yield Bits(self, "unused[]", 6)
예제 #24
0
    def createFields(self):
        yield UInt8(self, "version", "Version (0 or 1)")
        yield NullBits(self, "flags", 20)
        yield Bit(self, "is_in_poster")
        yield Bit(self, "is_in_preview",
                  "Is this track used when previewing the presentation?")
        yield Bit(self, "is_in_movie",
                  "Is this track used in the presentation?")
        yield Bit(self, "is_enabled", "Is this track enabled?")

        if self['version'].value == 0:
            # 32-bit version
            yield TimestampMac32(self, "creation_date",
                                 "Creation time of this track")
            yield TimestampMac32(self, "lastmod_date",
                                 "Last modification time of this track")
            yield UInt32(
                self, "track_id",
                "Unique nonzero identifier of this track within the presentation"
            )
            yield NullBytes(self, "reserved[]", 4)
            yield UInt32(self, "duration",
                         "Length of track, in movie time-units")
        elif self['version'].value == 1:
            # 64-bit version
            yield TimestampMac64(self, "creation_date",
                                 "Creation time of this track")
            yield TimestampMac64(self, "lastmod_date",
                                 "Last modification time of this track")
            yield UInt32(
                self, "track_id",
                "Unique nonzero identifier of this track within the presentation"
            )
            yield NullBytes(self, "reserved[]", 4)
            yield UInt64(self, "duration",
                         "Length of track, in movie time-units")
        yield NullBytes(self, "reserved[]", 8)
        yield Int16(
            self, "video_layer",
            "Middle layer is 0; lower numbers are closer to the viewer")
        yield Int16(self, "alternate_group",
                    "Group ID that this track belongs to (0=no group)")
        yield QTFloat16(self, "volume",
                        "Track relative audio volume (1.0 = full)")
        yield NullBytes(self, "reserved[]", 2)
        yield QTFloat32(self, "geom_a", "Width scale")
        yield QTFloat32(self, "geom_b", "Width rotate")
        yield QTFloat2_30(self, "geom_u", "Width angle")
        yield QTFloat32(self, "geom_c", "Height rotate")
        yield QTFloat32(self, "geom_d", "Height scale")
        yield QTFloat2_30(self, "geom_v", "Height angle")
        yield QTFloat32(self, "geom_x", "Position X")
        yield QTFloat32(self, "geom_y", "Position Y")
        yield QTFloat2_30(self, "geom_w", "Divider scale")
        yield QTFloat32(self, "frame_size_width")
        yield QTFloat32(self, "frame_size_height")
예제 #25
0
 def createFields(self):
     yield Bit(self, "drop_frame")
     yield Bits(self, "time_hh", 5)
     yield Bits(self, "time_mm", 6)
     yield PaddingBits(self, "time_pad[]", 1)
     yield Bits(self, "time_ss", 6)
     yield Bits(self, "time_ff", 6)
     yield Bit(self, "closed_group")
     yield Bit(self, "broken_group")
     yield PaddingBits(self, "pad[]", 5)
예제 #26
0
    def createFields(self):
        yield Bit(self, "has_private")
        yield Bit(self, "has_pack_lgth")
        yield Bit(self, "has_pack_seq")
        yield Bit(self, "has_pstd_buffer")
        yield Bits(self, "sync[]", 3)  # =7
        yield Bit(self, "has_extension2")

        if self["has_private"].value:
            yield RawBytes(self, "private", 16)

        if self["has_pack_lgth"].value:
            yield UInt8(self, "pack_lgth")

        if self["has_pack_seq"].value:
            yield Bit(self, "sync[]")  # =True
            yield Bits(self, "pack_seq_counter", 7)
            yield Bit(self, "sync[]")  # =True
            yield Bit(self, "mpeg12_id")
            yield Bits(self, "orig_stuffing_length", 6)

        if self["has_pstd_buffer"].value:
            yield Bits(self, "sync[]", 2)  # =1
            yield Enum(Bit(self, "pstd_buffer_scale"), {
                True: "128 bytes",
                False: "1024 bytes"
            })
            yield Bits(self, "pstd_size", 13)
예제 #27
0
 def createFields(self):
     yield Bit(self, "dir_prealloc", "Directory preallocation")
     yield Bit(self, "imagic_inodes", "imagic inodes - use unclear")
     yield Bit(self, "has_journal", "Has a journal")
     yield Bit(self, "ext_attr", "Supports extended attributes")
     yield Bit(self, "resize_inode", "Has reserved GDT blocks for FS expansion")
     yield Bit(self, "dir_index", "Has directory indices")
     yield Bit(self, "lazy_bg", "Lazy block groups (not used by Linux)")
     yield Bit(self, "exclude_inode", "Exclude inode (deprecated)")
     yield Bit(self, "exclude_bitmap", "Exclude bitmap (unused)")
     yield Bit(self, "sparse_super2", "Sparse Super Block v2")
     yield PaddingBits(self, "reserved[]", 22)
예제 #28
0
파일: png.py 프로젝트: markchipman/SickGear
def headerParse(parent):
    yield UInt32(parent, "width", "Width (pixels)")
    yield UInt32(parent, "height", "Height (pixels)")
    yield UInt8(parent, "bit_depth", "Bit depth")
    yield NullBits(parent, "reserved", 5)
    yield Bit(parent, "has_alpha", "Has alpha channel?")
    yield Bit(parent, "color", "Color used?")
    yield Bit(parent, "has_palette", "Has a color palette?")
    yield Enum(UInt8(parent, "compression", "Compression method"),
               COMPRESSION_NAME)
    yield UInt8(parent, "filter", "Filter method")
    yield UInt8(parent, "interlace", "Interlace method")
예제 #29
0
파일: flv.py 프로젝트: markchipman/SickGear
def parseAudio(parent, size):
    yield Enum(Bits(parent, "codec", 4, "Audio codec"), AUDIO_CODEC_NAME)
    yield Enum(Bits(parent, "sampling_rate", 2, "Sampling rate"),
               SAMPLING_RATE_TEXT)
    yield Bit(parent, "is_16bit", "16-bit or 8-bit per sample")
    yield Bit(parent, "is_stereo", "Stereo or mono channel")

    size -= 1
    if 0 < size:
        if parent["codec"].value == AUDIO_CODEC_MP3:
            yield Frame(parent, "music_data", size=size * 8)
        else:
            yield RawBytes(parent, "music_data", size)
예제 #30
0
def parseTry(parent, size):
    yield Bits(parent, "reserved", 5)
    catchInReg = Bit(parent, "catch_in_register")
    yield catchInReg
    yield Bit(parent, "finally")
    yield Bit(parent, "catch")
    yield UInt8(parent, "try_size")
    yield UInt8(parent, "catch_size")
    yield UInt8(parent, "finally_size")
    if catchInReg.value:
        yield CString(parent, "name")
    else:
        yield UInt8(parent, "register")