Exemplo n.º 1
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)
Exemplo n.º 2
0
    def createFields(self):
        yield String(self, "header_id", 4, "Playlist List 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 xrange(self["data_object_child_count"].value):
            yield DataObject(self, "mhod[]")

        for i in xrange(self["playlist_count"].value):
            yield PlaylistItem(self, "playlist_item[]")
Exemplo n.º 3
0
    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)")
Exemplo n.º 4
0
 def createFields(self):
     bytes = self.stream.readBytes(self.absolute_address, 4)
     if bytes == "\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)"))
Exemplo n.º 5
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)
Exemplo n.º 6
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))
Exemplo n.º 7
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")
Exemplo n.º 8
0
 def createFields(self):
     yield Enum(UInt16(self, "platformID"), PLATFORM_NAME)
     yield UInt16(self, "encodingID")
     yield UInt16(self, "languageID")
     yield Enum(UInt16(self, "nameID"), NAMEID_NAME)
     yield UInt16(self, "length")
     yield UInt16(self, "offset")
Exemplo n.º 9
0
    def createFields(self):
        # Header
        yield PaddingBits(self,
                          "sync",
                          11,
                          "Synchronize bits (set to 1)",
                          pattern=1)
        yield Enum(Bits(self, "version", 2, "MPEG audio version"),
                   self.VERSION_NAME)
        yield Enum(Bits(self, "layer", 2, "MPEG audio layer"), self.LAYER_NAME)
        yield Bit(self, "crc16", "No CRC16 protection?")

        # Rates and padding
        yield Bits(self, "bit_rate", 4, "Bit rate")
        yield Bits(self, "sampling_rate", 2, "Sampling rate")
        yield Bit(self, "use_padding", "Stream field use padding?")
        yield Bit(self, "extension", "Extension")

        # Channel mode, mode extension, copyright, ...
        yield Enum(Bits(self, "channel_mode", 2, "Channel mode"),
                   self.CHANNEL_MODE_NAME)
        yield Bits(self, "mode_ext", 2, "Mode extension")
        yield Bit(self, "copyright", "Is copyrighted?")
        yield Bit(self, "original", "Is original?")
        yield Enum(Bits(self, "emphasis", 2, "Emphasis"), self.EMPHASIS_NAME)

        size = (self.size - self.current_size) / 8
        if size:
            yield RawBytes(self, "data", size)
Exemplo n.º 10
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
Exemplo n.º 11
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)
Exemplo n.º 12
0
 def createFields(self):
     self.osconfig = self.parent.osconfig
     if True:
         yield Enum(Bits(self, "type", 12), self.TYPE_NAME)
         yield Bit(self, "is_vector")
         yield NullBits(self, "padding", 32 - 12 - 1)
     else:
         yield Enum(Bits(self, "type", 32), self.TYPE_NAME)
     tag = self["type"].value
     kw = {}
     try:
         handler = self.TYPE_INFO[tag][1]
         if handler == PascalString32:
             osconfig = self.osconfig
             if tag == self.TYPE_LPSTR:
                 kw["charset"] = osconfig.charset
             else:
                 kw["charset"] = osconfig.utf16
         elif handler == TimestampWin64:
             if self.description == "TotalEditingTime":
                 handler = TimedeltaWin64
     except LookupError:
         handler = None
     if not handler:
         raise ParserError("OLE2: Unable to parse property of type %s" \
             % self["type"].display)
     if self["is_vector"].value:
         yield UInt32(self, "count")
         for index in xrange(self["count"].value):
             yield handler(self, "item[]", **kw)
     else:
         yield handler(self, "value", **kw)
         self.createValue = lambda: self["value"].value
Exemplo n.º 13
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
Exemplo n.º 14
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)
Exemplo n.º 15
0
 def createFields(self):
     yield Enum(UInt16(self, "packet_type"), self.packet_type_name)
     yield UInt16(self, "addr_type", "Link-layer address type")
     yield UInt16(self, "addr_length", "Link-layer address length")
     length = self["addr_length"].value
     length = 8  # FIXME: Should we use addr_length or not?
     if length:
         yield RawBytes(self, "source", length)
     yield Enum(UInt16(self, "protocol"), self.PROTO_DESC)
Exemplo n.º 16
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"))
Exemplo n.º 17
0
 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)
Exemplo n.º 18
0
 def createFields(self):
     yield Enum(UInt8(self, "charset"), ID3_StringCharset.charset_desc)
     charset = getCharset(self["charset"])
     yield String(self, "img_fmt", 3, charset="ASCII")
     yield Enum(UInt8(self, "pict_type"), self.pict_type_name)
     yield CString(self, "text", "Text", charset=charset, strip=" \0")
     size = (self._size - self._current_size) / 8
     if size:
         yield RawBytes(self, "img_data", size)
Exemplo n.º 19
0
def parseFontHeader(self):
    yield UInt16(self, "maj_ver", "Major version")
    yield UInt16(self, "min_ver", "Minor version")
    yield UInt16(self, "font_maj_ver", "Font major version")
    yield UInt16(self, "font_min_ver", "Font minor version")
    yield textHandler(UInt32(self, "checksum"), hexadecimal)
    yield Bytes(self, "magic", 4, r"Magic string (\x5F\x0F\x3C\xF5)")
    if self["magic"].value != "\x5F\x0F\x3C\xF5":
        raise ParserError("TTF: invalid magic of font header")

    # Flags
    yield Bit(self, "y0", "Baseline at y=0")
    yield Bit(self, "x0", "Left sidebearing point at x=0")
    yield Bit(self, "instr_point", "Instructions may depend on point size")
    yield Bit(self, "ppem", "Force PPEM to integer values for all")
    yield Bit(self, "instr_width", "Instructions may alter advance width")
    yield Bit(self, "vertical", "e laid out vertically?")
    yield PaddingBits(self, "reserved[]", 1)
    yield Bit(self, "linguistic",
              "Requires layout for correct linguistic rendering?")
    yield Bit(self, "gx", "Metamorphosis effects?")
    yield Bit(self, "strong", "Contains strong right-to-left glyphs?")
    yield Bit(self, "indic", "contains Indic-style rearrangement effects?")
    yield Bit(self, "lossless",
              "Data is lossless (Agfa MicroType compression)")
    yield Bit(self, "converted", "Font converted (produce compatible metrics)")
    yield Bit(self, "cleartype", "Optimised for ClearType")
    yield Bits(self, "adobe", 2, "(used by Adobe)")

    yield UInt16(self, "unit_per_em", "Units per em")
    if not (16 <= self["unit_per_em"].value <= 16384):
        raise ParserError("TTF: Invalid unit/em value")
    yield UInt32(self, "created_high")
    yield TimestampMac32(self, "created")
    yield UInt32(self, "modified_high")
    yield TimestampMac32(self, "modified")
    yield UInt16(self, "xmin")
    yield UInt16(self, "ymin")
    yield UInt16(self, "xmax")
    yield UInt16(self, "ymax")

    # Mac style
    yield Bit(self, "bold")
    yield Bit(self, "italic")
    yield Bit(self, "underline")
    yield Bit(self, "outline")
    yield Bit(self, "shadow")
    yield Bit(self, "condensed", "(narrow)")
    yield Bit(self, "expanded")
    yield PaddingBits(self, "reserved[]", 9)

    yield UInt16(self, "lowest", "Smallest readable size in pixels")
    yield Enum(UInt16(self, "font_dir", "Font direction hint"), DIRECTION_NAME)
    yield Enum(UInt16(self, "ofst_format"), {0: "short offsets", 1: "long"})
    yield UInt16(self, "glyph_format", "(=0)")
Exemplo n.º 20
0
    def createFields(self):
        yield String(self, "magic", 4, "Signature (BLP1)")
        yield Enum(UInt32(self, "compression"), {
            0: "JPEG Compression",
            1: "Uncompressed"
        })
        yield UInt32(self, "flags")
        yield UInt32(self, "width")
        yield UInt32(self, "height")
        yield Enum(
            UInt32(self, "type"), {
                3: "Uncompressed Index List + Alpha List",
                4: "Uncompressed Index List + Alpha List",
                5: "Uncompressed Index List"
            })
        yield UInt32(self, "subtype")
        for i in xrange(16):
            yield UInt32(self, "mipmap_offset[]")
        for i in xrange(16):
            yield UInt32(self, "mipmap_size[]")

        compression = self["compression"].value
        image_type = self["type"].value
        width = self["width"].value
        height = self["height"].value

        if compression == 0:  # JPEG Compression
            yield UInt32(self, "jpeg_header_len")
            yield RawBytes(self, "jpeg_header", self["jpeg_header_len"].value,
                           "Shared JPEG Header")
        else:
            yield PaletteRGBA(self, "palette", 256)

        offsets = self.array("mipmap_offset")
        sizes = self.array("mipmap_size")
        for i in xrange(16):
            if not offsets[i].value or not sizes[i].value:
                continue
            padding = self.seekByte(offsets[i].value)
            if padding:
                yield padding
            if compression == 0:
                yield RawBytes(
                    self, "mipmap[%i]" % i, sizes[i].value,
                    "JPEG data, append to header to recover complete image")
            elif compression == 1:
                yield Generic2DArray(self, "mipmap_indexes[%i]" % i, width,
                                     height, PaletteIndex, "row", "index",
                                     "Indexes into the palette")
                if image_type in (3, 4):
                    yield Generic2DArray(self, "mipmap_alphas[%i]" % i, width,
                                         height, UInt8, "row", "alpha",
                                         "Alpha values")
            width /= 2
            height /= 2
Exemplo n.º 21
0
def parseAudio(parent, size):
    yield Enum(Bits(parent, "codec", 4, "Audio codec"), AUDIO_CODEC_NAME)
    yield Enum(Bits(parent, "sampling_rate", 2, "Sampling rate"), SAMPLING_RATE_TEXT)
    yield Bit(parent, "is_16bit", "16-bit or 8-bit per sample")
    yield Bit(parent, "is_stereo", "Stereo or mono channel")

    size -= 1
    if 0 < size:
        if parent["codec"].value == AUDIO_CODEC_MP3 :
            yield Frame(parent, "music_data", size=size*8)
        else:
            yield RawBytes(parent, "music_data", size)
Exemplo n.º 22
0
 def createFields(self):
     yield filesizeHandler(UInt32(self, "size"))
     yield Enum(Int32(self, "format"), self.FORMAT_NAME)
     if self["format"].value == self.FORMAT_CLIPBOARD:
         yield Enum(UInt32(self, "dib_format"), self.DIB_FORMAT)
         if self["dib_format"].value == self.DIB_BMP:
             yield BmpHeader(self, "bmp_header")
             size = (self.size - self.current_size) // 8
             yield parseImageData(self, "pixels", size, self["bmp_header"])
             return
     size = (self.size - self.current_size) // 8
     if size:
         yield RawBytes(self, "data", size)
Exemplo n.º 23
0
 def createFields(self):
     if self.stream.readBytes(self.absolute_address, 5) != "Adobe":
         yield RawBytes(self, "raw", self.size // 8, "Raw data")
         return
     yield String(self, "adobe", 5, "\"Adobe\" string", charset="ASCII")
     yield UInt16(self, "version", "DCT encoder version")
     yield Enum(Bit(self, "flag00"), {
         False: "Chop down or subsampling",
         True: "Blend"
     })
     yield NullBits(self, "flags0_reserved", 15)
     yield NullBytes(self, "flags1", 2)
     yield Enum(
         UInt8(self, "color_transform", "Colorspace transformation code"),
         self.COLORSPACE_TRANSFORMATION)
Exemplo n.º 24
0
 def createFields(self):
     yield Enum(Bits(self, "class", 2), self.CLASS_DESC)
     yield Enum(Bit(self, "form"), self.FORM_DESC)
     if self['class'].value == 0:
         yield Enum(Bits(self, "type", 5), self.TYPE_DESC)
     else:
         yield Bits(self, "type", 5)
     yield ASNInteger(self, "size", "Size in bytes")
     size = self["size"].value
     if size:
         if self._handler:
             for field in self._handler(self, size):
                 yield field
         else:
             yield RawBytes(self, "raw", size)
Exemplo n.º 25
0
 def createFields(self):
     if self["../.."].name.startswith("doc_summary"):
         enum = self.DOCUMENT_PROPERTY
     else:
         enum = self.COMPONENT_PROPERTY
     yield Enum(UInt32(self, "id"), enum)
     yield UInt32(self, "offset")
Exemplo n.º 26
0
    def createFields(self):
        yield Bytes(self, "endian", 2, "Endian (0xFF 0xFE for Intel)")
        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 xrange(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)
Exemplo n.º 27
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")
Exemplo n.º 28
0
    def createFields(self):
        yield Bit(self, "has_private")
        yield Bit(self, "has_pack_lgth")
        yield Bit(self, "has_pack_seq")
        yield Bit(self, "has_pstd_buffer")
        yield Bits(self, "sync[]", 3)  # =7
        yield Bit(self, "has_extension2")

        if self["has_private"].value:
            yield RawBytes(self, "private", 16)

        if self["has_pack_lgth"].value:
            yield UInt8(self, "pack_lgth")

        if self["has_pack_seq"].value:
            yield Bit(self, "sync[]")  # =True
            yield Bits(self, "pack_seq_counter", 7)
            yield Bit(self, "sync[]")  # =True
            yield Bit(self, "mpeg12_id")
            yield Bits(self, "orig_stuffing_length", 6)

        if self["has_pstd_buffer"].value:
            yield Bits(self, "sync[]", 2)  # =1
            yield Enum(Bit(self, "pstd_buffer_scale"), {
                True: "128 bytes",
                False: "1024 bytes"
            })
            yield Bits(self, "pstd_size", 13)
Exemplo n.º 29
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)
Exemplo n.º 30
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))