Beispiel #1
0
 def createFields(self):
     yield Enum(textHandler(UInt16(self, "type", "Chunk type"), hexadecimal), Chunk.type_name)
     yield UInt32(self, "size", "Chunk size (in bytes)")
     content_size = self["size"].value - 6
     if content_size == 0:
         return
     type = self["type"].value
     if type in Chunk.sub_chunks:
         while self.current_size < self.size:
             yield Chunk(self, "chunk[]")
     else:
         if type in Chunk.handlers:
             yield from Chunk.handlers[type](self)
         else:
             yield RawBytes(self, "data", content_size)
Beispiel #2
0
 def getInstrumentFields(self):
     yield S3MUInt24(self, "sample_offset")
     yield UInt32(self, "sample_size")
     yield UInt32(self, "loop_begin")
     yield UInt32(self, "loop_end")
     yield UInt8(self, "volume")
     yield UInt8(self, "reserved[]")
     yield Enum(UInt8(self, "packing"), self.PACKING)
     yield SampleFlags(self, "flags")
     yield UInt32(self, "c4_speed", "Frequency for middle C note")
     yield UInt32(self, "reserved[]", 4)
     yield UInt16(self, "internal[]", "Sample address in GUS memory")
     yield UInt16(self, "internal[]",
                  "Flags for SoundBlaster loop expansion")
     yield UInt32(self, "internal[]", "Last used position (SB)")
Beispiel #3
0
 def createFields(self):
     yield Bytes(self, "id", 4, "Tcpdump identifier")
     yield UInt16(self, "maj_ver", "Major version")
     yield UInt16(self, "min_ver", "Minor version")
     yield Int32(self, "this_zone", "GMT to local time zone correction")
     yield Int32(self, "sigfigs", "accuracy of timestamps")
     yield UInt32(self, "snap_len", "max length saved portion of each pkt")
     yield Enum(UInt32(self, "link_type", "data link type"),
                self.LINK_TYPE_DESC)
     link = self["link_type"].value
     if link not in self.LINK_TYPE:
         raise ParserError("Unknown link type: %s" % link)
     name, parser = self.LINK_TYPE[link]
     while self.current_size < self.size:
         yield Packet(self, "packet[]", parser, name)
Beispiel #4
0
    def createFields(self):
        yield String(self,
                     "header_id",
                     4,
                     "Playlist Header Markup (\"mhyp\")",
                     charset="ISO-8859-1")
        yield UInt32(self, "header_length", "Header Length")
        yield UInt32(self, "entry_length", "Entry Length")
        yield UInt32(self, "data_object_child_count",
                     "Number of Child Data Objects")
        yield UInt32(self, "playlist_count", "Number of Playlist Items")
        yield Enum(UInt8(self, "type", "Normal or master playlist?"),
                   self.is_master_pl_name)
        yield UInt8(self, "XXX1", "XXX1")
        yield UInt8(self, "XXX2", "XXX2")
        yield UInt8(self, "XXX3", "XXX3")
        yield TimestampMac32(self, "creation_date",
                             "Date when the playlist was created")
        yield UInt64(self, "playlistid", "Persistent Playlist ID")
        yield UInt32(self, "unk3", "unk3")
        yield UInt16(self, "string_mhod_count",
                     "Number of string MHODs for this playlist")
        yield Enum(UInt16(self, "is_podcast", "Playlist or Podcast List?"),
                   self.is_podcast_name)
        yield Enum(UInt32(self, "sort_order", "Playlist Sort Order"),
                   self.list_sort_order_name)

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

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

        for i in range(self["playlist_count"].value):
            yield PlaylistItem(self, "playlist_item[]")
Beispiel #5
0
 def createFields(self):
     yield Enum(UInt8(self, "kind"), self.MULTINAME_KIND)
     kind = self["kind"].value
     if kind in (7, 13):  # Qname
         yield FlashU30(self, "namespace_index")
         yield ABCStringIndex(self, "name_index")
     elif kind in (9, 14):  # Multiname
         yield ABCStringIndex(self, "name_index")
         yield FlashU30(self, "namespace_set_index")
     elif kind in (15, 16):  # RTQname
         yield ABCStringIndex(self, "name_index")
     elif kind == 27:  # MultinameL
         yield FlashU30(self, "namespace_set_index")
     elif kind in (17, 18):  # RTQnameL
         pass
Beispiel #6
0
def parseSoundHeader(parent, size):
    yield Bit(parent, "playback_is_stereo")
    yield Bit(parent, "playback_is_16bit")
    yield textHandler(Bits(parent, "playback_rate", 2), bit2hertz)
    yield NullBits(parent, "reserved", 4)

    yield Bit(parent, "sound_is_stereo")
    yield Bit(parent, "sound_is_16bit")
    yield textHandler(Bits(parent, "sound_rate", 2), bit2hertz)
    yield Enum(Bits(parent, "codec", 4), SOUND_CODEC)

    yield UInt16(parent, "sample_count")

    if parent["codec"].value == 2:
        yield UInt16(parent, "latency_seek")
Beispiel #7
0
 def createFields(self):
     # This stupid shit gets the LSB, not the MSB...
     self.info("Note info: 0x%02X" %
               self.stream.readBits(self.absolute_address, 8, LITTLE_ENDIAN))
     yield RealBit(self, "is_extended")
     if self["is_extended"].value:
         info = NoteInfo(self, "info")
         yield info
         if info["has_note"].value:
             yield Enum(UInt8(self, "note"), NOTE_NAME)
         if info["has_instrument"].value:
             yield UInt8(self, "instrument")
         if info["has_volume"].value:
             yield textHandler(UInt8(self, "volume"), parseVolume)
         if info["has_type"].value:
             yield Effect(self, "effect_type")
         if info["has_parameter"].value:
             yield textHandler(UInt8(self, "effect_parameter"), hexadecimal)
     else:
         yield Enum(Bits(self, "note", 7), NOTE_NAME)
         yield UInt8(self, "instrument")
         yield textHandler(UInt8(self, "volume"), parseVolume)
         yield Effect(self, "effect_type")
         yield textHandler(UInt8(self, "effect_parameter"), hexadecimal)
Beispiel #8
0
 def parseFilename(self):
     yield UInt64(self, "ref", "File reference to the parent directory")
     yield TimestampWin64(self, "ctime", "File Creation")
     yield TimestampWin64(self, "atime", "File Altered")
     yield TimestampWin64(self, "mtime", "MFT Changed")
     yield TimestampWin64(self, "rtime", "File Read")
     yield filesizeHandler(UInt64(self, "alloc_size", "Allocated size of the file"))
     yield filesizeHandler(UInt64(self, "real_size", "Real size of the file"))
     yield UInt32(self, "file_flags")
     yield UInt32(self, "file_flags2", "Used by EAs and Reparse")
     yield UInt8(self, "filename_length", "Filename length in characters")
     yield Enum(UInt8(self, "filename_namespace"), self.FILENAME_NAMESPACE)
     size = self["filename_length"].value * 2
     if size:
         yield String(self, "filename", size, charset="UTF-16-LE")
Beispiel #9
0
 def createFields(self):
     yield UInt16(self, "signature",
                  "PE optional header signature (0x010b)")
     # TODO: Support PE32+ (signature=0x020b)
     if self["signature"].value != 0x010b:
         raise ParserError("Invalid PE optional header signature")
     yield UInt8(self, "maj_lnk_ver", "Major linker version")
     yield UInt8(self, "min_lnk_ver", "Minor linker version")
     yield filesizeHandler(UInt32(self, "size_code", "Size of code"))
     yield filesizeHandler(
         UInt32(self, "size_init_data", "Size of initialized data"))
     yield filesizeHandler(
         UInt32(self, "size_uninit_data", "Size of uninitialized data"))
     yield textHandler(
         UInt32(self, "entry_point",
                "Address (RVA) of the code entry point"), hexadecimal)
     yield textHandler(UInt32(self, "base_code", "Base (RVA) of code"),
                       hexadecimal)
     yield textHandler(UInt32(self, "base_data", "Base (RVA) of data"),
                       hexadecimal)
     yield textHandler(UInt32(self, "image_base", "Image base (RVA)"),
                       hexadecimal)
     yield filesizeHandler(UInt32(self, "sect_align", "Section alignment"))
     yield filesizeHandler(UInt32(self, "file_align", "File alignment"))
     yield UInt16(self, "maj_os_ver", "Major OS version")
     yield UInt16(self, "min_os_ver", "Minor OS version")
     yield UInt16(self, "maj_img_ver", "Major image version")
     yield UInt16(self, "min_img_ver", "Minor image version")
     yield UInt16(self, "maj_subsys_ver", "Major subsystem version")
     yield UInt16(self, "min_subsys_ver", "Minor subsystem version")
     yield NullBytes(self, "reserved", 4)
     yield filesizeHandler(UInt32(self, "size_img", "Size of image"))
     yield filesizeHandler(UInt32(self, "size_hdr", "Size of headers"))
     yield textHandler(UInt32(self, "checksum"), hexadecimal)
     yield Enum(UInt16(self, "subsystem"), self.SUBSYSTEM_NAME)
     yield UInt16(self, "dll_flags")
     yield filesizeHandler(UInt32(self, "size_stack_reserve"))
     yield filesizeHandler(UInt32(self, "size_stack_commit"))
     yield filesizeHandler(UInt32(self, "size_heap_reserve"))
     yield filesizeHandler(UInt32(self, "size_heap_commit"))
     yield UInt32(self, "loader_flags")
     yield UInt32(self, "nb_directory", "Number of RVA and sizes")
     for index in range(self["nb_directory"].value):
         try:
             name = self.DIRECTORY_NAME[index]
         except KeyError:
             name = "data_dir[%u]" % index
         yield DataDirectory(self, name)
Beispiel #10
0
    def createFields(self):
        # Header
        yield UInt16(self, "version", "Version (=1)")
        yield Bytes(self, "endian", 2, "Endian (\\xfe\\xff for little endian)")
        yield UInt8(self, "os_version")
        yield UInt8(self, "os_revision")
        yield Enum(UInt16(self, "os"), OS_NAME)
        yield Int32(self, "unused", "(=-1)")
        yield GUID(self, "clsid")

        # User type
        yield PascalString32(self, "user_type", strip="\0")

        # Clipboard format
        if self["os"].value == OS_MAC:
            yield Int32(self, "unused[]", "(=-2)")
            yield String(self, "clipboard_format", 4)
        else:
            yield PascalString32(self, "clipboard_format", strip="\0")
        if self._current_size // 8 == self.datasize:
            return

        # -- OLE 2.01 ---

        # Program ID
        yield PascalString32(self, "prog_id", strip="\0")

        if self["os"].value != OS_MAC:
            # Magic number
            yield textHandler(
                UInt32(self, "magic", "Magic number (0x71B239F4)"),
                hexadecimal)

            # Unicode version
            yield PascalStringWin32(self, "user_type_unicode", strip="\0")
            yield PascalStringWin32(self,
                                    "clipboard_format_unicode",
                                    strip="\0")
            yield PascalStringWin32(self, "prog_id_unicode", strip="\0")

        # _current_size because current_size returns _current_max_size
        size = self.datasize - (self._current_size // 8)
        if size:
            yield NullBytes(self, "end_padding", size)

        if self.datasize < self.size // 8:
            yield RawBytes(self, "slack_space",
                           (self.size // 8) - self.datasize)
Beispiel #11
0
def parseApplicationExtension(parent):
    yield PascalString8(parent, "app_name", "Application name")
    while True:
        size = UInt8(parent, "size[]")
        if size.value == 0:
            break
        yield size
        if parent["app_name"].value == "NETSCAPE2.0" and size.value == 3:
            yield Enum(UInt8(parent, "netscape_code"), NETSCAPE_CODE)
            if parent["netscape_code"].value == 1:
                yield UInt16(parent, "loop_count")
            else:
                yield RawBytes(parent, "raw[]", 2)
        else:
            yield RawBytes(parent, "raw[]", size.value)
    yield NullBytes(parent, "terminator", 1, "Terminator (0)")
Beispiel #12
0
def parseDefineSound(parent, size):
    yield UInt16(parent, "sound_id")

    yield Bit(parent, "is_stereo")
    yield Bit(parent, "is_16bit")
    yield textHandler(Bits(parent, "rate", 2), bit2hertz)
    yield Enum(Bits(parent, "codec", 4), SOUND_CODEC)

    yield UInt32(parent, "sample_count")

    if parent["codec"].value == SOUND_CODEC_MP3:
        yield UInt16(parent, "len")

    size = (parent.size - parent.current_size) // 8
    if size:
        yield RawBytes(parent, "music_data", size)
Beispiel #13
0
def parseAudioFormat(self, size):
    yield Enum(UInt16(self, "codec", "Audio format: Codec id"),
               audio_codec_name)
    yield UInt16(self, "channel", "Audio format: Channels")
    yield UInt32(self, "sample_rate", "Audio format: Sample rate")
    yield UInt32(self, "bit_rate", "Audio format: Bit rate")
    yield UInt16(self, "block_align", "Audio format: Block align")
    if size >= 16:
        yield UInt16(self, "bits_per_sample", "Audio format: Bits per sample")
    if size >= 18:
        yield UInt16(self, "ext_size",
                     "Audio format: Size of extra information")
    if size >= 28:  # and self["a_channel"].value > 2
        yield UInt16(self, "reserved", "Audio format: ")
        yield UInt32(self, "channel_mask",
                     "Audio format: channels placement bitmask")
        yield UInt32(self, "subformat", "Audio format: Subformat id")
Beispiel #14
0
 def createFields(self):
     yield UInt8(self, "size")
     self._size = (self['size'].value + 1) * 8
     yield Enum(UInt8(self, "type"), self.ENTRYTYPE)
     if self['type'].value in (1, 3):
         yield textHandler(
             UInt16(self, "pid", "PID of item in clip stream m2ts file"),
             hexadecimal)
     else:  # 2,4
         '''
         The patent says:
             ref_to_SubPath_id
             ref_to_SubClip_entry_id
             ref_to_Stream_PID_of_subClip
         Sizes aren't given, though, so I cannot determine the format without a sample.
         '''
         pass
Beispiel #15
0
 def createFields(self):
     yield Enum(UInt8(self, "code", "Code"), self.code_name)
     code = self["code"].value
     if code == self.NOP:
         return
     yield UInt8(self, "length", "Option size in bytes")
     if code == self.MAX_SEGMENT:
         yield UInt16(self, "max_seg", "Maximum segment size")
     elif code == self.WINDOW_SCALE:
         yield UInt8(self, "win_scale", "Window scale")
     elif code == self.TIMESTAMP:
         yield UInt32(self, "ts_val", "Timestamp value")
         yield UInt32(self, "ts_ecr", "Timestamp echo reply")
     else:
         size = (self.size - self.current_size) // 8
         if size:
             yield RawBytes(self, "data", size)
Beispiel #16
0
def markerHeader(self):
    yield String(self, "signature", 7, "Signature")
    yield UInt8(self, "ver_extract", "Version needed to extract archive")
    yield UInt8(self, "ver_created", "Version used to create archive")
    yield Enum(UInt8(self, "host_os", "OS where the files were compressed"),
               HOST_OS)
    yield UInt8(self, "vol_num", "Volume number")
    yield TimeDateMSDOS32(self, "time", "Date and time (MS DOS format)")
    yield Bits(self, "reserved", 64, "Reserved size for future extensions")
    flags = self["flags"]
    if flags["has_av_string"].value:
        yield PascalString8(self, "av_string", "AV String")
    if flags["has_comment"].value:
        size = filesizeHandler(UInt16(self, "comment_size", "Comment size"))
        yield size
        if size.value > 0:
            yield RawBytes(self, "compressed_comment", size.value, \
                           "Compressed comment")
Beispiel #17
0
 def createFields(self):
     yield String(self, "magic", 4, "ITSF", charset="ASCII")
     yield UInt32(self, "version")
     yield UInt32(self, "header_size", "Total header length (in bytes)")
     yield UInt32(self, "one")
     yield UInt32(self, "last_modified",
                  "Lower 32 bits of the time expressed in units of 0.1 us")
     yield Enum(UInt32(self, "lang_id", "Windows Language ID"), LANGUAGE_ID)
     yield GUID(self, "dir_uuid",
                "{7C01FD10-7BAA-11D0-9E0C-00A0-C922-E6EC}")
     yield GUID(self, "stream_uuid",
                "{7C01FD11-7BAA-11D0-9E0C-00A0-C922-E6EC}")
     yield UInt64(self, "filesize_offset")
     yield filesizeHandler(UInt64(self, "filesize_len"))
     yield UInt64(self, "dir_offset")
     yield filesizeHandler(UInt64(self, "dir_len"))
     if 3 <= self["version"].value:
         yield UInt64(self, "data_offset")
Beispiel #18
0
 def createFields(self):
     yield Enum(UInt8(self, "charset"), self.charset_desc)
     yield String(self, "lang", 3, "Language", charset="ASCII")
     charset = getCharset(self["charset"])
     yield CString(self,
                   "title",
                   "Title",
                   charset=charset,
                   strip=self.STRIP)
     size = (self.size - self.current_size) // 8
     if not size:
         return
     yield String(self,
                  "text",
                  size,
                  "Text",
                  charset=charset,
                  strip=self.STRIP)
Beispiel #19
0
 def createFields(self):
     yield Enum(UInt32(self, "format"), {0: 'Raw RGB', 1: 'JPEG RGB'})
     yield UInt32(self, "width", "Width of thumbnail in pixels")
     yield UInt32(self, "height", "Height of thumbnail in pixels")
     yield UInt32(
         self, "widthbytes",
         "Padded row bytes = (width * bits per pixel + 31) / 32 * 4")
     yield UInt32(self, "uncompressed_size",
                  "Total size = widthbytes * height * planes")
     yield UInt32(self, "compressed_size",
                  "Size after compression. Used for consistency check")
     yield UInt16(self, "bits_per_pixel")
     yield UInt16(self, "num_planes")
     yield SubFile(self,
                   "thumbnail",
                   self['compressed_size'].value,
                   "Thumbnail (JPEG file)",
                   mime_type="image/jpeg")
Beispiel #20
0
    def createFields(self):
        yield UInt32(self, "width", "Layer width in pixels")
        yield UInt32(self, "height", "Layer height in pixels")
        yield Enum(UInt32(self, "type", "Layer type"), XcfFile.IMAGE_TYPE_NAME)
        yield PascalString32(self, "name", "Layer name", strip="\0", charset="UTF-8")
        for prop in readProperties(self):
            yield prop

        # --
        # TODO: Hack for Gimp 1.2 files
        # --

        yield UInt32(self, "hierarchy_ofs", "Hierarchy offset")
        yield UInt32(self, "mask_ofs", "Layer mask offset")
        padding = self.seekByte(self["hierarchy_ofs"].value, relative=False)
        if padding is not None:
            yield padding
        yield XcfHierarchy(self, "hierarchy", "Hierarchy")
Beispiel #21
0
 def createFields(self):
     yield Bit(self, "continued_from",
               "File continued from previous volume")
     yield Bit(self, "continued_in", "File continued in next volume")
     yield Bit(self, "is_encrypted", "File encrypted with password")
     yield Bit(self, "has_comment", "File comment present")
     yield Bit(self, "is_solid",
               "Information from previous files is used (solid flag)")
     # The 3 following lines are what blocks more staticity
     yield Enum(Bits(self, "dictionary_size", 3, "Dictionary size"),
                DICTIONARY_SIZE)
     for bit in commonFlags(self):
         yield bit
     yield Bit(self, "is_large", "file64 operations needed")
     yield Bit(self, "is_unicode", "Filename also encoded using Unicode")
     yield Bit(self, "has_salt", "Has salt for encryption")
     yield Bit(self, "uses_file_version", "File versioning is used")
     yield Bit(self, "has_ext_time", "Extra time ??")
     yield Bit(self, "has_ext_flags", "Extra flag ??")
Beispiel #22
0
    def createFields(self):
        yield Bit(self, "last_metadata_block", "True if this is the last metadata block")
        yield Enum(Bits(self, "block_type", 7, "Metadata block header type"), self.BLOCK_TYPE_DESC)
        yield UInt24(self, "metadata_length", "Length of following metadata in bytes (doesn't include this header)")

        block_type = self["block_type"].value
        size = self["metadata_length"].value
        if not size:
            return
        try:
            handler = self.BLOCK_TYPES[block_type][2]
        except KeyError:
            handler = None
        if handler:
            yield handler(self, "content", size=size * 8)
        elif self["block_type"].value == 1:
            yield NullBytes(self, "padding", size)
        else:
            yield RawBytes(self, "rawdata", size)
Beispiel #23
0
 def createFields(self):
     yield UInt32(self, "offset", "Offset to data (from file start)")
     yield UInt16(self, "data_blocks",
                  "Number of data blocks which are in this cabinet")
     yield Enum(Bits(self, "compr_method", 4, "Compression method"),
                COMPRESSION_NAME)
     if self["compr_method"].value in [
             2, 3
     ]:  # Quantum or LZX use compression level
         yield PaddingBits(self, "padding[]", 4)
         yield Bits(self, "compr_level", 5, "Compression level")
         yield PaddingBits(self, "padding[]", 3)
     else:
         yield PaddingBits(self, "padding[]", 12)
     if self["../flags/has_reserved"].value and self[
             "../reserved_folder_size"].value:
         yield RawBytes(self, "reserved_folder",
                        self["../reserved_folder_size"].value,
                        "Per-folder reserved area")
Beispiel #24
0
 def createFields(self):
     yield SymbolStringTableOffset(
         self, "name",
         "Section name (index into section header string table)")
     yield Enum(
         textHandler(UInt32(self, "type", "Section type"), hexadecimal),
         self.TYPE_NAME)
     yield SectionFlags(self, "flags", "Section flags")
     yield textHandler(UInt64(self, "VMA", "Virtual memory address"),
                       hexadecimal)
     yield textHandler(
         UInt64(self, "LMA", "Logical memory address (offset in file)"),
         hexadecimal)
     yield textHandler(UInt64(self, "size", "Section size (bytes)"),
                       hexadecimal)
     yield UInt32(self, "link", "Index of a related section")
     yield UInt32(self, "info", "Type-dependent information")
     yield UInt64(self, "addr_align", "Address alignment (bytes)")
     yield UInt64(self, "entry_size", "Size of each entry in section")
Beispiel #25
0
 def createFields(self):
     yield PascalString16(self,
                          "name",
                          "Name",
                          charset="UTF-16-LE",
                          strip="\0")
     yield Enum(UInt16(self, "type"), self.TYPE_NAME)
     yield UInt16(self, "value_length")
     type = self["type"].value
     size = self["value_length"].value
     name = "value"
     if type == 0 and (size % 2) == 0:
         yield String(self, name, size, charset="UTF-16-LE", strip="\0")
     elif type in (2, 3):
         yield UInt32(self, name)
     elif type == 4:
         yield UInt64(self, name)
     else:
         yield RawBytes(self, name, size)
Beispiel #26
0
 def createFields(self):
     yield String(self, "jfif", 5, "JFIF string", charset="ASCII")
     if self["jfif"].value != "JFIF\0":
         raise ParserError(
             "Stream doesn't look like JPEG chunk (wrong JFIF signature)")
     yield UInt8(self, "ver_maj", "Major version")
     yield UInt8(self, "ver_min", "Minor version")
     yield Enum(UInt8(self, "units", "Units"), self.UNIT_NAME)
     if self["units"].value == 0:
         yield UInt16(self, "aspect_x", "Aspect ratio (X)")
         yield UInt16(self, "aspect_y", "Aspect ratio (Y)")
     else:
         yield UInt16(self, "x_density", "X density")
         yield UInt16(self, "y_density", "Y density")
     yield UInt8(self, "thumb_w", "Thumbnail width")
     yield UInt8(self, "thumb_h", "Thumbnail height")
     thumb_size = self["thumb_w"].value * self["thumb_h"].value
     if thumb_size != 0:
         yield PaletteRGB(self, "thumb_palette", 256)
         yield RawBytes(self, "thumb_data", thumb_size, "Thumbnail data")
Beispiel #27
0
 def createFields(self):
     if False:
         yield UInt32(self, "width0")
         yield UInt32(self, "height0")
         yield PaddingBytes(self, "reserved[]", 7)
         yield UInt32(self, "width")
         yield UInt32(self, "height")
         yield PaddingBytes(self, "reserved[]", 2)
         yield UInt16(self, "depth")
         yield Enum(String(self, "codec", 4, charset="ASCII"),
                    video_fourcc_name)
         yield NullBytes(self, "padding", 20)
     else:
         yield UInt32(self, "width")
         yield UInt32(self, "height")
         yield PaddingBytes(self, "reserved[]", 1)
         yield UInt16(self, "format_data_size")
         if self["format_data_size"].value < 40:
             raise ParserError("Unknown format data size")
         yield BitmapInfoHeader(self, "bmp_info", use_fourcc=True)
Beispiel #28
0
 def createFields(self):
     yield Bits(self, "start_length", 5)
     length = self["start_length"].value
     lengths = []
     for i in xrange(self.symbols):
         while True:
             bit = Bit(self, "change_length[%i][]" % i, "Should the length be changed for symbol %i?" % i)
             yield bit
             if not bit.value:
                 break
             else:
                 bit = Enum(Bit(self, "length_decrement[%i][]" % i, "Decrement the value?"),
                            {True: "Decrement", False: "Increment"})
                 yield bit
                 if bit.value:
                     length -= 1
                 else:
                     length += 1
         lengths.append(length)
     self.final_length = length
     self.tree = build_tree(lengths)
Beispiel #29
0
 def createFields(self):
     yield filesizeHandler(
         UInt32(self, "filesize", "Uncompressed file size"))
     yield UInt32(self, "folder_offset",
                  "File offset in uncompressed folder")
     yield Enum(
         UInt16(self, "folder_index", "Containing folder ID (index)"), {
             0xFFFD:
             "Folder continued from previous cabinet (real folder ID = 0)",
             0xFFFE:
             "Folder continued to next cabinet (real folder ID = %i)" %
             (self["../nb_folder"].value - 1),
             0xFFFF:
             "Folder spanning previous, current and next cabinets (real folder ID = 0)"
         })
     yield DateTimeMSDOS32(self, "timestamp")
     yield CabFileAttributes(self, "attributes")
     if self["attributes/name_is_utf"].value:
         yield CString(self, "filename", charset="UTF-8")
     else:
         yield CString(self, "filename", charset="ASCII")
Beispiel #30
0
 def createFields(self):
     yield UInt8(self, "hdr_size", "Header size in bytes")
     yield UInt8(self, "version", "Targa version (always one)")
     yield Enum(UInt8(self, "codec", "Pixels encoding"), self.CODEC_NAME)
     yield UInt16(self, "palette_ofs", "Palette absolute file offset")
     yield UInt16(self, "nb_color", "Number of color")
     yield UInt8(self, "color_map_size", "Color map entry size")
     yield UInt16(self, "x_min")
     yield UInt16(self, "y_min")
     yield UInt16(self, "width")
     yield UInt16(self, "height")
     yield UInt8(self, "bpp", "Bits per pixel")
     yield UInt8(self, "options", "Options (0: vertical mirror)")
     if self["bpp"].value == 8:
         yield PaletteRGB(self, "palette", 256)
     if self["codec"].value == 1:
         yield Pixels(self, "pixels")
     else:
         size = (self.size - self.current_size) // 8
         if size:
             yield RawBytes(self, "raw_pixels", size)