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")
def createFields(self): yield Bits(self, "nbits", 5) nbits = self["nbits"].value if not nbits: raise ParserError("SWF parser: Invalid RECT field size (0)") yield Bits(self, "xmin", nbits, "X minimum in twips") yield Bits(self, "xmax", nbits, "X maximum in twips") yield Bits(self, "ymin", nbits, "Y minimum in twips") yield Bits(self, "ymax", nbits, "Y maximum in twips") size = paddingSize(self.current_size, 8) if size: yield NullBits(self, "padding", size)
def createFields(self): yield UInt8(self, "version") yield NullBits(self, "flags", 24) yield RawBytes(self, "SystemID", 16) if self["version"].value > 0: yield UInt32(self, "KID_Count") for i in range(self["KID_Count"].value): yield RawBytes(self, "KID[]", 16) yield UInt32(self, "DataSize") yield RawBytes(self, "Data", self["DataSize"].value)
def createFields(self): if 3 <= self["../ver_major"].value: # ID3 v2.3 and 2.4 yield Enum(String(self, "tag", 4, "Tag", charset="ASCII", strip="\0"), ID3_Chunk.tag23_name) if 4 <= self["../ver_major"].value: yield ID3_Size(self, "size") # ID3 v2.4 else: yield UInt32(self, "size") # ID3 v2.3 yield Bit(self, "tag_alter", "Tag alter preservation") yield Bit(self, "file_alter", "Tag alter preservation") yield Bit(self, "rd_only", "Read only?") yield NullBits(self, "padding[]", 5) yield Bit(self, "compressed", "Frame is compressed?") yield Bit(self, "encrypted", "Frame is encrypted?") yield Bit(self, "group", "Grouping identity") yield NullBits(self, "padding[]", 5) size = self["size"].value is_compressed = self["compressed"].value else: # ID3 v2.2 yield Enum(String(self, "tag", 3, "Tag", charset="ASCII", strip="\0"), ID3_Chunk.tag22_name) yield UInt24(self, "size") size = self["size"].value - self.current_size // 8 + 6 is_compressed = False if size: cls = None if not(is_compressed): tag = self["tag"].value if tag in ID3_Chunk.handler: cls = ID3_Chunk.handler[tag] elif tag[0] == "T": cls = ID3_StringCharset if cls: yield cls(self, "content", "Content", size=size * 8) else: yield RawBytes(self, "content", size, "Raw data content")
def createFields(self): yield UInt8(self, "version") yield NullBits(self, "flags", 24) yield UInt32(self, "count", description="Total entries in sample time table") for i in range(self['count'].value): yield UInt32(self, "sample_count[]", "Number of consecutive samples with this offset") yield UInt32( self, "sample_offset[]", "Difference between decode time and composition time of this sample, in time-units" )
def parseGraphicControl(parent): yield UInt8(parent, "size", "Block size (4)") yield Bit(parent, "has_transp", "Has transparency") yield Bit(parent, "user_input", "User input") yield Enum(Bits(parent, "disposal_method", 3), DISPOSAL_METHOD) yield NullBits(parent, "reserved[]", 3) if parent["size"].value != 4: raise ParserError("Invalid graphic control size") yield displayHandler(UInt16(parent, "delay", "Delay time in millisecond"), humanDuration) yield UInt8(parent, "transp", "Transparent color index") yield NullBytes(parent, "terminator", 1, "Terminator (0)")
def createFields(self): if self.stream.readBytes(self.absolute_address, 5) != b"Adobe": yield RawBytes(self, "raw", self.size // 8, "Raw data") return yield String(self, "adobe", 5, "\"Adobe\" string", charset="ASCII") yield UInt16(self, "version", "DCT encoder version") yield Enum(Bit(self, "flag00"), { False: "Chop down or subsampling", True: "Blend" }) yield NullBits(self, "flags0_reserved", 15) yield NullBytes(self, "flags1", 2) yield Enum( UInt8(self, "color_transform", "Colorspace transformation code"), self.COLORSPACE_TRANSFORMATION)
def parseSoundHeader(parent, size): yield Bit(parent, "playback_is_stereo") yield Bit(parent, "playback_is_16bit") yield textHandler(Bits(parent, "playback_rate", 2), bit2hertz) yield NullBits(parent, "reserved", 4) yield Bit(parent, "sound_is_stereo") yield Bit(parent, "sound_is_16bit") yield textHandler(Bits(parent, "sound_rate", 2), bit2hertz) yield Enum(Bits(parent, "codec", 4), SOUND_CODEC) yield UInt16(parent, "sample_count") if parent["codec"].value == 2: yield UInt16(parent, "latency_seek")
def createFields(self): yield UInt8(self, "version", "Version (0 or 1)") yield NullBits(self, "flags", 24) yield UInt32(self, "count") version = self['version'].value if version == 0: UInt, Int = UInt32, Int32 elif version == 1: UInt, Int = UInt64, Int64 else: raise ParserError("elst version %d not supported" % version) for i in xrange(self['count'].value): yield UInt(self, "duration[]", "Duration of this edit segment") yield Int(self, "time[]", "Starting time of this edit segment within the media (-1 = empty edit)") yield QTFloat32(self, "play_speed[]", "Playback rate (0 = dwell edit, 1 = normal playback)")
def parseAnimationHeader(self): yield UInt32(self, "hdr_size", "Size of header (36 bytes)") if self["hdr_size"].value != 36: self.warning("Animation header with unknown size (%s)" % self["size"].value) yield UInt32(self, "nb_frame", "Number of unique Icons in this cursor") yield UInt32(self, "nb_step", "Number of Blits before the animation cycles") yield UInt32(self, "cx") yield UInt32(self, "cy") yield UInt32(self, "bit_count") yield UInt32(self, "planes") yield UInt32( self, "jiffie_rate", "Default Jiffies (1/60th of a second) if rate chunk not present") yield Bit(self, "is_icon") yield NullBits(self, "padding", 31)
def createFields(self): yield UInt8(self, "version", "Version (0 or 1)") yield NullBits(self, "flags", 24) if self['version'].value == 0: # 32-bit version yield TimestampMac32(self, "creation_date", "Creation time of this media") yield TimestampMac32(self, "lastmod_date", "Last modification time of this media") yield UInt32(self, "time_scale", "Number of time-units per second") yield UInt32(self, "duration", "Length of media, in time-units") elif self['version'].value == 1: # 64-bit version yield TimestampMac64(self, "creation_date", "Creation time of this media") yield TimestampMac64(self, "lastmod_date", "Last modification time of this media") yield UInt32(self, "time_scale", "Number of time-units per second") yield UInt64(self, "duration", "Length of media, in time-units") yield LanguageCode(self, "language") yield Int16(self, "quality")
def createFields(self): yield UInt8(self, "version", "Version (0 or 1)") yield NullBits(self, "flags", 24) if self['version'].value == 0: # 32-bit version yield TimestampMac32(self, "creation_date", "Creation time of this presentation") yield TimestampMac32( self, "lastmod_date", "Last modification time of this presentation") yield UInt32(self, "time_scale", "Number of time-units per second") yield UInt32(self, "duration", "Length of presentation, in time-units") elif self['version'].value == 1: # 64-bit version yield TimestampMac64(self, "creation_date", "Creation time of this presentation") yield TimestampMac64( self, "lastmod_date", "Last modification time of this presentation") yield UInt32(self, "time_scale", "Number of time-units per second") yield UInt64(self, "duration", "Length of presentation, in time-units") yield QTFloat32(self, "play_speed", "Preferred playback speed (1.0 = normal)") yield QTFloat16(self, "volume", "Preferred playback volume (1.0 = full)") yield NullBytes(self, "reserved[]", 10) 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 UInt32(self, "preview_start") yield UInt32(self, "preview_length") yield UInt32(self, "still_poster") yield UInt32(self, "sel_start") yield UInt32(self, "sel_length") yield UInt32(self, "current_time") yield UInt32(self, "next_track_ID", "Value to use as the track ID for the next track added")
def parseStartSound(parent, size): yield UInt16(parent, "sound_id") yield Bit(parent, "has_in_point") yield Bit(parent, "has_out_point") yield Bit(parent, "has_loops") yield Bit(parent, "has_envelope") yield Bit(parent, "no_multiple") yield Bit(parent, "stop_playback") yield NullBits(parent, "reserved", 2) if parent["has_in_point"].value: yield UInt32(parent, "in_point") if parent["has_out_point"].value: yield UInt32(parent, "out_point") if parent["has_loops"].value: yield UInt16(parent, "loop_count") if parent["has_envelope"].value: yield SoundEnvelope(parent, "envelope")
def createFields(self): yield String(self, 'capture_pattern', 4, charset="ASCII") if self['capture_pattern'].value != "OggS": self.warning( 'Invalid signature. An Ogg page must start with "OggS".') yield UInt8(self, 'stream_structure_version') yield Bit(self, 'continued_packet') yield Bit(self, 'first_page') yield Bit(self, 'last_page') yield NullBits(self, 'unused', 5) yield UInt64(self, 'abs_granule_pos') yield textHandler(UInt32(self, 'serial'), hexadecimal) yield UInt32(self, 'page') yield textHandler(UInt32(self, 'checksum'), hexadecimal) yield UInt8(self, 'lacing_size') if self.lacing_size: yield Lacing(self, "lacing", size=self.lacing_size * 8) yield Segments(self, "segments", size=self._size - self._current_size)
def createFields(self): yield String(self, "name", 8, charset="ASCII", strip="\0 ") yield filesizeHandler(UInt32(self, "mem_size", "Size in memory")) yield textHandler(UInt32(self, "rva", "RVA (location) in memory"), hexadecimal) yield filesizeHandler( UInt32(self, "phys_size", "Physical size (on disk)")) yield filesizeHandler( UInt32(self, "phys_off", "Physical location (on disk)")) yield PaddingBytes(self, "reserved", 12) # 0x0000000# yield NullBits(self, "reserved[]", 4) # 0x000000#0 yield NullBits(self, "reserved[]", 1) yield Bit(self, "has_code", "Contains code") yield Bit(self, "has_init_data", "Contains initialized data") yield Bit(self, "has_uninit_data", "Contains uninitialized data") # 0x00000#00 yield NullBits(self, "reserved[]", 1) yield Bit(self, "has_comment", "Contains comments?") yield NullBits(self, "reserved[]", 1) yield Bit(self, "remove", "Contents will not become part of image") # 0x0000#000 yield Bit(self, "has_comdata", "Contains comdat?") yield NullBits(self, "reserved[]", 1) yield Bit( self, "no_defer_spec_exc", "Reset speculative exceptions handling bits in the TLB entries") yield Bit(self, "gp_rel", "Content can be accessed relative to GP") # 0x000#0000 yield NullBits(self, "reserved[]", 4) # 0x00#00000 yield NullBits(self, "reserved[]", 4) # 0x0#000000 yield Bit(self, "ext_reloc", "Contains extended relocations?") yield Bit(self, "discarded", "Can be discarded?") yield Bit(self, "is_not_cached", "Is not cachable?") yield Bit(self, "is_not_paged", "Is not pageable?") # 0x#0000000 yield Bit(self, "is_shareable", "Is shareable?") yield Bit(self, "is_executable", "Is executable?") yield Bit(self, "is_readable", "Is readable?") yield Bit(self, "is_writable", "Is writable?")
def createFields(self): yield Bit(self, "continued_from", "File continued from previous volume") yield Bit(self, "continued_in", "File continued in next volume") yield Bit(self, "is_encrypted", "File encrypted with password") yield Bit(self, "has_comment", "File comment present") yield Bit(self, "is_solid", "Information from previous files is used (solid flag)") # The 3 following lines are what blocks more staticity yield Enum(Bits(self, "dictionary_size", 3, "Dictionary size"), DICTIONARY_SIZE) # for bit in common_flags(self): # yield bit yield Bit(self, "is_large", "file64 operations needed") yield Bit(self, "is_unicode", "Filename also encoded using Unicode") yield Bit(self, "has_salt", "Has salt for encryption") yield Bit(self, "uses_file_version", "File versioning is used") yield Bit(self, "has_ext_time", "Extra time ??") yield NullBits(self, "reserved", 2, "Reserved for 'internal use'") yield Bit(self, "has_ext_flags", "Extra flag ??")
def createFields(self): self.osconfig = self.parent.osconfig if True: yield Enum(Bits(self, "type", 12), self.TYPE_NAME) yield Bit(self, "is_vector") yield NullBits(self, "padding", 32 - 12 - 1) else: yield Enum(Bits(self, "type", 32), self.TYPE_NAME) tag = self["type"].value kw = {} try: handler = self.TYPE_INFO[tag][1] if handler in (self.WidePascalString32, PascalString32): cur = self while not hasattr(cur, 'osconfig'): cur = cur.parent if cur is None: raise LookupError('Cannot find osconfig') osconfig = cur.osconfig if tag == self.TYPE_LPSTR: kw["charset"] = osconfig.charset else: kw["charset"] = osconfig.utf16 elif handler == TimestampWin64: if self.description == "TotalEditingTime": handler = TimedeltaWin64 except LookupError: handler = None if not handler: self.warning("OLE2: Unable to parse property of type %s" % self["type"].display) # raise ParserError( elif self["is_vector"].value: yield UInt32(self, "count") for index in range(self["count"].value): yield handler(self, "item[]", **kw) else: yield handler(self, "value", **kw) self.createValue = lambda: self["value"].value
def createFields(self): yield Enum(UInt8(self, "typecode"), TYPECODE_NAMES) yield PascalString16(self, "className", charset="UTF-8") yield Int64(self, "serialVersionUID") self.root.newHandle(self) yield NullBits(self, "classDescFlags_reserved", 3) yield Bit(self, "classDescFlags_enum", "Is the class an Enum?") yield Bit( self, "classDescFlags_block_data", "Was the externalizable's block data written using stream version 2?" ) yield Bit(self, "classDescFlags_externalizable", "Does the class implement java.io.Externalizable?") yield Bit(self, "classDescFlags_serializable", "Does the class implement java.io.Serializable?") yield Bit(self, "classDescFlags_write_method", "Does the class have a writeObject method?") yield Int16(self, "fieldDesc_count") for i in range(self['fieldDesc_count'].value): yield FieldDesc(self, "fieldDesc[]") yield ClassAnnotation(self, "classAnnotation") yield SerializedContent(self, "superClassDesc")
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")
def createFields(self): yield UInt8(self, "version") yield NullBits(self, "flags", 24) yield UInt32(self, "count", description="Number of sync samples") for i in xrange(self['count'].value): yield UInt32(self, "sample_number[]")
def createFields(self): yield UInt8(self, "version") yield NullBits(self, "flags", 24) yield UInt32(self, "count", description="Total entries in table") for i in xrange(self['count'].value): yield SampleEntry(self, "sample_entry[]")
def createFields(self): yield UInt8(self, "version", "Version") yield NullBits(self, "flags", 24) yield Descriptor(self, "ES", restrict=ESDescriptor)
def createFields(self): yield UInt8(self, "version") yield NullBits(self, "flags", 24) yield UInt32(self, "count", description="Total entries in offset table") for i in xrange(self['count'].value): yield UInt64(self, "chunk_offset[]")
def createFields(self): yield UInt8(self, "version") yield NullBits(self, "flags", 24) yield UInt32(self, "count") for i in xrange(self['count'].value): yield Atom(self, "key[]")
def createFields(self): yield UInt8(self, "version", "Version") yield NullBits(self, "flags", 24) yield UInt32(self, "size")
def createFields(self): yield UInt8(self, "version", "Version") yield NullBits(self, "flags", 24) yield UInt32(self, "sequence_number")
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): yield UInt8(self, "version", "Version") yield NullBits(self, "flags", 23) yield Bit(self, "is_same_file", "Is the reference to this file?") if not self['is_same_file'].value: yield CString(self, "location")
def createFields(self): yield UInt8(self, "version", "Version") yield NullBits(self, "flags", 24) yield QTFloat16(self, "balance") yield UInt16(self, "reserved[]")
def createFields(self): yield Bit(self, "has_previous") yield Bit(self, "has_next") yield Bit(self, "has_reserved") yield NullBits(self, "padding", 13)