示例#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)
示例#2
0
 def createFields(self):
     yield ABCMultinameIndex(self, "name_index")
     yield Enum(Bits(self, "kind", 4), self.TRAIT_KIND)
     yield Enum(Bit(self, "is_final"), {True: 'final', False: 'virtual'})
     yield Enum(Bit(self, "is_override"), {True: 'override', False: 'new'})
     yield Bit(self, "has_metadata")
     yield Bits(self, "unused", 1)
     kind = self["kind"].value
     if kind in (0, 6):  # slot, const
         yield FlashU30(self, "slot_id")
         yield ABCMultinameIndex(self, "type_index")
         ### TODO reference appropriate constant pool using value_kind
         yield FlashU30(self, "value_index")
         if self['value_index'].value != 0:
             yield UInt8(self, "value_kind")
     elif kind in (1, 2, 3):  # method, getter, setter
         yield FlashU30(self, "disp_id")
         yield ABCMethodIndex(self, "method_info")
     elif kind == 4:  # class
         yield FlashU30(self, "disp_id")
         yield FlashU30(self, "class_info")
     elif kind == 5:  # function
         yield FlashU30(self, "disp_id")
         yield ABCMethodIndex(self, "method_info")
     if self['has_metadata'].value:
         yield ABCObjectArray(self, "metadata", FlashU30)
示例#3
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
示例#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)"))
示例#5
0
 def createFields(self):
     yield Enum(Bits(self, "compression_method", 4), {
         8: "deflate",
         15: "reserved"
     })  # CM
     yield Bits(self, "compression_info", 4,
                "base-2 log of the window size")  # CINFO
     yield Bits(self, "flag_check_bits", 5)  # FCHECK
     yield Bit(self, "flag_dictionary_present")  # FDICT
     yield Enum(
         Bits(self, "flag_compression_level", 2),  # FLEVEL
         {
             0: "Fastest",
             1: "Fast",
             2: "Default",
             3: "Maximum, Slowest"
         })
     if self["flag_dictionary_present"].value:
         yield textHandler(
             UInt32(self, "dict_checksum",
                    "ADLER32 checksum of dictionary information"),
             hexadecimal)
     yield DeflateData(self,
                       "data",
                       self.stream,
                       description="Compressed Data")
     yield textHandler(
         UInt32(self, "data_checksum",
                "ADLER32 checksum of compressed data"), hexadecimal)
示例#6
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")
示例#7
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)
示例#8
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")
示例#9
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[]")
示例#10
0
    def createFields(self):
        yield textHandler(UInt32(self, "magic", "File information magic (0xFEEF04BD)"), hexadecimal)
        if self["magic"].value != 0xFEEF04BD:
            raise ParserError("EXE resource: invalid file info magic")
        yield Version(self, "struct_ver", "Structure version (1.0)")
        yield Version(self, "file_ver_ms", "File version MS")
        yield Version(self, "file_ver_ls", "File version LS")
        yield Version(self, "product_ver_ms", "Product version MS")
        yield Version(self, "product_ver_ls", "Product version LS")
        yield textHandler(UInt32(self, "file_flags_mask"), hexadecimal)

        yield Bit(self, "debug")
        yield Bit(self, "prerelease")
        yield Bit(self, "patched")
        yield Bit(self, "private_build")
        yield Bit(self, "info_inferred")
        yield Bit(self, "special_build")
        yield NullBits(self, "reserved", 26)

        yield Enum(textHandler(UInt16(self, "file_os_major"), hexadecimal), MAJOR_OS_NAME)
        yield Enum(textHandler(UInt16(self, "file_os_minor"), hexadecimal), MINOR_OS_NAME)
        yield Enum(textHandler(UInt32(self, "file_type"), hexadecimal), FILETYPE_NAME)
        field = textHandler(UInt32(self, "file_subfile"), hexadecimal)
        if field.value == FILETYPE_DRIVER:
            field = Enum(field, DRIVER_SUBTYPE_NAME)
        elif field.value == FILETYPE_FONT:
            field = Enum(field, FONT_SUBTYPE_NAME)
        yield field
        yield TimestampUnix32(self, "date_ms")
        yield TimestampUnix32(self, "date_ls")
示例#11
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)
示例#12
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)
 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
示例#14
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")
示例#15
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
示例#16
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))
示例#17
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)")
示例#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"))
示例#19
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)
示例#20
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)
示例#21
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)
 def createFields(self):
     yield UInt32(self, "inodes_count", "Inodes count")
     yield UInt32(self, "blocks_count", "Blocks count")
     yield UInt32(self, "r_blocks_count", "Reserved blocks count")
     yield UInt32(self, "free_blocks_count", "Free blocks count")
     yield UInt32(self, "free_inodes_count", "Free inodes count")
     yield UInt32(self, "first_data_block", "First data block")
     yield UInt32(self, "log_block_size", "Block size")
     yield UInt32(self, "log_frag_size", "Fragment size")
     yield UInt32(self, "blocks_per_group", "Blocks per group")
     yield UInt32(self, "frags_per_group", "Fragments per group")
     yield UInt32(self, "inodes_per_group", "Inodes per group")
     yield TimestampUnix32(self, "mtime", "Mount time")
     yield TimestampUnix32(self, "wtime", "Write time")
     yield UInt16(self, "mnt_count", "Mount count")
     yield UInt16(self, "max_mnt_count", "Max mount count")
     yield String(self, "magic", 2, "Magic number (0x53EF)")
     yield Enum(UInt16(self, "state", "File system state"), self.state_desc)
     yield Enum(UInt16(self, "errors", "Behaviour when detecting errors"),
                self.error_handling_desc)
     yield UInt16(self, "minor_rev_level", "Minor revision level")
     yield TimestampUnix32(self, "last_check", "Time of last check")
     yield textHandler(
         UInt32(self, "check_interval", "Maximum time between checks"),
         self.postMaxTime)
     yield Enum(UInt32(self, "creator_os", "Creator OS"), self.os_name)
     yield UInt32(self, "rev_level", "Revision level")
     yield UInt16(self, "def_resuid", "Default uid for reserved blocks")
     yield UInt16(self, "def_resgid", "Default gid for reserved blocks")
     yield UInt32(self, "first_ino", "First non-reserved inode")
     yield UInt16(self, "inode_size", "Size of inode structure")
     yield UInt16(self, "block_group_nr",
                  "Block group # of this superblock")
     yield UInt32(self, "feature_compat", "Compatible feature set")
     yield UInt32(self, "feature_incompat", "Incompatible feature set")
     yield UInt32(self, "feature_ro_compat",
                  "Read-only compatible feature set")
     yield RawBytes(self, "uuid", 16, "128-bit uuid for volume")
     yield String(self, "volume_name", 16, "Volume name", strip="\0")
     yield String(self,
                  "last_mounted",
                  64,
                  "Directory where last mounted",
                  strip="\0")
     yield UInt32(self, "compression",
                  "For compression (algorithm usage bitmap)")
     yield UInt8(self, "prealloc_blocks",
                 "Number of blocks to try to preallocate")
     yield UInt8(self, "prealloc_dir_blocks",
                 "Number to preallocate for directories")
     yield UInt16(self, "padding", "Padding")
     yield String(self, "journal_uuid", 16, "uuid of journal superblock")
     yield UInt32(self, "journal_inum", "inode number of journal file")
     yield UInt32(self, "journal_dev", "device number of journal file")
     yield UInt32(self, "last_orphan", "start of list of inodes to delete")
     yield RawBytes(self, "reserved", 197, "Reserved")
示例#23
0
 def createFields(self):
     yield Bytes(self, "magic", 4, "Mach-O signature")
     yield Enum(Int32(self, "cputype"), CPU_TYPE)
     yield Int32(self, "cpusubtype")
     yield Enum(UInt32(self, "filetype"), FILE_TYPE)
     yield UInt32(self, "ncmds")
     yield UInt32(self, "sizeofcmds")
     yield UInt32(self, "flags")
     if self.parent.is64bit:
         yield UInt32(self, "reserved")
示例#24
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
示例#25
0
    def createFields(self):
        yield UInt16(self, "wIdent", "Magic Number")
        yield UInt16(self, "nFib", "File Information Block (FIB) Version")
        yield UInt16(self, "nProduct", "Product Version")
        yield Enum(UInt16(self, "lid", "Language ID"), LANGUAGE_ID)
        yield Int16(self, "pnNext")

        yield Bit(self, "fDot", "Is the document a document template?")
        yield Bit(self, "fGlsy", "Is the document a glossary?")
        yield Bit(self, "fComplex", "Is the document in Complex format?")
        yield Bit(self, "fHasPic", "Does the document have embedded images?")
        yield Bits(self, "cQuickSaves", 4,
                   "Number of times the document was quick-saved")
        yield Bit(self, "fEncrypted", "Is the document encrypted?")
        yield Bits(self, "fWhichTblStm", 1,
                   "Which table stream (0Table or 1Table) to use")
        yield Bit(self, "fReadOnlyRecommended",
                  "Should the file be opened read-only?")
        yield Bit(self, "fWriteReservation", "Is the file write-reserved?")
        yield Bit(self, "fExtChar",
                  "Does the file use an extended character set?")
        yield Bit(self, "fLoadOverride")
        yield Bit(self, "fFarEast")
        yield Bit(self, "fCrypto")

        yield UInt16(
            self, "nFibBack",
            "Document is backwards compatible down to this FIB version")
        yield UInt32(self, "lKey", "File encryption key (only if fEncrypted)")
        yield Enum(UInt8(self, "envr", "Document creation environment"), {
            0: 'Word for Windows',
            1: 'Macintosh Word'
        })

        yield Bit(self, "fMac", "Was this file last saved on a Mac?")
        yield Bit(self, "fEmptySpecial")
        yield Bit(self, "fLoadOverridePage")
        yield Bit(self, "fFutureSavedUndo")
        yield Bit(self, "fWord97Save")
        yield Bits(self, "fSpare0", 3)
        CHARSET = {0: 'Windows ANSI', 256: 'Macintosh'}
        yield Enum(UInt16(self, "chse", "Character set for document text"),
                   CHARSET)
        yield Enum(
            UInt16(self, "chsTables", "Character set for internal table text"),
            CHARSET)
        yield UInt32(self, "fcMin",
                     "File offset for the first character of text")
        yield UInt32(self, "fcMax",
                     "File offset for the last character of text + 1")

        yield ShortArray(self, "array1", "Array of shorts")
        yield LongArray(self, "array2", "Array of longs")
        yield FCLCBArray(self, "array3",
                         "Array of File Offset/Byte Count (FC/LCB) pairs")
示例#26
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)
示例#27
0
 def createFields(self):
     yield Enum(UInt8(self, "labels"), BOOL)
     yield Enum(UInt8(self, "crop_marks"), BOOL)
     yield Enum(UInt8(self, "color_bars"), BOOL)
     yield Enum(UInt8(self, "reg_marks"), BOOL)
     yield Enum(UInt8(self, "negative"), BOOL)
     yield Enum(UInt8(self, "flip"), BOOL)
     yield Enum(UInt8(self, "interpolate"), BOOL)
     yield Enum(UInt8(self, "caption"), BOOL)
     yield Enum(UInt8(self, "print_flags"), BOOL)
     yield Enum(UInt8(self, "unknown"), BOOL)
示例#28
0
 def createFields(self):
     yield Enum(Bits(self, "class", 2), self.CLASS_DESC)
     yield Enum(Bit(self, "form"), self.FORM_DESC)
     yield Enum(Bits(self, "type", 5), self.TYPE_DESC)
     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)
示例#29
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)")
示例#30
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)