コード例 #1
0
ファイル: sevenzip.py プロジェクト: valnar1/SickGear
 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")
コード例 #2
0
ファイル: id3.py プロジェクト: valnar1/SickGear
    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
コード例 #3
0
 def createFields(self):
     yield String(self,
                  "magic",
                  len(self.MAGIC),
                  'Magic string (%r)' % self.MAGIC,
                  charset="ASCII")
     yield UInt8(self, "major_version")
     yield UInt8(self, "minor_version")
     yield Enum(UInt8(self, "crypto"), self.CRYPTO_NAMES)
     yield Enum(UInt8(self, "hash"), self.HASH_NAMES)
     yield KeyringString(self, "keyring_name")
     yield TimestampUnix64(self, "mtime")
     yield TimestampUnix64(self, "ctime")
     yield Bit(self, "lock_on_idle")
     yield NullBits(self, "reserved[]", 31, "Reserved for future flags")
     yield UInt32(self, "lock_timeout")
     yield UInt32(self, "hash_iterations")
     yield RawBytes(self, "salt", 8)
     yield NullBytes(self, "reserved[]", 16)
     yield Items(self, "items")
     yield UInt32(self, "encrypted_size")
     yield Deflate(
         SubFile(self,
                 "encrypted",
                 self["encrypted_size"].value,
                 "AES128 CBC",
                 parser_class=EncryptedData))
コード例 #4
0
ファイル: itunesdb.py プロジェクト: valnar1/SickGear
    def createFields(self):
        yield String(self, "header_id", 4, "Playlist Header Markup (\"mhyp\")", charset="ISO-8859-1")
        yield UInt32(self, "header_length", "Header Length")
        yield UInt32(self, "entry_length", "Entry Length")
        yield UInt32(self, "data_object_child_count", "Number of Child Data Objects")
        yield UInt32(self, "playlist_count", "Number of Playlist Items")
        yield Enum(UInt8(self, "type", "Normal or master playlist?"), self.is_master_pl_name)
        yield UInt8(self, "XXX1", "XXX1")
        yield UInt8(self, "XXX2", "XXX2")
        yield UInt8(self, "XXX3", "XXX3")
        yield TimestampMac32(self, "creation_date", "Date when the playlist was created")
        yield UInt64(self, "playlistid", "Persistent Playlist ID")
        yield UInt32(self, "unk3", "unk3")
        yield UInt16(self, "string_mhod_count", "Number of string MHODs for this playlist")
        yield Enum(UInt16(self, "is_podcast", "Playlist or Podcast List?"), self.is_podcast_name)
        yield Enum(UInt32(self, "sort_order", "Playlist Sort Order"), self.list_sort_order_name)

        padding = self.seekByte(self["header_length"].value, "entry padding")
        if padding:
            yield padding

        for i in range(self["data_object_child_count"].value):
            yield DataObject(self, "mhod[]")

        for i in range(self["playlist_count"].value):
            yield PlaylistItem(self, "playlist_item[]")
コード例 #5
0
def fileHeader(self):
    yield filesizeHandler(
        UInt32(self, "compressed_size", "Size of the compressed file"))
    yield filesizeHandler(
        UInt32(self, "uncompressed_size", "Uncompressed file size"))
    yield TimeDateMSDOS32(self, "ftime", "Date and time (MS DOS format)")
    if self["/header/host_os"].value in (OS_MSDOS, OS_WIN32):
        yield MSDOSFileAttr32(self, "file_attr", "File attributes")
    else:
        yield textHandler(UInt32(self, "file_attr", "File attributes"),
                          hexadecimal)
    yield textHandler(
        UInt32(self, "file_crc32", "CRC32 checksum over the compressed file)"),
        hexadecimal)
    yield Enum(UInt8(self, "compression_type", "Type of compression"),
               COMPRESSION_TYPE)
    yield Enum(UInt8(self, "compression_mode", "Quality of compression"),
               COMPRESSION_MODE)
    yield textHandler(UInt16(self, "parameters", "Compression parameters"),
                      hexadecimal)
    yield textHandler(UInt16(self, "reserved", "Reserved data"), hexadecimal)
    # Filename
    yield PascalString16(self, "filename", "Filename")
    # Comment
    if self["flags/has_comment"].value:
        yield filesizeHandler(
            UInt16(self, "comment_size", "Size of the compressed comment"))
        if self["comment_size"].value > 0:
            yield RawBytes(self, "comment_data", self["comment_size"].value,
                           "Comment data")
コード例 #6
0
ファイル: swf.py プロジェクト: valnar1/SickGear
def parseProductInfo(parent, size):
    yield Int32(parent, "product_id")
    yield Int32(parent, "edition")
    yield UInt8(parent, "major_version")
    yield UInt8(parent, "minor_version")
    yield Int64(parent, "build_number")
    yield Int64(parent, "compilation_date")
コード例 #7
0
ファイル: png.py プロジェクト: valnar1/SickGear
def timestampParse(parent):
    yield UInt16(parent, "year", "Year")
    yield UInt8(parent, "month", "Month")
    yield UInt8(parent, "day", "Day")
    yield UInt8(parent, "hour", "Hour")
    yield UInt8(parent, "minute", "Minute")
    yield UInt8(parent, "second", "Second")
コード例 #8
0
 def createFields(self):
     yield Integer(self, "time", "Delta time in ticks")
     next = self.stream.readBits(self.absolute_address + self.current_size,
                                 8, self.root.endian)
     if next & 0x80 == 0:
         # "Running Status" command
         if self.prev_command is None:
             raise ParserError(
                 "Running Status command not preceded by another command.")
         self.command = self.prev_command.command
     else:
         yield Enum(textHandler(UInt8(self, "command"), hexadecimal),
                    self.COMMAND_DESC)
         self.command = self["command"].value
     if self.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 is not None:
                 yield from parser(self, size)
             else:
                 yield RawBytes(self, "data", size)
     else:
         if self.command not in self.COMMAND_PARSER:
             raise ParserError("Unknown command: %s" %
                               self["command"].display)
         parser = self.COMMAND_PARSER[self.command]
         yield from parser(self)
コード例 #9
0
ファイル: id3.py プロジェクト: valnar1/SickGear
    def createFields(self):
        yield String(self, "signature", 3, "IDv1 signature (\"TAG\")", charset="ASCII")
        if self["signature"].value != "TAG":
            raise MatchError(
                "Stream doesn't look like ID3v1 (wrong signature)!")
        # TODO: Charset of below strings?
        yield String(self, "song", 30, "Song title", strip=" \0", charset="ISO-8859-1")
        yield String(self, "author", 30, "Author", strip=" \0", charset="ISO-8859-1")
        yield String(self, "album", 30, "Album title", strip=" \0", charset="ISO-8859-1")
        yield String(self, "year", 4, "Year", strip=" \0", charset="ISO-8859-1")

        # TODO: Write better algorithm to guess ID3v1 version
        version = self.getVersion()
        if version in ("v1.1", "v1.1b"):
            if version == "v1.1b":
                # ID3 v1.1b
                yield String(self, "comment", 29, "Comment", strip=" \0", charset="ISO-8859-1")
                yield UInt8(self, "track_nb", "Track number")
            else:
                # ID3 v1.1
                yield String(self, "comment", 30, "Comment", strip=" \0", charset="ISO-8859-1")
            yield Enum(UInt8(self, "genre", "Genre"), self.GENRE_NAME)
        else:
            # ID3 v1.0
            yield String(self, "comment", 31, "Comment", strip=" \0", charset="ISO-8859-1")
コード例 #10
0
ファイル: gif.py プロジェクト: valnar1/SickGear
    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, "image_block_size[]")
            if size.value == 0:
                break
            yield size
            block = CustomFragment(self, "image_block[]", size.value * 8,
                                   GifImageBlock, "GIF Image Block", group)
            if group is None:
                block.group.args["startbits"] = self["lzw_min_code_size"].value
            group = block.group
            yield block
        yield NullBytes(self, "terminator", 1, "Terminator (0)")
コード例 #11
0
ファイル: pcx.py プロジェクト: valnar1/SickGear
    def createFields(self):
        yield UInt8(self, "id", "PCX identifier (10)")
        yield Enum(UInt8(self, "version", "PCX version"), self.version_name)
        yield Enum(UInt8(self, "compression", "Compression method"),
                   self.compression_name)
        yield UInt8(self, "bpp", "Bits / pixel")
        yield UInt16(self, "xmin", "Minimum X")
        yield UInt16(self, "ymin", "Minimum Y")
        yield UInt16(self, "xmax", "Width minus one")  # value + 1
        yield UInt16(self, "ymax", "Height minus one")  # value + 1
        yield UInt16(self, "horiz_dpi", "Horizontal DPI")
        yield UInt16(self, "vert_dpi", "Vertical DPI")
        yield PaletteRGB(self, "palette_4bits", 16, "Palette (4 bits)")
        yield PaddingBytes(self, "reserved[]", 1)
        yield UInt8(self, "nb_color_plan", "Number of color plans")
        yield UInt16(self, "bytes_per_line", "Bytes per line")
        yield UInt16(self, "color_mode", "Color mode")
        yield PaddingBytes(self, "reserved[]", 58)

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

        nb_colors = 256
        size = (self._size - self.current_size) // 8
        has_palette = self["bpp"].value == 8
        if has_palette:
            size -= nb_colors * 3
        yield RawBytes(self, "image_data", size, "Image data")

        if has_palette:
            yield PaletteRGB(self, "palette_8bits", nb_colors,
                             "Palette (8 bit)")
コード例 #12
0
ファイル: ole2.py プロジェクト: valnar1/SickGear
 def createFields(self):
     bytes = self.stream.readBytes(self.absolute_address, 4)
     if bytes == b"\0R\0\0":
         charset = "UTF-16-BE"
     else:
         charset = "UTF-16-LE"
     yield String(self, "name", 64, charset=charset, truncate="\0")
     yield UInt16(self, "namelen", "Length of the name")
     yield Enum(UInt8(self, "type", "Property type"), self.TYPE_NAME)
     yield Enum(UInt8(self, "decorator", "Decorator"), self.DECORATOR_NAME)
     yield SECT(self, "left")
     yield SECT(self, "right")
     yield SECT(self, "child",
                "Child node (valid for storage and root types)")
     yield GUID(self, "clsid",
                "CLSID of this storage (valid for storage and root types)")
     yield NullBytes(self, "flags", 4, "User flags")
     yield TimestampWin64(
         self, "creation",
         "Creation timestamp(valid for storage and root types)")
     yield TimestampWin64(
         self, "lastmod",
         "Modify timestamp (valid for storage and root types)")
     yield SECT(
         self, "start",
         "Starting SECT of the stream (valid for stream and root types)")
     if self["/header/bb_shift"].value == 9:
         yield filesizeHandler(
             UInt32(self, "size",
                    "Size in bytes (valid for stream and root types)"))
         yield NullBytes(self, "padding", 4)
     else:
         yield filesizeHandler(
             UInt64(self, "size",
                    "Size in bytes (valid for stream and root types)"))
コード例 #13
0
def parseTimeSignature(parser, size):
    yield UInt8(parser, "numerator", "Numerator of time signature")
    yield UInt8(parser, "denominator",
                "denominator of time signature 2=quarter 3=eighth, etc.")
    yield UInt8(parser, "nb_tick", "Number of ticks in metronome click")
    yield UInt8(parser, "nb_32nd_note",
                "Number of 32nd notes to the quarter note")
コード例 #14
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")
コード例 #15
0
ファイル: xm.py プロジェクト: valnar1/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")
コード例 #16
0
ファイル: tcpdump.py プロジェクト: valnar1/SickGear
    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)
コード例 #17
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)")
コード例 #18
0
 def createFields(self):
     yield String(self, "name", 20, strip='\0')
     yield GenericVector(self, "samples", 31, SampleInfo, "info")
     yield UInt8(self, "length")
     yield UInt8(self, "played_patterns_count")
     yield GenericVector(self, "patterns", 128, UInt8, "position")
     yield String(self, "type", 4)
コード例 #19
0
    def createFields(self):
        yield Bytes(self, "endian", 2, "Endian (\\xfe\\xff for little endian)")
        yield UInt16(self, "format", "Format (0)")
        yield UInt8(self, "os_version")
        yield UInt8(self, "os_revision")
        yield Enum(UInt16(self, "os_type"), OS_NAME)
        yield GUID(self, "format_id")
        yield UInt32(self, "section_count")
        if MAX_SECTION_COUNT < self["section_count"].value:
            raise ParserError("OLE2: Too much sections (%s)" %
                              self["section_count"].value)

        section_indexes = []
        for index in range(self["section_count"].value):
            section_index = SummaryIndex(self, "section_index[]")
            yield section_index
            section_indexes.append(section_index)

        for section_index in section_indexes:
            self.seekByte(section_index["offset"].value)
            yield SummarySection(self, "section[]")

        size = (self.size - self.current_size) // 8
        if 0 < size:
            yield NullBytes(self, "end_padding", size)
コード例 #20
0
    def createFields(self):
        yield Bytes(self, "signature", 4, r'ELF signature ("\x7fELF")')
        yield Enum(UInt8(self, "class", "Class"), self.CLASS_NAME)
        if self["class"].value == 1:
            ElfLongWord = UInt32
        else:
            ElfLongWord = UInt64
        yield Enum(UInt8(self, "endian", "Endian"), self.ENDIAN_NAME)
        yield UInt8(self, "file_version", "File version")
        yield Enum(UInt8(self, "osabi_ident", "OS/syscall ABI identification"),
                   self.OSABI_NAME)
        yield UInt8(self, "abi_version", "syscall ABI version")
        yield String(self, "pad", 7, "Pad")

        yield Enum(UInt16(self, "type", "File type"), self.TYPE_NAME)
        yield Enum(UInt16(self, "machine", "Machine type"), self.MACHINE_NAME)
        yield UInt32(self, "version", "ELF format version")
        yield textHandler(ElfLongWord(self, "entry", "Entry point"),
                          hexadecimal)
        yield ElfLongWord(self, "phoff", "Program header file offset")
        yield ElfLongWord(self, "shoff", "Section header file offset")
        yield UInt32(self, "flags", "Architecture-specific flags")
        yield UInt16(self, "ehsize", "Elf header size (this header)")
        yield UInt16(self, "phentsize", "Program header entry size")
        yield UInt16(self, "phnum", "Program header entry count")
        yield UInt16(self, "shentsize", "Section header entry size")
        yield UInt16(self, "shnum", "Section header entry count")
        yield UInt16(self, "shstrndx", "Section header string table index")
コード例 #21
0
ファイル: bplist.py プロジェクト: valnar1/SickGear
 def createFields(self):
     yield NullBytes(self, "unused", 6)
     yield UInt8(self, "offsetIntSize", "Size (in bytes) of offsets in the offset table")
     yield UInt8(self, "objectRefSize", "Size (in bytes) of object numbers in object references")
     yield UInt64(self, "numObjects", "Number of objects in this file")
     yield UInt64(self, "topObject", "Top-level object reference")
     yield UInt64(self, "offsetTableOffset", "File offset to the offset table")
コード例 #22
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)
コード例 #23
0
ファイル: pifv.py プロジェクト: valnar1/SickGear
    def createFields(self):
        # Header
        yield NullBytes(self, "zero_vector", 16)
        yield GUID(self, "fs_guid")
        yield UInt64(self, "volume_len")
        yield String(self, "signature", 4)
        yield UInt32(self, "attributes")
        yield UInt16(self, "header_len")
        yield UInt16(self, "checksum")
        yield UInt16(self, "ext_header_offset")
        yield UInt8(self, "reserved")
        yield UInt8(self, "revision")
        while True:
            bm = BlockMap(self, "block_map[]")
            yield bm
            if bm['num_blocks'].value == 0 and bm['len'].value == 0:
                break
        # TODO must handle extended header

        # Content
        while not self.eof:
            padding = paddingSize(self.current_size // 8, 8)
            if padding:
                yield PaddingBytes(self, "padding[]", padding)
            yield File(self, "file[]")
コード例 #24
0
 def createFields(self):
     yield UInt32(self, "data_offset")
     yield UInt8(self, "logical_width")
     yield UInt8(self, "unknown[]")
     yield UInt8(self, "unknown[]")
     yield UInt8(self, "unknown[]")
     yield UInt32(self, "width_pixels")
     yield UInt32(self, "height_pixels")
コード例 #25
0
ファイル: tcpdump.py プロジェクト: valnar1/SickGear
    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")
コード例 #26
0
def commentHeader(s):
    yield filesizeHandler(
        UInt16(s, "total_size", "Comment header size + comment size"))
    yield filesizeHandler(
        UInt16(s, "uncompressed_size", "Uncompressed comment size"))
    yield UInt8(s, "required_version", "RAR version needed to extract comment")
    yield UInt8(s, "packing_method", "Comment packing method")
    yield UInt16(s, "comment_crc16", "Comment CRC")
コード例 #27
0
ファイル: gzip_parser.py プロジェクト: valnar1/SickGear
    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"))
コード例 #28
0
ファイル: id3.py プロジェクト: valnar1/SickGear
 def createFields(self):
     yield Enum(UInt8(self, "charset"), ID3_StringCharset.charset_desc)
     charset = getCharset(self["charset"])
     yield CString(self, "mime", "MIME type", charset=charset)
     yield Enum(UInt8(self, "pict_type"), ID3_Picture23.pict_type_name)
     yield CString(self, "description", charset=charset)
     size = (self._size - self._current_size) // 8
     if size:
         yield RawBytes(self, "img_data", size)
コード例 #29
0
ファイル: jpeg.py プロジェクト: valnar1/SickGear
    def createFields(self):
        yield UInt8(self, "precision")

        yield UInt16(self, "height")
        yield UInt16(self, "width")
        yield UInt8(self, "nr_components")

        for index in range(self["nr_components"].value):
            yield SOFComponent(self, "component[]")
コード例 #30
0
def avInfoHeader(s):
    yield filesizeHandler(UInt16(s, "total_size", "Total block size"))
    yield UInt8(s,
                "version",
                "Version needed to decompress",
                handler=hexadecimal)
    yield UInt8(s, "method", "Compression method", handler=hexadecimal)
    yield UInt8(s, "av_version", "Version for AV", handler=hexadecimal)
    yield UInt32(s, "av_crc", "AV info CRC32", handler=hexadecimal)