Example #1
0
    def createFields(self):
        # Header
        yield String(self, "magic", 3, "File magic code", charset="ASCII")
        yield String(self, "version", 3, "GIF version", charset="ASCII")

        yield ScreenDescriptor(self, "screen")
        if self["screen/global_map"].value:
            bpp = (self["screen/bpp"].value + 1)
            yield PaletteRGB(self, "color_map", 1 << bpp, "Color map")
            self.color_map = self["color_map"]
        else:
            self.color_map = None

        self.images = []
        while True:
            code = Enum(Character(self, "separator[]", "Separator code"),
                        self.separator_name)
            yield code
            code = code.value
            if code == "!":
                yield Extension(self, "extensions[]")
            elif code == ",":
                yield Image(self, "image[]")
            elif code == ";":
                # GIF Terminator
                break
            else:
                raise ParserError("Wrong GIF image separator: 0x%02X" %
                                  ord(code))
Example #2
0
 def createFields(self):
     addr = self.absolute_address
     len = self.stream.searchBytesLength(':', False, addr,
                                         addr + (MAX_STRING_LENGTH + 1) * 8)
     if len is None:
         raise ParserError("Torrent: unable to find string separator (':')")
     if not len:
         raise ParserError("Torrent: error: no string length!")
     val = String(self, "length", len, "String length")
     yield val
     try:
         len = int(val.value)
     except ValueError:
         len = -1
     if len < 0:
         raise ParserError(
             "Invalid string length (%s)" %
             makePrintable(val.value, "ASCII", to_unicode=True))
     yield String(self, "separator", 1, "String length/value separator")
     if not len:
         self.info("Empty string: len=%i" % len)
         return
     if len < 512:
         yield String(self,
                      "value",
                      len,
                      "String value",
                      charset="ISO-8859-1")
     else:
         # Probably raw data
         yield RawBytes(self, "value", len, "Raw data")
Example #3
0
 def createFields(self):
     # Headers
     yield String(self, "header", 6, "Header (Exif\\0\\0)", charset="ASCII")
     if self["header"].value != "Exif\0\0":
         raise ParserError("Invalid EXIF signature!")
     yield String(self, "byte_order", 2, "Byte order", charset="ASCII")
     if self["byte_order"].value not in ("II", "MM"):
         raise ParserError("Invalid endian!")
     if self["byte_order"].value == "II":
         self.endian = LITTLE_ENDIAN
     else:
         self.endian = BIG_ENDIAN
     yield UInt16(self, "version", "TIFF version number")
     yield UInt32(self, "img_dir_ofs", "Next image directory offset")
     while not self.eof:
         addr = self.absolute_address + self.current_size
         tag = self.stream.readBits(addr, 16, NETWORK_ENDIAN)
         if tag == 0xFFD8:
             size = (self._size - self.current_size) // 8
             yield SubFile(self,
                           "thumbnail",
                           size,
                           "Thumbnail (JPEG file)",
                           mime_type="image/jpeg")
             break
         elif tag == 0xFFFF:
             break
         yield ExifIFD(self, "ifd[]", "IFD")
     padding = self.seekBit(self._size)
     if padding is not None:
         yield padding
Example #4
0
 def createFields(self):
     size = self._size / 8
     # TODO: Strings charset?
     if self.stream.readBytes(self.absolute_address, 9) == "PeakValue":
         yield String(self, "text", 9, "Text")
         size -= 9
     yield String(self, "content", size, "Content")
Example #5
0
 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")
Example #6
0
    def createFields(self):
        yield String(self,
                     "signature",
                     4,
                     "AVI header (RIFF)",
                     charset="ASCII")
        yield filesizeHandler(UInt32(self, "filesize", "File size"))
        yield String(self,
                     "type",
                     4,
                     "Content type (\"AVI \", \"WAVE\", ...)",
                     charset="ASCII")

        # Choose chunk type depending on file type
        try:
            chunk_cls = self.VALID_TYPES[self["type"].value][0]
        except KeyError:
            chunk_cls = Chunk

        # Parse all chunks up to filesize
        while self.current_size < self["filesize"].value * 8 + 8:
            yield chunk_cls(self, "chunk[]")
        if not self.eof:
            yield RawBytes(self, "padding[]",
                           (self.size - self.current_size) / 8)
Example #7
0
    def createFields(self):
        yield String(self,
                     "signature",
                     4,
                     'Format signature (".snd")',
                     charset="ASCII")
        yield UInt32(self, "data_ofs", "Data offset")
        yield filesizeHandler(UInt32(self, "data_size", "Data size"))
        yield Enum(UInt32(self, "codec", "Audio codec"), self.CODEC_NAME)
        yield displayHandler(
            UInt32(self, "sample_rate", "Number of samples/second"),
            humanFrequency)
        yield UInt32(self, "channels", "Number of interleaved channels")

        size = self["data_ofs"].value - self.current_size // 8
        if 0 < size:
            yield String(self,
                         "info",
                         size,
                         "Information",
                         strip=" \0",
                         charset="ISO-8859-1")

        size = min(self["data_size"].value,
                   (self.size - self.current_size) // 8)
        yield RawBytes(self, "audio_data", size, "Audio data")
Example #8
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)
Example #9
0
 def createFields(self):
     yield RawBytes(self, "marker", len(self.MAGIC))
     yield LineEnd(self, "line_end[]")
     yield String(self, "start_attribute_marker", 2)
     addr = self.absolute_address + self.current_size
     while self.stream.readBytes(addr, 2) != '>>':
         t = PDFName(self, "type[]")
         yield t
         name = t.value
         self.info("Parsing PDFName '%s'" % name)
         if name == "Size":
             yield PDFNumber(self, "size",
                             "Entries in the file cross-reference section")
         elif name == "Prev":
             yield PDFNumber(self, "offset")
         elif name == "Root":
             yield Catalog(self, "object_catalog")
         elif name == "Info":
             yield Catalog(self, "info")
         elif name == "ID":
             yield PDFArray(self, "id")
         elif name == "Encrypt":
             yield PDFDictionary(self, "decrypt")
         else:
             raise ParserError("Don't know trailer type '%s'" % name)
         addr = self.absolute_address + self.current_size
     yield String(self, "end_attribute_marker", 2)
     yield LineEnd(self, "line_end[]")
     yield String(self, "start_xref", 9)
     yield LineEnd(self, "line_end[]")
     yield PDFNumber(self, "cross_ref_table_start_address")
     yield LineEnd(self, "line_end[]")
     yield String(self, "end_marker", len(ENDMAGIC))
     yield LineEnd(self, "line_end[]")
Example #10
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)")
Example #11
0
 def createFields(self):
     yield String(self, "array_start", 1)
     while self.stream.readBytes(self.absolute_address + self.current_size,
                                 1) != ']':
         for field in parsePDFType(self):
             yield field
     yield String(self, "array_end", 1)
Example #12
0
 def createFields(self):
     #TODO: This structure is normally divided in two parts:
     # _reiserfs_super_block_v1
     # _reiserfs_super_block
     # It will be divided later to easily support older version of the first part
     yield UInt32(self, "block_count", "Number of blocks")
     yield UInt32(self, "free_blocks", "Number of free blocks")
     yield UInt32(self, "root_block", "Root block number")
     yield Journal_params(self, "Journal parameters")
     yield UInt16(self, "blocksize", "Size of a block")
     yield UInt16(self, "oid_maxsize", "Max size of object id array")
     yield UInt16(self, "oid_cursize", "Current size of object id array")
     yield Enum(UInt16(self, "umount_state", "Filesystem umounted or not"), self.UMOUNT_STATE)
     yield String(self, "magic", 10, "Magic string", strip="\0")
     #TODO: change the type of s_fs_state in Enum to have more details about this fsck state
     yield UInt16(self, "fs_state", "Rebuilding phase of fsck ")
     yield Enum(UInt32(self, "hash_function", "Hash function to sort names in a directory"), self.HASH_FUNCTIONS)
     yield UInt16(self, "tree_height", "Height of disk tree")
     yield UInt16(self, "bmap_nr", "Amount of bitmap blocks needed to address each block of file system")
     #TODO: find a good description for this field
     yield UInt16(self, "version", "Field only reliable on filesystem with non-standard journal")
     yield UInt16(self, "reserved_for_journal", "Size in blocks of journal area on main device")
     #TODO: same as above
     yield UInt32(self, "inode_generation", "No description")
     #TODO: same as above and should be an enum field
     yield UInt32(self, "flags", "No description")
     #TODO: Create a special Type to format this id
     yield RawBytes(self, "uuid", 16, "Filesystem unique identifier")
     yield String(self, "label", 16, "Filesystem volume label", strip="\0")
     yield NullBytes(self, "unused", 88)
Example #13
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
Example #14
0
 def createFields(self):
     yield UInt16(self, "length", "Length of this string")
     if self.root.hasUnicodeNames():
         yield String(self,
                      "data",
                      self["length"].value * 2,
                      charset="UTF-16-LE")
     else:
         yield String(self, "data", self["length"].value, charset="ASCII")
Example #15
0
 def createFields(self):
     yield String(self, "marker", 5, MAGIC)
     length = getLineEnd(self, 4)
     if length != None:
         #self.info("Found at position %08X" % len)
         yield String(self, "version", length - 1)
         yield LineEnd(self, "line_end")
     else:
         self.warning("Can't determine version!")
Example #16
0
 def createFields(self):
     yield String(self, "dict_start", 2)
     while not self.eof:
         addr = self.absolute_address + self.current_size
         if self.stream.readBytes(addr, 2) != '>>':
             for field in parsePDFType(self):
                 yield field
         else:
             break
     yield String(self, "dict_end", 2)
Example #17
0
 def createFields(self):
     yield String(self,
                  "start",
                  1,
                  "Dictionary start delimiter (d)",
                  charset="ASCII")
     while self.stream.readBytes(self.absolute_address + self.current_size,
                                 1) != "e":
         yield DictionaryItem(self, "item[]")
     yield String(self, "end", 1, "Dictionary end delimiter")
Example #18
0
 def createFields(self):
     yield String(self, "signature", 4, "Signature (FORM)", charset="ASCII")
     yield filesizeHandler(UInt32(self, "filesize"))
     yield String(self,
                  "type",
                  4,
                  "Form type (AIFF or AIFC)",
                  charset="ASCII")
     while not self.eof:
         yield Chunk(self, "chunk[]")
Example #19
0
 def createFields(self):
     yield textHandler(UInt8(self, "version"), hexadecimal)
     yield RawBytes(self, "flags", 3)
     yield String(self, "subtype", 8)
     yield String(self, "manufacturer", 4)
     yield UInt32(self, "res_flags")
     yield UInt32(self, "res_flags_mask")
     if self.root.is_mpeg4:
         yield CString(self, "name")
     else:
         yield PascalString8(self, "name")
Example #20
0
    def createFields(self):
        yield self.getType()
        yield String(self, "filename", 12, strip='\0')

        for field in self.getInstrumentFields():
            yield field

        yield String(self, "name", 28, strip='\0')
        yield String(self,
                     "marker",
                     4,
                     "Either 'SCRS' or '(empty)'",
                     strip='\0')
Example #21
0
 def createFields(self):
     if not self.LFN:
         yield String(self, "name", 8, "DOS file name (padded with spaces)",
             strip=' ', charset="ASCII")
         yield String(self, "ext", 3, "DOS file extension (padded with spaces)",
             strip=' ', charset="ASCII")
         yield Bit(self, "read_only")
         yield Bit(self, "hidden")
         yield Bit(self, "system")
         yield Bit(self, "volume_label")
         yield Bit(self, "directory")
         yield Bit(self, "archive")
         yield Bit(self, "device")
         yield Bit(self, "unused")
         yield RawBytes(self, "reserved", 1, "Something about the case")
         yield Date(self, "create")
         yield Date(self, "access")
         if self.parent.parent.version > 16:
             yield UInt16(self, "cluster_hi")
         else:
             yield UInt16(self, "ea_index")
         yield Date(self, "modify")
         yield UInt16(self, "cluster_lo")
         size = UInt32(self, "size")
         yield size
         if self.process:
             del self.process
             target_size = size.value
             if self["directory"].value:
                 if target_size:
                     size.error("(FAT) value must be zero")
                     target_size = 0
             elif not target_size:
                 return
             self.target_size = 8 * target_size
             yield InodeLink(self, "data")
     else:
         yield UInt8(self, "seq_no", "Sequence Number")
         yield String(self, "name[]", 10, "(5 UTF-16 characters)",
             charset="UTF-16-LE")
         yield UInt8(self, "magic", "Magic number (15)")
         yield NullBytes(self, "reserved", 1, "(always 0)")
         yield UInt8(self, "checksum", "Checksum of DOS file name")
         yield String(self, "name[]", 12, "(6 UTF-16 characters)",
             charset="UTF-16-LE")
         yield UInt16(self, "first_cluster", "(always 0)")
         yield String(self, "name[]",  4, "(2 UTF-16 characters)",
             charset="UTF-16-LE")
Example #22
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
Example #23
0
    def createFields(self):
        yield String(self, "name", 32, strip="\0")
        yield UInt32(self, "id")
        yield UInt32(self, "geometry_mode")
        yield UInt32(self, "lighting_mode")
        yield UInt32(self, "texture_mode")
        yield UInt32(self, "nmesh_vertices")
        yield UInt32(self, "ntexture_vertices")
        yield UInt32(self, "nfaces")

        nb_vert = self["nmesh_vertices"].value
        if nb_vert:
            yield Vector(self, "vertices", nb_vert, Vertex, "vertex")
        if self["ntexture_vertices"].value:
            yield Vector(self, "texture vertices",
                         self["ntexture_vertices"].value, MapUV,
                         "texture_vertex")
        if nb_vert:
            yield Vector(self, "light vertices", nb_vert, Float32,
                         "extra_light")
            yield Vector(self, "unknown[]", nb_vert, Float32, "unknown")
        if self["nfaces"].value:
            yield Vector(self, "faces", self["nfaces"].value, Face, "face")
        if nb_vert:
            yield Vector(self, "vertex normals", nb_vert, Vertex, "normal")

        yield UInt32(self, "has_shadow")
        yield Float32(self, "unknown[]")
        yield Float32(self, "radius")
        yield Vertex(self, "unknown[]")
        yield Vertex(self, "unknown[]")
Example #24
0
 def createFields(self):
     yield String(self, "name", 32, strip="\0")
     yield PaddingBytes(self, "unknown[]", 32, pattern="\xCC")
     yield UInt32(self, "flags")
     yield UInt32(self, "id")
     yield UInt32(self, "type")
     yield Int32(self, "mesh_id")
     yield UInt32(self, "depth")
     yield Int32(self, "parent_offset")
     yield UInt32(self, "nchildren")
     yield UInt32(self, "first_child_offset")
     yield UInt32(self, "next_sibling_offset")
     yield Vertex(self, "pivot")
     yield Vertex(self, "position")
     yield Float32(self, "pitch")
     yield Float32(self, "yaw")
     yield Float32(self, "roll")
     for index in xrange(4):
         yield Vertex(self, "unknown_vertex[]")
     if self["parent_offset"].value != 0:
         yield UInt32(self, "parent_id")
     if self["first_child_offset"].value != 0:
         yield UInt32(self, "first_child_id")
     if self["next_sibling_offset"].value != 0:
         yield UInt32(self, "next_sibling_id")
Example #25
0
    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[]")
Example #26
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))
Example #27
0
def parseCommon(self):
    yield UInt16(self, "nb_channel")
    yield UInt32(self, "nb_sample")
    yield UInt16(self, "sample_size")
    yield Float80(self, "sample_rate")
    yield Enum(String(self, "codec", 4, strip="\0", charset="ASCII"),
               CODEC_NAME)
Example #28
0
    def createFields(self):
        # Signature + version
        yield String(self, "header", 3, "Header (ID3)", charset="ASCII")
        yield UInt8(self, "ver_major", "Version (major)")
        yield UInt8(self, "ver_minor", "Version (minor)")

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

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

        # Size
        yield ID3_Size(self, "size")

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

        # Search first byte of the MPEG file
        padding = self.seekBit(self._size)
        if padding:
            yield padding
Example #29
0
    def createFields(self):
        yield String(self,
                     "signature",
                     4,
                     "PSD signature (8BPS)",
                     charset="ASCII")
        yield UInt16(self, "version")
        yield NullBytes(self, "reserved[]", 6)
        yield UInt16(self, "nb_channels")
        yield UInt32(self, "width")
        yield UInt32(self, "height")
        yield UInt16(self, "depth")
        yield Enum(UInt16(self, "color_mode"), self.COLOR_MODE)

        # Mode data
        yield UInt32(self, "mode_data_size")
        size = self["mode_data_size"].value
        if size:
            yield RawBytes(self, "mode_data", size)

        # Resources
        yield Config(self, "config")

        # Reserved
        yield UInt32(self, "reserved_data_size")
        size = self["reserved_data_size"].value
        if size:
            yield RawBytes(self, "reserved_data", size)

        yield Enum(UInt16(self, "compression"), self.COMPRESSION_NAME)

        size = (self.size - self.current_size) // 8
        if size:
            yield RawBytes(self, "end", size)
Example #30
0
 def createFields(self):
     yield String(self,
                  "text",
                  self._size / 8,
                  "Text",
                  charset="ISO-8859-1",
                  strip=self.STRIP)