示例#1
0
文件: ole2.py 项目: bopopescu/repo-1
 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)"))
示例#2
0
文件: fat.py 项目: bopopescu/repo-1
 def createFields(self):
     yield Bytes(self, "jmp", 3, "Jump instruction (to skip over header on boot)")
     yield Bytes(self, "oem_name", 8, "OEM Name (padded with spaces)")
     yield UInt16(self, "sector_size", "Bytes per sector")
     yield UInt8 (self, "cluster_size", "Sectors per cluster")
     yield UInt16(self, "reserved_sectors", "Reserved sector count (including boot sector)")
     yield UInt8 (self, "fat_nb", "Number of file allocation tables")
     yield UInt16(self, "max_root", "Maximum number of root directory entries")
     yield UInt16(self, "sectors1", "Total sectors (if zero, use 'sectors2')")
     yield UInt8 (self, "media_desc", "Media descriptor")
     yield UInt16(self, "fat_size", "Sectors per FAT")
     yield UInt16(self, "track_size", "Sectors per track")
     yield UInt16(self, "head_nb", "Number of heads")
     yield UInt32(self, "hidden", "Hidden sectors")
     yield UInt32(self, "sectors2", "Total sectors (if greater than 65535)")
     if self.parent.version == 32:
         yield UInt32(self, "fat32_size", "Sectors per FAT")
         yield UInt16(self, "fat_flags", "FAT Flags")
         yield UInt16(self, "version", "Version")
         yield UInt32(self, "root_start", "Cluster number of root directory start")
         yield UInt16(self, "inf_sector", "Sector number of FS Information Sector")
         yield UInt16(self, "boot_copy", "Sector number of a copy of this boot sector")
         yield NullBytes(self, "reserved[]", 12, "Reserved")
     yield UInt8(self, "phys_drv", "Physical drive number")
     yield NullBytes(self, "reserved[]", 1, 'Reserved ("current head")')
     yield UInt8(self, "sign", "Signature")
     yield textHandler(UInt32(self, "serial", "ID (serial number)"), hexadecimal)
     yield String(self, "label", 11, "Volume Label", strip=' ', charset="ASCII")
     yield String(self, "fs_type", 8, "FAT file system type", strip=' ', charset="ASCII")
     yield Bytes(self, "code", 510-self.current_size/8, "Operating system boot code")
     yield Bytes(self, "trail_sig", 2, "Signature (0x55 0xAA)")
示例#3
0
    def createFields(self):
        # Read chunk header
        yield Bytes(self, "signature", 3, r"Property signature (\x8E\xAD\xE8)")
        if self["signature"].value != "\x8E\xAD\xE8":
            raise ParserError("Invalid property signature")
        yield UInt8(self, "version", "Signature version")
        yield NullBytes(self, "reserved", 4, "Reserved")
        yield UInt32(self, "count", "Count")
        yield UInt32(self, "size", "Size")

        # Read item header
        items = []
        for i in range(0, self["count"].value):
            item = ItemHeader(self, "item[]")
            yield item
            items.append(item)

        # Sort items by their offset
        items.sort(sortRpmItem)

        # Read item content
        start = self.current_size / 8
        for item in items:
            offset = item["offset"].value
            diff = offset - (self.current_size / 8 - start)
            if 0 < diff:
                yield NullBytes(self, "padding[]", diff)
            yield ItemContent(self, "content[]", item)
        size = start + self["size"].value - self.current_size / 8
        if 0 < size:
            yield NullBytes(self, "padding[]", size)
示例#4
0
    def createFields(self):
        yield Bytes(self, "jump", 3, "Intel x86 jump instruction")
        yield String(self, "name", 8)
        yield BiosParameterBlock(self, "bios", "BIOS parameters")

        yield textHandler(UInt8(self, "physical_drive", "(0x80)"), hexadecimal)
        yield NullBytes(self, "current_head", 1)
        yield textHandler(
            UInt8(self, "ext_boot_sig", "Extended boot signature (0x80)"),
            hexadecimal)
        yield NullBytes(self, "unused", 1)

        yield UInt64(self, "nb_sectors")
        yield UInt64(self, "mft_cluster", "Cluster location of MFT data")
        yield UInt64(self, "mftmirr_cluster",
                     "Cluster location of copy of MFT")
        yield UInt8(self, "cluster_per_mft", "MFT record size in clusters")
        yield NullBytes(self, "reserved[]", 3)
        yield UInt8(self, "cluster_per_index", "Index block size in clusters")
        yield NullBytes(self, "reserved[]", 3)
        yield textHandler(UInt64(self, "serial_number"), hexadecimal)
        yield textHandler(UInt32(self, "checksum", "Boot sector checksum"),
                          hexadecimal)
        yield Bytes(self, "boot_code", 426)
        yield Bytes(self, "mbr_magic", 2,
                    r"Master boot record magic number (\x55\xAA)")
示例#5
0
def parseVideoHeader(parent):
    yield NullBytes(parent, "padding[]", 2)
    yield String(parent, "fourcc", 4)
    yield UInt32(parent, "size")
    yield textHandler(UInt64(parent, "time_unit", "Frame duration"), formatTimeUnit)
    yield UInt64(parent, "sample_per_unit")
    yield UInt32(parent, "default_len")
    yield UInt32(parent, "buffer_size")
    yield UInt16(parent, "bits_per_sample")
    yield NullBytes(parent, "padding[]", 2)
    yield UInt32(parent, "width")
    yield UInt32(parent, "height")
    yield NullBytes(parent, "padding[]", 4)
示例#6
0
    def createFields(self):
        # File mode
        yield Bit(self, "other_exec")
        yield Bit(self, "other_write")
        yield Bit(self, "other_read")
        yield Bit(self, "group_exec")
        yield Bit(self, "group_write")
        yield Bit(self, "group_read")
        yield Bit(self, "owner_exec")
        yield Bit(self, "owner_write")
        yield Bit(self, "owner_read")
        yield Bit(self, "sticky")
        yield Bit(self, "setgid")
        yield Bit(self, "setuid")
        yield Enum(Bits(self, "file_type", 4), self.file_type)

        yield UInt16(self, "uid", "User ID")
        yield UInt32(self, "size", "File size (in bytes)")
        yield TimestampUnix32(self, "atime", "Last access time")
        yield TimestampUnix32(self, "ctime", "Creation time")
        yield TimestampUnix32(self, "mtime", "Last modification time")
        yield TimestampUnix32(self, "dtime", "Delete time")
        yield UInt16(self, "gid", "Group ID")
        yield UInt16(self, "links_count", "Links count")
        yield UInt32(self, "blocks", "Number of blocks")
        yield UInt32(self, "flags", "Flags")
        yield NullBytes(self, "reserved[]", 4, "Reserved")
        for index in xrange(15):
            yield UInt32(self, "block[]")
        yield UInt32(self, "version", "Version")
        yield UInt32(self, "file_acl", "File ACL")
        yield UInt32(self, "dir_acl", "Directory ACL")
        yield UInt32(self, "faddr", "Block where the fragment of the file resides")

        os = self["/superblock/creator_os"].value
        if os == SuperBlock.OS_LINUX:
            yield UInt8(self, "frag", "Number of fragments in the block")
            yield UInt8(self, "fsize", "Fragment size")
            yield UInt16(self, "padding", "Padding")
            yield UInt16(self, "uid_high", "High 16 bits of user ID")
            yield UInt16(self, "gid_high", "High 16 bits of group ID")
            yield NullBytes(self, "reserved[]", 4, "Reserved")
        elif os == SuperBlock.OS_HURD:
            yield UInt8(self, "frag", "Number of fragments in the block")
            yield UInt8(self, "fsize", "Fragment size")
            yield UInt16(self, "mode_high", "High 16 bits of mode")
            yield UInt16(self, "uid_high", "High 16 bits of user ID")
            yield UInt16(self, "gid_high", "High 16 bits of group ID")
            yield UInt32(self, "author", "Author ID (?)")
        else:
            yield RawBytes(self, "raw", 12, "Reserved")
示例#7
0
    def createFields(self):
        # Header
        yield NullBytes(self, "zero_vector", 16)
        yield GUID(self, "fs_guid")
        yield UInt64(self, "volume_len")
        yield String(self, "signature", 4)
        yield UInt32(self, "attributes")
        yield UInt16(self, "header_len")
        yield UInt16(self, "checksum")
        yield UInt16(self, "ext_header_offset")
        yield UInt8(self, "reserved")
        yield UInt8(self, "revision")
        while True:
            bm = BlockMap(self, "block_map[]")
            yield bm
            if bm['num_blocks'].value == 0 and bm['len'].value == 0:
                break
        # TODO must handle extended header

        # Content
        while not self.eof:
            padding = paddingSize(self.current_size // 8, 8)
            if padding:
                yield PaddingBytes(self, "padding[]", padding)
            yield File(self, "file[]")
示例#8
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)
示例#9
0
    def createFields(self):
        # Skip something (what is stored here? MBR?)
        yield NullBytes(self, "padding[]", 1024)

        # Read superblock
        superblock = SuperBlock(self, "superblock")
        yield superblock
        if not(0 <= self["superblock/log_block_size"].value <= 2):
            raise ParserError("EXT2: Invalid (log) block size")
        self.block_size = 1024 << superblock["log_block_size"].value # in bytes

        # Read groups' descriptor
        field = self.seekByte(((1023 + superblock.size/8) / self.block_size + 1) * self.block_size, null=True)
        if field:
            yield field
        groups = GroupDescriptors(self, "group_desc", superblock.group_count)
        yield groups

        # Read groups
        address = groups["group[0]/block_bitmap"].value * self.block_size
        field = self.seekByte(address, null=True)
        if field:
            yield field
        for index in range(0, superblock.group_count):
            yield Group(self, "group[]", index)
示例#10
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)
示例#11
0
def createNullField(parent, nbits, name="padding[]", description=None):
    if nbits <= 0:
        raise FieldError("Unable to create null padding of %s bits" % nbits)
    if (nbits % 8) == 0:
        return NullBytes(parent, name, nbits/8, description)
    else:
        return NullBits(parent, name, nbits, description)
示例#12
0
文件: riff.py 项目: bopopescu/repo-1
def parseAviHeader(self):
    yield UInt32(self, "microsec_per_frame", "Microsecond per frame")
    yield UInt32(self, "max_byte_per_sec", "Maximum byte per second")
    yield NullBytes(self, "reserved", 4)

    # Flags
    yield NullBits(self, "reserved[]", 4)
    yield Bit(self, "has_index")
    yield Bit(self, "must_use_index")
    yield NullBits(self, "reserved[]", 2)
    yield Bit(self, "is_interleaved")
    yield NullBits(self, "reserved[]", 2)
    yield Bit(self, "trust_cktype")
    yield NullBits(self, "reserved[]", 4)
    yield Bit(self, "was_capture_file")
    yield Bit(self, "is_copyrighted")
    yield NullBits(self, "reserved[]", 14)

    yield UInt32(self, "total_frame", "Total number of frames in the video")
    yield UInt32(self, "init_frame",
                 "Initial frame (used in interleaved video)")
    yield UInt32(self, "nb_stream", "Number of streams")
    yield UInt32(self, "sug_buf_size", "Suggested buffer size")
    yield UInt32(self, "width", "Width in pixel")
    yield UInt32(self, "height", "Height in pixel")
    yield UInt32(self, "scale")
    yield UInt32(self, "rate")
    yield UInt32(self, "start")
    yield UInt32(self, "length")
示例#13
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)
示例#14
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))
示例#15
0
    def createFields(self):
        # First kilobyte: boot sectors
        yield RawBytes(self, "boot", 1024, "Space for disklabel etc.")

        # Header
        yield UInt32(self, "version")
        yield UInt32(self, "last_page")
        yield UInt32(self, "nb_badpage")
        yield UUID(self, "sws_uuid")
        yield UUID(self, "sws_volume")
        yield NullBytes(self, "reserved", 117*4)

        # Read bad pages (if any)
        count = self["nb_badpage"].value
        if count:
            if MAX_SWAP_BADPAGES < count:
                raise ParserError("Invalid number of bad page (%u)" % count)
            yield GenericVector(self, "badpages", count, UInt32, "badpage")

        # Read magic
        padding = self.seekByte(PAGE_SIZE - 10, "padding", null=True)
        if padding:
            yield padding
        yield String(self, "magic", 10, charset="ASCII")

        # Read all pages
        yield GenericVector(self, "pages", self["last_page"].value, Page, "page")

        # Padding at the end
        padding = self.seekBit(self.size, "end_padding", null=True)
        if padding:
            yield padding
示例#16
0
文件: id3.py 项目: bopopescu/repo-1
 def createFields(self):
     yield NullBytes(self, "zero", 1)
     yield textHandler(
         String(self,
                "length",
                self._size / 8 - 1,
                "Length in ms",
                charset="ASCII"), self.computeLength)
示例#17
0
 def createFields(self):
     yield UInt32(self, "block_bitmap", "Points to the blocks bitmap block")
     yield UInt32(self, "inode_bitmap", "Points to the inodes bitmap block")
     yield UInt32(self, "inode_table", "Points to the inodes table first block")
     yield UInt16(self, "free_blocks_count", "Number of free blocks")
     yield UInt16(self, "free_inodes_count", "Number of free inodes")
     yield UInt16(self, "used_dirs_count", "Number of inodes allocated to directories")
     yield UInt16(self, "padding", "Padding")
     yield NullBytes(self, "reserved", 12, "Reserved")
示例#18
0
 def createFields(self):
     yield UInt32(self, "inode", "Inode")
     yield UInt16(self, "rec_len", "Record length")
     yield UInt8(self, "name_len", "Name length")
     yield Enum(UInt8(self, "file_type", "File type"), self.file_type)
     yield String(self, "name", self["name_len"].value, "File name")
     size = (self._size - self.current_size)//8
     if size:
         yield NullBytes(self, "padding", size)
示例#19
0
 def createFields(self):
     yield UInt32(self, "version")
     yield UInt8(self, "has_realm")
     yield PascalStringWin32(self, "writer_name", charset="UTF-16-BE")
     yield PascalStringWin32(self, "reader_name", charset="UTF-16-BE")
     yield UInt32(self, "file_version")
     size = (self.size - self.current_size) // 8
     if size:
         yield NullBytes(self, "padding", size)
示例#20
0
文件: tar.py 项目: bopopescu/repo-1
 def createFields(self):
     while not self.eof:
         field = FileEntry(self, "file[]")
         if field.isEmpty():
             yield NullBytes(self, "terminator", 512)
             break
         yield field
     if self.current_size < self._size:
         yield self.seekBit(self._size, "end")
示例#21
0
 def createFields(self):
     yield textHandler(
         UInt32(self, "signature",
                "Placeable Metafiles signature (0x9AC6CDD7)"), hexadecimal)
     yield UInt16(self, "handle")
     yield RECT16(self, "rect")
     yield UInt16(self, "inch")
     yield NullBytes(self, "reserved", 4)
     yield textHandler(UInt16(self, "checksum"), hexadecimal)
示例#22
0
 def createFields(self):
     yield NullBytes(self, "unused", 6)
     yield UInt8(self, "offsetIntSize",
                 "Size (in bytes) of offsets in the offset table")
     yield UInt8(self, "objectRefSize",
                 "Size (in bytes) of object numbers in object references")
     yield UInt64(self, "numObjects", "Number of objects in this file")
     yield UInt64(self, "topObject", "Top-level object reference")
     yield UInt64(self, "offsetTableOffset",
                  "File offset to the offset table")
示例#23
0
 def createFields(self):
     yield RawBytes(self, "md5", 16)
     while True:
         size = (self.size - self.current_size) // 8
         if size < 77:
             break
         yield EncryptedItem(self, "item[]")
     size = paddingSize(self.current_size // 8, 16)
     if size:
         yield NullBytes(self, "padding_align", size)
示例#24
0
def parseNames(self):
    # Read header
    yield UInt16(self, "format")
    if self["format"].value != 0:
        raise ParserError("TTF (names): Invalid format (%u)" %
                          self["format"].value)
    yield UInt16(self, "count")
    yield UInt16(self, "offset")
    if MAX_NAME_COUNT < self["count"].value:
        raise ParserError("Invalid number of names (%s)" % self["count"].value)

    # Read name index
    entries = []
    for index in xrange(self["count"].value):
        entry = NameHeader(self, "header[]")
        yield entry
        entries.append(entry)

    # Sort names by their offset
    entries.sort(key=lambda field: field["offset"].value)

    # Read name value
    last = None
    for entry in entries:
        # Skip duplicates values
        new = (entry["offset"].value, entry["length"].value)
        if last and last == new:
            self.warning("Skip duplicate %s %s" % (entry.name, new))
            continue
        last = (entry["offset"].value, entry["length"].value)

        # Skip negative offset
        offset = entry["offset"].value + self["offset"].value
        if offset < self.current_size // 8:
            self.warning("Skip value %s (negative offset)" % entry.name)
            continue

        # Add padding if any
        padding = self.seekByte(offset, relative=True, null=True)
        if padding:
            yield padding

        # Read value
        size = entry["length"].value
        if size:
            yield String(self,
                         "value[]",
                         size,
                         entry.description,
                         charset=entry.getCharset())

    padding = (self.size - self.current_size) // 8
    if padding:
        yield NullBytes(self, "padding_end", padding)
示例#25
0
    def createFields(self):
        addr = self.absolute_address
        while True:
            # Check empty note
            byte = self.stream.readBits(addr, 8, self.endian)
            if not byte:
                yield NullBytes(self, "terminator", 1)
                return

            note = self.NOTE(self, "note[]")
            yield note
            addr += note.size
示例#26
0
 def createFields(self):
     yield UInt8(self, "tag")
     yield UInt24(self, "size", "Content size")
     yield UInt24(self, "timestamp", "Timestamp in millisecond")
     yield NullBytes(self, "reserved", 4)
     size = self["size"].value
     if size:
         if self.parser:
             for field in self.parser(self, size):
                 yield field
         else:
             yield RawBytes(self, "content", size)
示例#27
0
文件: 8svx.py 项目: bopopescu/repo-1
 def createFields(self):
     yield String(self, "type", 4, "Signature (FORM)", charset="ASCII")
     yield filesizeHandler(UInt32(self, "size"))
     size = self["size"].value
     if size:
         if self._parser:
             for field in self._parser(self):
                 yield field
             if size % 2:
                 yield NullBytes(self, "padding", 1)
         else:
             yield RawBytes(self, "data", size)
示例#28
0
文件: ole2.py 项目: bopopescu/repo-1
 def createFields(self):
     yield GUID(self, "clsid", "16 bytes GUID used by some apps")
     yield UInt16(self, "ver_min", "Minor version")
     yield UInt16(self, "ver_maj", "Minor version")
     yield Bytes(self, "endian", 2, "Endian (0xFFFE for Intel)")
     yield UInt16(self, "bb_shift", "Log, base 2, of the big block size")
     yield UInt16(self, "sb_shift", "Log, base 2, of the small block size")
     yield NullBytes(self, "reserved[]", 6, "(reserved)")
     yield UInt32(
         self, "csectdir",
         "Number of SECTs in directory chain for 4 KB sectors (version 4)")
     yield UInt32(self, "bb_count", "Number of Big Block Depot blocks")
     yield SECT(self, "bb_start", "Root start block")
     yield NullBytes(self, "transaction", 4,
                     "Signature used for transactions (must be zero)")
     yield UInt32(self, "threshold",
                  "Maximum size for a mini stream (typically 4096 bytes)")
     yield SECT(self, "sb_start", "Small Block Depot start block")
     yield UInt32(self, "sb_count")
     yield SECT(self, "db_start", "First block of DIFAT")
     yield UInt32(self, "db_count", "Number of SECTs in DIFAT")
示例#29
0
文件: gif.py 项目: bopopescu/repo-1
def parseApplicationExtension(parent):
    yield PascalString8(parent, "app_name", "Application name")
    yield UInt8(parent, "size")
    size = parent["size"].value
    if parent["app_name"].value == "NETSCAPE2.0" and size == 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)
    yield NullBytes(parent, "terminator", 1, "Terminator (0)")
示例#30
0
    def createFields(self):
        yield Enum(textHandler(UInt16(self, "tag", "Tag"), hexadecimal),
                   self.TAG_NAME)
        yield Enum(textHandler(UInt16(self, "type", "Type"), hexadecimal),
                   self.TYPE_NAME)
        yield UInt32(self, "count", "Count")
        if self["type"].value not in (self.TYPE_BYTE, self.TYPE_UNDEFINED) \
        and  MAX_COUNT < self["count"].value:
            raise ParserError("EXIF: Invalid count value (%s)" %
                              self["count"].value)
        value_size, array_size = self.getSizes()

        # Get offset/value
        if not value_size:
            yield NullBytes(self, "padding", 4)
        elif value_size <= 32:
            if 1 < array_size:
                name = "value[]"
            else:
                name = "value"
            kw = {}
            cls = self.value_cls
            if cls is String:
                args = (self, name, value_size / 8, "Value")
                kw["strip"] = " \0"
                kw["charset"] = "ISO-8859-1"
            elif cls is Bytes:
                args = (self, name, value_size / 8, "Value")
            else:
                args = (self, name, "Value")
            for index in xrange(array_size):
                yield cls(*args, **kw)

            size = array_size * value_size
            if size < 32:
                yield NullBytes(self, "padding", (32 - size) // 8)
        else:
            yield UInt32(self, "offset", "Value offset")