def createRawField(parent, size, name="raw[]", description=None): if size <= 0: raise FieldError("Unable to create raw field of %s bits" % size) if (size % 8) == 0: return RawBytes(parent, name, size // 8, description) else: return RawBits(parent, name, size, description)
def createFields(self): yield UInt8(self, "length") yield Bit(self, "discontinuity_indicator") yield Bit(self, "random_access_indicator") yield Bit(self, "es_prio_indicator") yield Bit(self, "has_pcr") yield Bit(self, "has_opcr") yield Bit(self, "has_splice_point") yield Bit(self, "private_data") yield Bit(self, "has_extension") if self['has_pcr'].value: yield Bits(self, "pcr_base", 33) yield Bits(self, "pcr_ext", 9) if self['has_opcr'].value: yield Bits(self, "opcr_base", 33) yield Bits(self, "opcr_ext", 9) if self['has_splice_point'].value: yield Bits(self, "splice_countdown", 8) stuff_len = ((self['length'].value + 1) * 8) - self.current_size if self['length'].value and stuff_len: yield RawBits(self, 'stuffing', stuff_len)
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)
def createFields(self): yield Enum(Bits(self, "ext_type", 4), self.EXT_TYPE) ext_type = self['ext_type'].value if ext_type == 1: # Sequence extension yield Bits(self, 'profile_and_level', 8) yield Bit(self, 'progressive_sequence') yield Bits(self, 'chroma_format', 2) yield Bits(self, 'horiz_size_ext', 2) yield Bits(self, 'vert_size_ext', 2) yield Bits(self, 'bit_rate_ext', 12) yield Bits(self, 'pad[]', 1) yield Bits(self, 'vbv_buffer_size_ext', 8) yield Bit(self, 'low_delay') yield Bits(self, 'frame_rate_ext_n', 2) yield Bits(self, 'frame_rate_ext_d', 5) elif ext_type == 2: # Sequence Display extension yield Bits(self, 'video_format', 3) yield Bit(self, 'color_desc_present') if self['color_desc_present'].value: yield UInt8(self, 'color_primaries') yield UInt8(self, 'transfer_characteristics') yield UInt8(self, 'matrix_coeffs') yield Bits(self, 'display_horiz_size', 14) yield Bits(self, 'pad[]', 1) yield Bits(self, 'display_vert_size', 14) yield NullBits(self, 'pad[]', 3) elif ext_type == 8: yield Bits(self, 'f_code[0][0]', 4, description="forward horizontal") yield Bits(self, 'f_code[0][1]', 4, description="forward vertical") yield Bits(self, 'f_code[1][0]', 4, description="backward horizontal") yield Bits(self, 'f_code[1][1]', 4, description="backward vertical") yield Bits(self, 'intra_dc_precision', 2) yield Bits(self, 'picture_structure', 2) yield Bit(self, 'top_field_first') yield Bit(self, 'frame_pred_frame_dct') yield Bit(self, 'concealment_motion_vectors') yield Bit(self, 'q_scale_type') yield Bit(self, 'intra_vlc_format') yield Bit(self, 'alternate_scan') yield Bit(self, 'repeat_first_field') yield Bit(self, 'chroma_420_type') yield Bit(self, 'progressive_frame') yield Bit(self, 'composite_display') if self['composite_display'].value: yield Bit(self, 'v_axis') yield Bits(self, 'field_sequence', 3) yield Bit(self, 'sub_carrier') yield Bits(self, 'burst_amplitude', 7) yield Bits(self, 'sub_carrier_phase', 8) yield NullBits(self, 'pad[]', 2) else: yield NullBits(self, 'pad[]', 6) else: yield RawBits(self, "raw[]", 4)
def createFields(self): field_thunks = ( lambda: Bit(self, "is_writable", "Section contains writable data?" ), lambda: Bit(self, "is_alloc", "Section occupies memory?"), lambda: Bit(self, "is_exec", "Section contains executable instructions?"), lambda: NullBits(self, "reserved[]", 1), lambda: Bit(self, "is_merged", "Section might be merged to eliminate duplication?"), lambda: Bit(self, "is_strings", "Section contains nul terminated strings?"), lambda: Bit( self, "is_info_link", "sh_info field of this section header holds section header table index?" ), lambda: Bit(self, "preserve_link_order", "Section requires special ordering for linker?"), lambda: Bit(self, "os_nonconforming", "Section rqeuires OS-specific processing?"), lambda: Bit(self, "is_group", "Section is a member of a section group?"), lambda: Bit(self, "is_tls", "Section contains TLS data?"), lambda: Bit(self, "is_compressed", "Section contains compressed data?"), lambda: NullBits(self, "reserved[]", 8), lambda: RawBits(self, "os_specific", 8, "OS specific flags"), lambda: RawBits(self, "processor_specific", 4, "Processor specific flags"), ) if self.root.endian == BIG_ENDIAN: if self.root.is64bit: yield RawBits(self, "reserved[]", 32) for t in reversed(field_thunks): yield t() else: for t in field_thunks: yield t() if self.root.is64bit: yield RawBits(self, "reserved[]", 32)
def parseSMPTEOffset(parser, size): yield RawBits(parser, "padding", 1) yield Enum(Bits(parser, "frame_rate", 2), { 0: "24 fps", 1: "25 fps", 2: "30 fps (drop frame)", 3: "30 fps" }) yield Bits(parser, "hour", 5) yield UInt8(parser, "minute") yield UInt8(parser, "second") yield UInt8(parser, "frame") yield UInt8(parser, "subframe", "100 subframes per frame")
def parseFileProperties(self): yield UInt32(self, "max_bit_rate", "Maximum bit rate") yield UInt32(self, "avg_bit_rate", "Average bit rate") yield UInt32(self, "max_pkt_size", "Size of largest data packet") yield UInt32(self, "avg_pkt_size", "Size of average data packet") yield UInt32(self, "num_pkts", "Number of data packets") yield UInt32(self, "duration", "File duration in milliseconds") yield UInt32(self, "preroll", "Suggested preroll in milliseconds") yield textHandler( UInt32(self, "index_offset", "Absolute offset of first index chunk"), hexadecimal) yield textHandler( UInt32(self, "data_offset", "Absolute offset of first data chunk"), hexadecimal) yield UInt16(self, "stream_count", "Number of streams in the file") yield RawBits(self, "reserved", 13) yield Bit(self, "is_live", "Whether file is a live broadcast") yield Bit(self, "is_perfect_play", "Whether PerfectPlay can be used") yield Bit(self, "is_saveable", "Whether file can be saved")
def __init__(self, parent, name): RawBits.__init__(self, parent, name, 8)
def __init__(self, parent, name, description=None): RawBits.__init__(self, parent, name, 1, description=description)
def createFields(self): yield Bits(self, "quantizer_scale", 5) start = self.absolute_address + self.current_size + 3 pos = self.stream.searchBytes('\0\0\1', start, start + 1024 * 1024 * 8) # seek forward by at most 1MB if pos is None: pos = self.root.size yield RawBits(self, "data", pos - start + 3)