Esempio n. 1
0
    def createFields(self):
        yield Enum(textHandler(UInt16(self, "tag", "Tag"), hexadecimal), self.TAG_NAME)
        yield Enum(textHandler(UInt16(self, "type", "Type"), hexadecimal), self.TYPE_NAME)
        yield UInt32(self, "count", "Count")
        if self["type"].value not in (self.TYPE_BYTE, self.TYPE_UNDEFINED) \
        and  MAX_COUNT < self["count"].value:
            raise ParserError("EXIF: Invalid count value (%s)" % self["count"].value)
        value_size, array_size = self.getSizes()

        # Get offset/value
        if not value_size:
            yield NullBytes(self, "padding", 4)
        elif value_size <= 32:
            if 1 < array_size:
                name = "value[]"
            else:
                name = "value"
            kw = {}
            cls = self.value_cls
            if cls is String:
                args = (self, name, value_size/8, "Value")
                kw["strip"] = " \0"
                kw["charset"] = "ISO-8859-1"
            elif cls is Bytes:
                args = (self, name, value_size/8, "Value")
            else:
                args = (self, name, "Value")
            for index in xrange(array_size):
                yield cls(*args, **kw)

            size = array_size * value_size
            if size < 32:
                yield NullBytes(self, "padding", (32-size)//8)
        else:
            yield UInt32(self, "offset", "Value offset")
Esempio n. 2
0
    def createFields(self):
        yield String(self, "magic", 4, "Magic (MSCF)", charset="ASCII")
        yield textHandler(UInt32(self, "hdr_checksum", "Header checksum (0 if not used)"), hexadecimal)
        yield filesizeHandler(UInt32(self, "filesize", "Cabinet file size"))
        yield textHandler(UInt32(self, "fld_checksum", "Folders checksum (0 if not used)"), hexadecimal)
        yield UInt32(self, "off_file", "Offset of first file")
        yield textHandler(UInt32(self, "files_checksum", "Files checksum (0 if not used)"), hexadecimal)
        yield textHandler(UInt16(self, "cab_version", "Cabinet version"), hexadecimal)
        yield UInt16(self, "nb_folder", "Number of folders")
        yield UInt16(self, "nb_files", "Number of files")
        yield Flags(self, "flags")
        yield UInt16(self, "setid")
        yield UInt16(self, "number", "Zero-based cabinet number")

        # --- TODO: Support flags
        if self["flags/has_reserved"].value:
            yield Reserved(self, "reserved")
        #(3) Previous cabinet name, if CAB_HEADER.flags & CAB_FLAG_HASPREV
        #(4) Previous disk name, if CAB_HEADER.flags & CAB_FLAG_HASPREV
        #(5) Next cabinet name, if CAB_HEADER.flags & CAB_FLAG_HASNEXT
        #(6) Next disk name, if CAB_HEADER.flags & CAB_FLAG_HASNEXT
        # ----

        for index in xrange(self["nb_folder"].value):
            yield Folder(self, "folder[]")
        for index in xrange(self["nb_files"].value):
            yield File(self, "file[]")

        end = self.seekBit(self.size, "endraw")
        if end:
            yield end
Esempio n. 3
0
    def createFields(self):
        while self.stream.readBytes(self.absolute_address+self.current_size, 1) == '%':
            size = getLineEnd(self, 4)
            if size == 2:
                yield textHandler(UInt16(self, "crc32"), hexadecimal)
            elif size == 4:
                yield textHandler(UInt32(self, "crc32"), hexadecimal)
            elif self.stream.readBytes(self.absolute_address+self.current_size, size).isalpha():
                yield String(self, "comment[]", size)
            else:
                RawBytes(self, "unknown_data[]", size)
            yield LineEnd(self, "line_end[]")

        #abs_offset = self.current_size//8
        # TODO: yield objects that read offsets and deduce size from
        # "/cross_ref_table/sub_section[]/entries/item[]"
        offsets = []
        for subsection in self.array("/cross_ref_table/sub_section"):
            for obj in subsection.array("entries/item"):
                if "byte_offset" in obj:
                    # Could be inserted already sorted
                    offsets.append(obj["byte_offset"].value)

        offsets.append(self["/cross_ref_table"].absolute_address//8)
        offsets.sort()
        for index in xrange(len(offsets)-1):
            yield Catalog(self, "object[]", size=offsets[index+1]-offsets[index])
Esempio n. 4
0
 def createFields(self):
     yield String(self, "name", 22, strip='\0')
     yield UInt16(self, "sample_count")
     yield textHandler(UInt8(self, "fine_tune"), getFineTune)
     yield textHandler(UInt8(self, "volume"), getVolume)
     yield UInt16(self, "loop_start", "Loop start offset in samples")
     yield UInt16(self, "loop_len", "Loop length in samples")
Esempio n. 5
0
    def createFields(self):
        # Version 2 (12 bytes)
        yield UInt32(self, "header_size", "Header size")
        yield UInt32(self, "width", "Width (pixels)")
        yield UInt32(self, "height", "Height (pixels)")
        yield UInt16(self, "nb_plan", "Number of plan (=1)")
        yield UInt16(self, "bpp", "Bits per pixel") # may be zero for PNG/JPEG picture

        # Version 3 (40 bytes)
        if self["header_size"].value < 40:
            return
        yield Enum(UInt32(self, "compression", "Compression method"), BmpFile.COMPRESSION_NAME)
        yield UInt32(self, "image_size", "Image size (bytes)")
        yield UInt32(self, "horizontal_dpi", "Horizontal DPI")
        yield UInt32(self, "vertical_dpi", "Vertical DPI")
        yield UInt32(self, "used_colors", "Number of color used")
        yield UInt32(self, "important_color", "Number of import colors")

        # Version 4 (108 bytes)
        if self["header_size"].value < 108:
            return
        yield textHandler(UInt32(self, "red_mask"), hexadecimal)
        yield textHandler(UInt32(self, "green_mask"), hexadecimal)
        yield textHandler(UInt32(self, "blue_mask"), hexadecimal)
        yield textHandler(UInt32(self, "alpha_mask"), hexadecimal)
        yield Enum(UInt32(self, "color_space"), self.color_space_name)
        yield CIEXYZ(self, "red_primary")
        yield CIEXYZ(self, "green_primary")
        yield CIEXYZ(self, "blue_primary")
        yield UInt32(self, "gamma_red")
        yield UInt32(self, "gamma_green")
        yield UInt32(self, "gamma_blue")
Esempio n. 6
0
    def createFields(self):
        # Version 2 (12 bytes)
        yield UInt32(self, "header_size", "Header size")
        yield UInt32(self, "width", "Width (pixels)")
        yield UInt32(self, "height", "Height (pixels)")
        yield UInt16(self, "nb_plan", "Number of plan (=1)")
        yield UInt16(self, "bpp",
                     "Bits per pixel")  # may be zero for PNG/JPEG picture

        # Version 3 (40 bytes)
        if self["header_size"].value < 40:
            return
        yield Enum(UInt32(self, "compression", "Compression method"),
                   BmpFile.COMPRESSION_NAME)
        yield UInt32(self, "image_size", "Image size (bytes)")
        yield UInt32(self, "horizontal_dpi", "Horizontal DPI")
        yield UInt32(self, "vertical_dpi", "Vertical DPI")
        yield UInt32(self, "used_colors", "Number of color used")
        yield UInt32(self, "important_color", "Number of import colors")

        # Version 4 (108 bytes)
        if self["header_size"].value < 108:
            return
        yield textHandler(UInt32(self, "red_mask"), hexadecimal)
        yield textHandler(UInt32(self, "green_mask"), hexadecimal)
        yield textHandler(UInt32(self, "blue_mask"), hexadecimal)
        yield textHandler(UInt32(self, "alpha_mask"), hexadecimal)
        yield Enum(UInt32(self, "color_space"), self.color_space_name)
        yield CIEXYZ(self, "red_primary")
        yield CIEXYZ(self, "green_primary")
        yield CIEXYZ(self, "blue_primary")
        yield UInt32(self, "gamma_red")
        yield UInt32(self, "gamma_green")
        yield UInt32(self, "gamma_blue")
Esempio n. 7
0
 def createFields(self):
     # This stupid shit gets the LSB, not the MSB...
     self.info(
         "Note info: 0x%02X" %
         self.stream.readBits(self.absolute_address, 8, LITTLE_ENDIAN))
     yield RealBit(self, "is_extended")
     if self["is_extended"].value:
         info = NoteInfo(self, "info")
         yield info
         if info["has_note"].value:
             yield Enum(UInt8(self, "note"), NOTE_NAME)
         if info["has_instrument"].value:
             yield UInt8(self, "instrument")
         if info["has_volume"].value:
             yield textHandler(UInt8(self, "volume"), parseVolume)
         if info["has_type"].value:
             yield Effect(self, "effect_type")
         if info["has_parameter"].value:
             yield textHandler(UInt8(self, "effect_parameter"), hexadecimal)
     else:
         yield Enum(Bits(self, "note", 7), NOTE_NAME)
         yield UInt8(self, "instrument")
         yield textHandler(UInt8(self, "volume"), parseVolume)
         yield Effect(self, "effect_type")
         yield textHandler(UInt8(self, "effect_parameter"), hexadecimal)
Esempio n. 8
0
    def createFields(self):
        yield Bytes(self, "jump", 3, "Intel x86 jump instruction")
        yield String(self, "name", 8)
        yield BiosParameterBlock(self, "bios", "BIOS parameters")

        yield textHandler(UInt8(self, "physical_drive", "(0x80)"), hexadecimal)
        yield NullBytes(self, "current_head", 1)
        yield textHandler(
            UInt8(self, "ext_boot_sig", "Extended boot signature (0x80)"),
            hexadecimal)
        yield NullBytes(self, "unused", 1)

        yield UInt64(self, "nb_sectors")
        yield UInt64(self, "mft_cluster", "Cluster location of MFT data")
        yield UInt64(self, "mftmirr_cluster",
                     "Cluster location of copy of MFT")
        yield UInt8(self, "cluster_per_mft", "MFT record size in clusters")
        yield NullBytes(self, "reserved[]", 3)
        yield UInt8(self, "cluster_per_index", "Index block size in clusters")
        yield NullBytes(self, "reserved[]", 3)
        yield textHandler(UInt64(self, "serial_number"), hexadecimal)
        yield textHandler(UInt32(self, "checksum", "Boot sector checksum"),
                          hexadecimal)
        yield Bytes(self, "boot_code", 426)
        yield Bytes(self, "mbr_magic", 2,
                    r"Master boot record magic number (\x55\xAA)")
Esempio n. 9
0
 def createFields(self):
     yield textHandler(UInt32(self, "signature", "Placeable Metafiles signature (0x9AC6CDD7)"), hexadecimal)
     yield UInt16(self, "handle")
     yield RECT16(self, "rect")
     yield UInt16(self, "inch")
     yield NullBytes(self, "reserved", 4)
     yield textHandler(UInt16(self, "checksum"), hexadecimal)
Esempio n. 10
0
def specialHeader(s, is_file):
    yield filesizeHandler(UInt32(s, "compressed_size", "Compressed size (bytes)"))
    yield filesizeHandler(UInt32(s, "uncompressed_size", "Uncompressed size (bytes)"))
    yield Enum(UInt8(s, "host_os", "Operating system used for archiving"), OS_NAME)
    yield textHandler(UInt32(s, "crc32", "File CRC32"), hexadecimal)
    yield TimeDateMSDOS32(s, "ftime", "Date and time (MS DOS format)")
    yield textHandler(UInt8(s, "version", "RAR version needed to extract file"), formatRARVersion)
    yield Enum(UInt8(s, "method", "Packing method"), COMPRESSION_NAME)
    yield filesizeHandler(UInt16(s, "filename_length", "File name size"))
    if s["host_os"].value in (OS_MSDOS, OS_WIN32):
        yield MSDOSFileAttr32(s, "file_attr", "File attributes")
    else:
        yield textHandler(UInt32(s, "file_attr", "File attributes"), hexadecimal)

    # Start additional field from unrar
    if s["flags/is_large"].value:
        yield filesizeHandler(UInt64(s, "large_size", "Extended 64bits filesize"))

    # End additional field
    size = s["filename_length"].value
    if size > 0:
        if s["flags/is_unicode"].value:
            charset = "UTF-8"
        else:
            charset = "ISO-8859-15"
        yield String(s, "filename", size, "Filename", charset=charset)
    # Start additional fields from unrar - file only
    if is_file:
        if s["flags/has_salt"].value:
            yield textHandler(UInt8(s, "salt", "Salt"), hexadecimal)
        if s["flags/has_ext_time"].value:
            yield ExtTime(s, "extra_time", "Extra time info")
Esempio n. 11
0
    def createFields(self):
        while self.stream.readBytes(self.absolute_address + self.current_size,
                                    1) == '%':
            size = getLineEnd(self, 4)
            if size == 2:
                yield textHandler(UInt16(self, "crc32"), hexadecimal)
            elif size == 4:
                yield textHandler(UInt32(self, "crc32"), hexadecimal)
            elif self.stream.readBytes(
                    self.absolute_address + self.current_size, size).isalpha():
                yield String(self, "comment[]", size)
            else:
                RawBytes(self, "unknown_data[]", size)
            yield LineEnd(self, "line_end[]")

        #abs_offset = self.current_size//8
        # TODO: yield objects that read offsets and deduce size from
        # "/cross_ref_table/sub_section[]/entries/item[]"
        offsets = []
        for subsection in self.array("/cross_ref_table/sub_section"):
            for obj in subsection.array("entries/item"):
                if "byte_offset" in obj:
                    # Could be inserted already sorted
                    offsets.append(obj["byte_offset"].value)

        offsets.append(self["/cross_ref_table"].absolute_address // 8)
        offsets.sort()
        for index in xrange(len(offsets) - 1):
            yield Catalog(self,
                          "object[]",
                          size=offsets[index + 1] - offsets[index])
Esempio n. 12
0
 def createFields(self):
     yield Integer(self, "time", "Delta time in ticks")
     yield Enum(textHandler(UInt8(self, "command"), hexadecimal), self.COMMAND_DESC)
     command = self["command"].value
     if command == 0xFF:
         yield Enum(textHandler(UInt8(self, "meta_command"), hexadecimal), self.META_COMMAND_DESC)
         yield UInt8(self, "data_len")
         size = self["data_len"].value
         if size:
             command = self["meta_command"].value
             if command in self.META_COMMAND_PARSER:
                 parser = self.META_COMMAND_PARSER[command]
             else:
                 parser = None
             if parser:
                 for field in parser(self, size):
                     yield field
             else:
                 yield RawBytes(self, "data", size)
     else:
         if command not in self.COMMAND_PARSER:
             raise ParserError("Unknown command: %s" % self["command"].display)
         parser = self.COMMAND_PARSER[command]
         for field in parser(self):
             yield field
Esempio n. 13
0
 def createFields(self):
     yield textHandler(UInt32(self, "plugin_id1"), hexadecimal)
     yield textHandler(UInt32(self, "plugin_id2"), hexadecimal)
     yield UInt32(self, "input_routing")
     yield UInt32(self, "output_routing")
     yield GenericVector(self, "routing_info", 4, UInt32, "reserved")
     yield String(self, "name", 32, strip='\0')
     yield String(self, "dll_name", 64, desc="Original DLL name", strip='\0')
Esempio n. 14
0
 def createFields(self):
     yield textHandler(
         UInt32(self, "signature",
                "Placeable Metafiles signature (0x9AC6CDD7)"), hexadecimal)
     yield UInt16(self, "handle")
     yield RECT16(self, "rect")
     yield UInt16(self, "inch")
     yield NullBytes(self, "reserved", 4)
     yield textHandler(UInt16(self, "checksum"), hexadecimal)
Esempio n. 15
0
    def createFields(self):
        # Gzip header
        yield Bytes(self, "signature", 2, r"GZip file signature (\x1F\x8B)")
        yield Enum(UInt8(self, "compression", "Compression method"),
                   self.COMPRESSION_NAME)

        # Flags
        yield Bit(self, "is_text", "File content is probably ASCII text")
        yield Bit(self, "has_crc16", "Header CRC16")
        yield Bit(self, "has_extra", "Extra informations (variable size)")
        yield Bit(self, "has_filename", "Contains filename?")
        yield Bit(self, "has_comment", "Contains comment?")
        yield NullBits(self, "reserved[]", 3)
        yield TimestampUnix32(self, "mtime", "Modification time")

        # Extra flags
        yield NullBits(self, "reserved[]", 1)
        yield Bit(self, "slowest",
                  "Compressor used maximum compression (slowest)")
        yield Bit(self, "fastest", "Compressor used the fastest compression")
        yield NullBits(self, "reserved[]", 5)
        yield Enum(UInt8(self, "os", "Operating system"), self.os_name)

        # Optional fields
        if self["has_extra"].value:
            yield UInt16(self, "extra_length", "Extra length")
            yield RawBytes(self, "extra", self["extra_length"].value, "Extra")
        if self["has_filename"].value:
            yield CString(self, "filename", "Filename", charset="ISO-8859-1")
        if self["has_comment"].value:
            yield CString(self, "comment", "Comment")
        if self["has_crc16"].value:
            yield textHandler(UInt16(self, "hdr_crc16", "CRC16 of the header"),
                              hexadecimal)

        if self._size is None:  # TODO: is it possible to handle piped input?
            raise NotImplementedError()

        # Read file
        size = (self._size - self.current_size) // 8 - 8  # -8: crc32+size
        if 0 < size:
            if self["has_filename"].value:
                filename = self["filename"].value
            else:
                for tag, filename in self.stream.tags:
                    if tag == "filename" and filename.endswith(".gz"):
                        filename = filename[:-3]
                        break
                else:
                    filename = None
            yield Deflate(SubFile(self, "file", size, filename=filename))

        # Footer
        yield textHandler(
            UInt32(self, "crc32", "Uncompressed data content CRC32"),
            hexadecimal)
        yield filesizeHandler(UInt32(self, "size", "Uncompressed size"))
Esempio n. 16
0
 def createFields(self):
     yield Enum(UInt16(self, "type", "Type"), ProgramHeader32.TYPE_NAME)
     yield UInt16(self, "flags", "Flags")
     yield UInt32(self, "offset", "Offset")
     yield textHandler(UInt32(self, "vaddr", "V. address"), hexadecimal)
     yield textHandler(UInt32(self, "paddr", "P. address"), hexadecimal)
     yield UInt32(self, "file_size", "File size")
     yield UInt32(self, "mem_size", "Memory size")
     yield UInt32(self, "align", "Alignment")
     yield UInt32(self, "xxx", "???")
Esempio n. 17
0
 def createFields(self):
     yield Enum(UInt16(self, "type", "Type"), ProgramHeader32.TYPE_NAME)
     yield UInt16(self, "flags", "Flags")
     yield UInt32(self, "offset", "Offset")
     yield textHandler(UInt32(self, "vaddr", "V. address"), hexadecimal)
     yield textHandler(UInt32(self, "paddr", "P. address"), hexadecimal)
     yield UInt32(self, "file_size", "File size")
     yield UInt32(self, "mem_size", "Memory size")
     yield UInt32(self, "align", "Alignment")
     yield UInt32(self, "xxx", "???")
Esempio n. 18
0
    def createFields(self):
        # Gzip header
        yield Bytes(self, "signature", 2, r"GZip file signature (\x1F\x8B)")
        yield Enum(UInt8(self, "compression", "Compression method"), self.COMPRESSION_NAME)

        # Flags
        yield Bit(self, "is_text", "File content is probably ASCII text")
        yield Bit(self, "has_crc16", "Header CRC16")
        yield Bit(self, "has_extra", "Extra informations (variable size)")
        yield Bit(self, "has_filename", "Contains filename?")
        yield Bit(self, "has_comment", "Contains comment?")
        yield NullBits(self, "reserved[]", 3)
        yield TimestampUnix32(self, "mtime", "Modification time")

        # Extra flags
        yield NullBits(self, "reserved[]", 1)
        yield Bit(self, "slowest", "Compressor used maximum compression (slowest)")
        yield Bit(self, "fastest", "Compressor used the fastest compression")
        yield NullBits(self, "reserved[]", 5)
        yield Enum(UInt8(self, "os", "Operating system"), self.os_name)

        # Optional fields
        if self["has_extra"].value:
            yield UInt16(self, "extra_length", "Extra length")
            yield RawBytes(self, "extra", self["extra_length"].value, "Extra")
        if self["has_filename"].value:
            yield CString(self, "filename", "Filename", charset="ISO-8859-1")
        if self["has_comment"].value:
            yield CString(self, "comment", "Comment")
        if self["has_crc16"].value:
            yield textHandler(UInt16(self, "hdr_crc16", "CRC16 of the header"),
                hexadecimal)

        if self._size is None: # TODO: is it possible to handle piped input?
            raise NotImplementedError()

        # Read file
        size = (self._size - self.current_size) // 8 - 8  # -8: crc32+size
        if 0 < size:
            if self["has_filename"].value:
                filename = self["filename"].value
            else:
                for tag, filename in self.stream.tags:
                    if tag == "filename" and filename.endswith(".gz"):
                        filename = filename[:-3]
                        break
                else:
                    filename = None
            yield Deflate(SubFile(self, "file", size, filename=filename))

        # Footer
        yield textHandler(UInt32(self, "crc32",
            "Uncompressed data content CRC32"), hexadecimal)
        yield filesizeHandler(UInt32(self, "size", "Uncompressed size"))
Esempio n. 19
0
 def createFields(self):
     yield UInt32(self, "name", "Name")
     yield Enum(UInt32(self, "type", "Type"), self.TYPE_NAME)
     yield UInt32(self, "flags", "Flags")
     yield textHandler(UInt32(self, "VMA", "Virtual memory address"), hexadecimal)
     yield textHandler(UInt32(self, "LMA", "Logical memory address (in file)"), hexadecimal)
     yield textHandler(UInt32(self, "size", "Size"), hexadecimal)
     yield UInt32(self, "link", "Link")
     yield UInt32(self, "info", "Information")
     yield UInt32(self, "addr_align", "Address alignment")
     yield UInt32(self, "entry_size", "Entry size")
Esempio n. 20
0
def newRecoveryHeader(self):
    """
    This header is described nowhere
    """
    if self["flags/extend"].value:
        yield filesizeHandler(UInt32(self, "body_size", "Size of the unknown body following"))
        self.body_size = self["body_size"].value
    yield textHandler(UInt32(self, "unknown[]", "Unknown field, probably 0"),
        hexadecimal)
    yield String(self, "signature", 7, "Signature, normally '**ACE**'")
    yield textHandler(UInt32(self, "relative_start",
        "Offset (=crc16's) of this block in the file"), hexadecimal)
    yield textHandler(UInt32(self, "unknown[]",
        "Unknown field, probably 0"), hexadecimal)
Esempio n. 21
0
 def createFields(self):
     yield UInt32(self, "name", "Name")
     yield Enum(UInt32(self, "type", "Type"), self.TYPE_NAME)
     yield UInt32(self, "flags", "Flags")
     yield textHandler(UInt32(self, "VMA", "Virtual memory address"),
                       hexadecimal)
     yield textHandler(
         UInt32(self, "LMA", "Logical memory address (in file)"),
         hexadecimal)
     yield textHandler(UInt32(self, "size", "Size"), hexadecimal)
     yield UInt32(self, "link", "Link")
     yield UInt32(self, "info", "Information")
     yield UInt32(self, "addr_align", "Address alignment")
     yield UInt32(self, "entry_size", "Entry size")
Esempio n. 22
0
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")
Esempio n. 23
0
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")
Esempio n. 24
0
 def createFields(self):
     yield textHandler(UInt8(self, "header", "Header"), hexadecimal)
     if self["header"].value != 0xFF:
         raise ParserError("JPEG: Invalid chunk header!")
     yield textHandler(UInt8(self, "type", "Type"), hexadecimal)
     tag = self["type"].value
     if tag in (self.TAG_SOI, self.TAG_EOI):
         return
     yield UInt16(self, "size", "Size")
     size = (self["size"].value - 2)
     if 0 < size:
         if self._parser:
             yield self._parser(self, "content", "Chunk content", size=size*8)
         else:
             yield RawBytes(self, "data", size, "Data")
Esempio n. 25
0
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")
Esempio n. 26
0
 def createFields(self):
     yield UInt16(self, "signature",
                  "PE optional header signature (0x010b)")
     # TODO: Support PE32+ (signature=0x020b)
     if self["signature"].value != 0x010b:
         raise ParserError("Invalid PE optional header signature")
     yield UInt8(self, "maj_lnk_ver", "Major linker version")
     yield UInt8(self, "min_lnk_ver", "Minor linker version")
     yield filesizeHandler(UInt32(self, "size_code", "Size of code"))
     yield filesizeHandler(
         UInt32(self, "size_init_data", "Size of initialized data"))
     yield filesizeHandler(
         UInt32(self, "size_uninit_data", "Size of uninitialized data"))
     yield textHandler(
         UInt32(self, "entry_point",
                "Address (RVA) of the code entry point"), hexadecimal)
     yield textHandler(UInt32(self, "base_code", "Base (RVA) of code"),
                       hexadecimal)
     yield textHandler(UInt32(self, "base_data", "Base (RVA) of data"),
                       hexadecimal)
     yield textHandler(UInt32(self, "image_base", "Image base (RVA)"),
                       hexadecimal)
     yield filesizeHandler(UInt32(self, "sect_align", "Section alignment"))
     yield filesizeHandler(UInt32(self, "file_align", "File alignment"))
     yield UInt16(self, "maj_os_ver", "Major OS version")
     yield UInt16(self, "min_os_ver", "Minor OS version")
     yield UInt16(self, "maj_img_ver", "Major image version")
     yield UInt16(self, "min_img_ver", "Minor image version")
     yield UInt16(self, "maj_subsys_ver", "Major subsystem version")
     yield UInt16(self, "min_subsys_ver", "Minor subsystem version")
     yield NullBytes(self, "reserved", 4)
     yield filesizeHandler(UInt32(self, "size_img", "Size of image"))
     yield filesizeHandler(UInt32(self, "size_hdr", "Size of headers"))
     yield textHandler(UInt32(self, "checksum"), hexadecimal)
     yield Enum(UInt16(self, "subsystem"), self.SUBSYSTEM_NAME)
     yield UInt16(self, "dll_flags")
     yield filesizeHandler(UInt32(self, "size_stack_reserve"))
     yield filesizeHandler(UInt32(self, "size_stack_commit"))
     yield filesizeHandler(UInt32(self, "size_heap_reserve"))
     yield filesizeHandler(UInt32(self, "size_heap_commit"))
     yield UInt32(self, "loader_flags")
     yield UInt32(self, "nb_directory", "Number of RVA and sizes")
     for index in xrange(self["nb_directory"].value):
         try:
             name = self.DIRECTORY_NAME[index]
         except KeyError:
             name = "data_dir[%u]" % index
         yield DataDirectory(self, name)
Esempio n. 27
0
    def createFields(self):
        yield textHandler(UInt8(self, "version"), hexadecimal)

        # TODO: sum of :
        # TrackEnabled = 1;
        # TrackInMovie = 2;
        # TrackInPreview = 4;
        # TrackInPoster = 8
        yield RawBytes(self, "flags", 3)

        yield TimestampMac32(self, "creation_date")
        yield TimestampMac32(self, "lastmod_date")
        yield UInt32(self, "track_id")
        yield PaddingBytes(self, "reserved[]", 8)
        yield UInt32(self, "duration")
        yield PaddingBytes(self, "reserved[]", 8)
        yield Int16(self, "video_layer", "Middle is 0, negative in front")
        yield PaddingBytes(self, "other", 2)
        yield QTFloat32(self, "geom_a", "Width scale")
        yield QTFloat32(self, "geom_b", "Width rotate")
        yield QTFloat32(self, "geom_u", "Width angle")
        yield QTFloat32(self, "geom_c", "Height rotate")
        yield QTFloat32(self, "geom_d", "Height scale")
        yield QTFloat32(self, "geom_v", "Height angle")
        yield QTFloat32(self, "geom_x", "Position X")
        yield QTFloat32(self, "geom_y", "Position Y")
        yield QTFloat32(self, "geom_w", "Divider scale")
        yield QTFloat32(self, "frame_size_width")
        yield QTFloat32(self, "frame_size_height")
Esempio n. 28
0
    def createFields(self):
        yield textHandler(UInt8(self, "version"), hexadecimal)

        # TODO: sum of :
        # TrackEnabled = 1;
        # TrackInMovie = 2;
        # TrackInPreview = 4;
        # TrackInPoster = 8
        yield RawBytes(self, "flags", 3)

        yield TimestampMac32(self, "creation_date")
        yield TimestampMac32(self, "lastmod_date")
        yield UInt32(self, "track_id")
        yield PaddingBytes(self, "reserved[]", 8)
        yield UInt32(self, "duration")
        yield PaddingBytes(self, "reserved[]", 8)
        yield Int16(self, "video_layer", "Middle is 0, negative in front")
        yield PaddingBytes(self, "other", 2)
        yield QTFloat32(self, "geom_a", "Width scale")
        yield QTFloat32(self, "geom_b", "Width rotate")
        yield QTFloat32(self, "geom_u", "Width angle")
        yield QTFloat32(self, "geom_c", "Height rotate")
        yield QTFloat32(self, "geom_d", "Height scale")
        yield QTFloat32(self, "geom_v", "Height angle")
        yield QTFloat32(self, "geom_x", "Position X")
        yield QTFloat32(self, "geom_y", "Position Y")
        yield QTFloat32(self, "geom_w", "Divider scale")
        yield QTFloat32(self, "frame_size_width")
        yield QTFloat32(self, "frame_size_height")
Esempio n. 29
0
 def createFields(self):
     yield textHandler(UInt8(self, "version"), hexadecimal)
     yield RawBytes(self, "flags", 3)
     yield TimestampMac32(self, "creation_date")
     yield TimestampMac32(self, "lastmod_date")
     yield UInt32(self, "time_scale")
     yield UInt32(self, "duration")
     yield QTFloat32(self, "play_speed")
     yield UInt16(self, "volume")
     yield PaddingBytes(self, "reserved[]", 10)
     yield QTFloat32(self, "geom_a", "Width scale")
     yield QTFloat32(self, "geom_b", "Width rotate")
     yield QTFloat32(self, "geom_u", "Width angle")
     yield QTFloat32(self, "geom_c", "Height rotate")
     yield QTFloat32(self, "geom_d", "Height scale")
     yield QTFloat32(self, "geom_v", "Height angle")
     yield QTFloat32(self, "geom_x", "Position X")
     yield QTFloat32(self, "geom_y", "Position Y")
     yield QTFloat32(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")
Esempio n. 30
0
    def createFields(self):
        LONG = Int32
        yield UInt32(self, "type", "Record type (always 1)")
        yield UInt32(self, "size", "Size of the header in bytes")
        yield RECT32(self, "Bounds", "Inclusive bounds")
        yield RECT32(self, "Frame", "Inclusive picture frame")
        yield textHandler(UInt32(self, "signature", "Signature ID (always 0x464D4520)"), hexadecimal)
        yield UInt16(self, "min_ver", "Minor version")
        yield UInt16(self, "maj_ver", "Major version")
        yield UInt32(self, "file_size", "Size of the file in bytes")
        yield UInt32(self, "NumOfRecords", "Number of records in the metafile")
        yield UInt16(self, "NumOfHandles", "Number of handles in the handle table")
        yield NullBytes(self, "reserved", 2)
        yield UInt32(self, "desc_size", "Size of description in 16-bit words")
        yield UInt32(self, "desc_ofst", "Offset of description string in metafile")
        yield UInt32(self, "nb_colors", "Number of color palette entries")
        yield LONG(self, "width_px", "Width of reference device in pixels")
        yield LONG(self, "height_px", "Height of reference device in pixels")
        yield LONG(self, "width_mm", "Width of reference device in millimeters")
        yield LONG(self, "height_mm", "Height of reference device in millimeters")

        # Read description (if any)
        offset = self["desc_ofst"].value
        current = (self.absolute_address + self.current_size) // 8
        size = self["desc_size"].value * 2
        if offset == current and size:
            yield String(self, "description", size, charset="UTF-16-LE", strip="\0 ")

        # Read padding (if any)
        size = self["size"].value - self.current_size//8
        if size:
            yield RawBytes(self, "padding", size)
Esempio n. 31
0
 def createFields(self):
     yield RawBytes(self, "program", 446, "Boot program (Intel x86 machine code)")
     yield PartitionHeader(self, "header[0]")
     yield PartitionHeader(self, "header[1]")
     yield PartitionHeader(self, "header[2]")
     yield PartitionHeader(self, "header[3]")
     yield textHandler(UInt16(self, "signature", "Signature (0xAA55)"), hexadecimal)
Esempio n. 32
0
 def createFields(self):
     byte = UInt8(self, "id_size")
     yield byte
     byte = byte.value
     self.info("ID=%u" % byte)
     size = byte & 0xF
     if size > 0:
         name = self.stream.readBytes(
             self.absolute_address + self.current_size, size)
         if name in self.CODECS:
             name = self.CODECS[name]
             self.info("Codec is %s" % name)
         else:
             self.info("Undetermined codec %s" % name)
             name = "unknown"
         yield RawBytes(self, name, size)
         #yield textHandler(Bytes(self, "id", size), lambda: name)
     if byte & 0x10:
         yield SZUInt64(self, "num_stream_in")
         yield SZUInt64(self, "num_stream_out")
         self.info("Streams: IN=%u    OUT=%u" % \
                   (self["num_stream_in"].value, self["num_stream_out"].value))
     if byte & 0x20:
         size = SZUInt64(self, "properties_size[]")
         yield size
         if size.value == 5:
             #[email protected]
             yield textHandler(UInt8(self, "parameters"), lzmaParams)
             yield filesizeHandler(UInt32(self, "dictionary_size"))
         elif size.value > 0:
             yield RawBytes(self, "properties[]", size.value)
Esempio n. 33
0
 def createFields(self):
     # File data
     self.signature = None
     self.central_directory = []
     while not self.eof:
         header = textHandler(UInt32(self, "header[]", "Header"), hexadecimal)
         yield header
         header = header.value
         if header == FileEntry.HEADER:
             yield FileEntry(self, "file[]")
         elif header == ZipDataDescriptor.HEADER:
             yield ZipDataDescriptor(self, "spanning[]")
         elif header == 0x30304b50:
             yield ZipDataDescriptor(self, "temporary_spanning[]")
         elif header == ZipCentralDirectory.HEADER:
             yield ZipCentralDirectory(self, "central_directory[]")
         elif header == ZipEndCentralDirectory.HEADER:
             yield ZipEndCentralDirectory(self, "end_central_directory", "End of central directory")
         elif header == Zip64EndCentralDirectory.HEADER:
             yield Zip64EndCentralDirectory(self, "end64_central_directory", "ZIP64 end of central directory")
         elif header == ZipSignature.HEADER:
             yield ZipSignature(self, "signature", "Signature")
         elif header == Zip64EndCentralDirectoryLocator.HEADER:
             yield Zip64EndCentralDirectoryLocator(self, "end_locator", "ZIP64 Enf of central directory locator")
         else:
             raise ParserError("Error, unknown ZIP header (0x%08X)." % header)
Esempio n. 34
0
 def createFields(self):
     byte = UInt8(self, "id_size")
     yield byte
     byte = byte.value
     self.info("ID=%u" % byte)
     size = byte & 0xF
     if size > 0:
         name = self.stream.readBytes(self.absolute_address+self.current_size, size)
         if name in self.CODECS:
             name = self.CODECS[name]
             self.info("Codec is %s" % name)
         else:
             self.info("Undetermined codec %s" % name)
             name = "unknown"
         yield RawBytes(self, name, size)
         #yield textHandler(Bytes(self, "id", size), lambda: name)
     if byte & 0x10:
         yield SZUInt64(self, "num_stream_in")
         yield SZUInt64(self, "num_stream_out")
         self.info("Streams: IN=%u    OUT=%u" % \
                   (self["num_stream_in"].value, self["num_stream_out"].value))
     if byte & 0x20:
         size = SZUInt64(self, "properties_size[]")
         yield size
         if size.value == 5:
             #[email protected]
             yield textHandler(UInt8(self, "parameters"), lzmaParams)
             yield filesizeHandler(UInt32(self, "dictionary_size"))
         elif size.value > 0:
             yield RawBytes(self, "properties[]", size.value)
Esempio n. 35
0
 def createFields(self):
     yield Bytes(self, "signature", 6, "Signature Header")
     yield UInt8(self, "major_ver", "Archive major version")
     yield UInt8(self, "minor_ver", "Archive minor version")
     yield textHandler(UInt32(self, "start_hdr_crc", "Start header CRC"),
                       hexadecimal)
     yield StartHeader(self, "start_hdr", "Start header")
Esempio n. 36
0
 def createFields(self):
     yield textHandler(UInt32(self, "file_crc32",
         "Checksum (CRC32)"), hexadecimal)
     yield filesizeHandler(UInt32(self, "file_compressed_size",
         "Compressed size (bytes)"))
     yield filesizeHandler(UInt32(self, "file_uncompressed_size",
          "Uncompressed size (bytes)"))
Esempio n. 37
0
 def createFields(self):
     yield textHandler(UInt8(self, "version"), hexadecimal)
     yield RawBytes(self, "flags", 3)
     yield TimestampMac32(self, "creation_date")
     yield TimestampMac32(self, "lastmod_date")
     yield UInt32(self, "time_scale")
     yield UInt32(self, "duration")
     yield QTFloat32(self, "play_speed")
     yield UInt16(self, "volume")
     yield PaddingBytes(self, "reserved[]", 10)
     yield QTFloat32(self, "geom_a", "Width scale")
     yield QTFloat32(self, "geom_b", "Width rotate")
     yield QTFloat32(self, "geom_u", "Width angle")
     yield QTFloat32(self, "geom_c", "Height rotate")
     yield QTFloat32(self, "geom_d", "Height scale")
     yield QTFloat32(self, "geom_v", "Height angle")
     yield QTFloat32(self, "geom_x", "Position X")
     yield QTFloat32(self, "geom_y", "Position Y")
     yield QTFloat32(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")
Esempio n. 38
0
    def createUnpaddedFields(self):
        yield String(self, "title", 28, strip='\0')
        yield textHandler(UInt8(self, "marker[]"), hexadecimal)
        for field in self.getFileVersionField():
            yield field

        yield UInt16(self, "num_orders")
        yield UInt16(self, "num_instruments")
        yield UInt16(self, "num_patterns")

        for field in self.getFirstProperties():
            yield field
        yield String(self, "marker[]", 4)
        for field in self.getLastProperties():
            yield field

        yield GenericVector(self, "channel_settings", 32, ChannelSettings,
                            "channel")

        # Orders
        yield GenericVector(self, "orders", self.getNumOrders(), UInt8,
                            "order")

        for field in self.getHeaderEndFields():
            yield field
Esempio n. 39
0
 def createFields(self):
     yield textHandler(UInt8(self, "version"), hexadecimal)
     yield RawBytes(self, "flags", 3)
     yield UInt32(self, "nb_edits")
     yield UInt32(self, "length")
     yield UInt32(self, "start")
     yield QTFloat32(self, "playback_speed")
Esempio n. 40
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)
Esempio n. 41
0
 def createFields(self):
     yield textHandler(UInt8(self, "version"), hexadecimal)
     yield RawBytes(self, "flags", 3)
     yield UInt32(self, "nb_edits")
     yield UInt32(self, "length")
     yield UInt32(self, "start")
     yield QTFloat32(self, "playback_speed")
Esempio n. 42
0
 def createFields(self):
     yield Bytes(self, "signature", 6, "Signature Header")
     yield UInt8(self, "major_ver", "Archive major version")
     yield UInt8(self, "minor_ver", "Archive minor version")
     yield textHandler(UInt32(self, "start_hdr_crc",
         "Start header CRC"), hexadecimal)
     yield StartHeader(self, "start_hdr", "Start header")
Esempio n. 43
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 == '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)
Esempio n. 44
0
 def createFields(self):
     yield Bytes(self, "jmp", 3, "Jump instruction (to skip over header on boot)")
     yield Bytes(self, "oem_name", 8, "OEM Name (padded with spaces)")
     yield UInt16(self, "sector_size", "Bytes per sector")
     yield UInt8 (self, "cluster_size", "Sectors per cluster")
     yield UInt16(self, "reserved_sectors", "Reserved sector count (including boot sector)")
     yield UInt8 (self, "fat_nb", "Number of file allocation tables")
     yield UInt16(self, "max_root", "Maximum number of root directory entries")
     yield UInt16(self, "sectors1", "Total sectors (if zero, use 'sectors2')")
     yield UInt8 (self, "media_desc", "Media descriptor")
     yield UInt16(self, "fat_size", "Sectors per FAT")
     yield UInt16(self, "track_size", "Sectors per track")
     yield UInt16(self, "head_nb", "Number of heads")
     yield UInt32(self, "hidden", "Hidden sectors")
     yield UInt32(self, "sectors2", "Total sectors (if greater than 65535)")
     if self.parent.version == 32:
         yield UInt32(self, "fat32_size", "Sectors per FAT")
         yield UInt16(self, "fat_flags", "FAT Flags")
         yield UInt16(self, "version", "Version")
         yield UInt32(self, "root_start", "Cluster number of root directory start")
         yield UInt16(self, "inf_sector", "Sector number of FS Information Sector")
         yield UInt16(self, "boot_copy", "Sector number of a copy of this boot sector")
         yield NullBytes(self, "reserved[]", 12, "Reserved")
     yield UInt8(self, "phys_drv", "Physical drive number")
     yield NullBytes(self, "reserved[]", 1, 'Reserved ("current head")')
     yield UInt8(self, "sign", "Signature")
     yield textHandler(UInt32(self, "serial", "ID (serial number)"), hexadecimal)
     yield String(self, "label", 11, "Volume Label", strip=' ', charset="ASCII")
     yield String(self, "fs_type", 8, "FAT file system type", strip=' ', charset="ASCII")
     yield Bytes(self, "code", 510-self.current_size/8, "Operating system boot code")
     yield Bytes(self, "trail_sig", 2, "Signature (0x55 0xAA)")
Esempio n. 45
0
    def createFields(self):
        yield Enum(UInt16(self, "src"), self.port_name)
        yield Enum(UInt16(self, "dst"), self.port_name)
        yield UInt32(self, "seq_num")
        yield UInt32(self, "ack_num")

        yield Bits(self, "hdrlen", 6, "Header lenght")
        yield NullBits(self, "reserved", 2, "Reserved")

        yield Bit(self, "cgst", "Congestion Window Reduced")
        yield Bit(self, "ecn-echo", "ECN-echo")
        yield Bit(self, "urg", "Urgent")
        yield Bit(self, "ack", "Acknowledge")
        yield Bit(self, "psh", "Push mmode")
        yield Bit(self, "rst", "Reset connection")
        yield Bit(self, "syn", "Synchronize")
        yield Bit(self, "fin", "Stop the connection")

        yield UInt16(self, "winsize", "Windows size")
        yield textHandler(UInt16(self, "checksum"), hexadecimal)
        yield UInt16(self, "urgent")

        size = self["hdrlen"].value*8 - self.current_size
        while 0 < size:
            option = TCP_Option(self, "option[]")
            yield option
            size -= option.size
Esempio n. 46
0
    def createFields(self):
        yield Enum(UInt16(self, "src"), self.port_name)
        yield Enum(UInt16(self, "dst"), self.port_name)
        yield UInt32(self, "seq_num")
        yield UInt32(self, "ack_num")

        yield Bits(self, "hdrlen", 6, "Header lenght")
        yield NullBits(self, "reserved", 2, "Reserved")

        yield Bit(self, "cgst", "Congestion Window Reduced")
        yield Bit(self, "ecn-echo", "ECN-echo")
        yield Bit(self, "urg", "Urgent")
        yield Bit(self, "ack", "Acknowledge")
        yield Bit(self, "psh", "Push mmode")
        yield Bit(self, "rst", "Reset connection")
        yield Bit(self, "syn", "Synchronize")
        yield Bit(self, "fin", "Stop the connection")

        yield UInt16(self, "winsize", "Windows size")
        yield textHandler(UInt16(self, "checksum"), hexadecimal)
        yield UInt16(self, "urgent")

        size = self["hdrlen"].value * 8 - self.current_size
        while 0 < size:
            option = TCP_Option(self, "option[]")
            yield option
            size -= option.size
Esempio n. 47
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)
Esempio n. 48
0
    def createFields(self):
        yield Enum(UInt8(self, "type"), self.TYPE_DESC)
        yield UInt8(self, "code")
        yield textHandler(UInt16(self, "checksum"), hexadecimal)

        if self['type'].value in (self.ECHO_REQUEST, self.ECHO_REPLY):
            yield UInt16(self, "id")
            yield UInt16(self, "sequence")
Esempio n. 49
0
 def createFields(self):
     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)
     yield RawBytes(self, "payload", 184)
     if self["has_error"].value:
         yield RawBytes(self, "error_correction", 16)
Esempio n. 50
0
    def createFields(self):
        yield Enum(UInt8(self, "type"), self.TYPE_DESC)
        yield UInt8(self, "code")
        yield textHandler(UInt16(self, "checksum"), hexadecimal)

        if self['type'].value in (self.ECHO_REQUEST, self.ECHO_REPLY):
            yield UInt16(self, "id")
            yield UInt16(self, "sequence")
Esempio n. 51
0
 def createFields(self):
     yield NullBytes(self, "zero", 1)
     yield textHandler(
         String(self,
                "length",
                self._size / 8 - 1,
                "Length in ms",
                charset="ASCII"), self.computeLength)
Esempio n. 52
0
 def createFields(self):
     yield textHandler(UInt8(self, "version"), hexadecimal)
     yield RawBytes(self, "flags", 3)
     yield TimestampMac32(self, "creation_date")
     yield TimestampMac32(self, "lastmod_date")
     yield UInt32(self, "time_scale")
     yield UInt32(self, "duration")
     yield UInt16(self, "mac_lang")
     yield Int16(self, "quality")