コード例 #1
0
 def data(self, size):
     compression = self["compression"].value
     if compression == 0:
         return SubFile(self, "data", size, filename=self.filename)
     compressed = SubFile(self, "compressed_data", size, filename=self.filename)
     if compression == COMPRESSION_DEFLATE:
         return Deflate(compressed)
     else:
         return compressed
コード例 #2
0
ファイル: exif.py プロジェクト: markchipman/SickGear
    def createFields(self):
        # Headers
        yield String(self, "header", 6, "Header (Exif\\0\\0)", charset="ASCII")
        if self["header"].value != "Exif\0\0":
            raise ParserError("Invalid EXIF signature!")
        iff_start = self.absolute_address + self.current_size
        ifds = []
        for field in TIFF(self):
            yield field
            if isinstance(field, IFD):
                ifds.append(field)

        for ifd in ifds:
            data = {}
            for i, entry in enumerate(ifd.array('entry')):
                data[entry['tag'].display] = entry
            if 'JPEGInterchangeFormat' in data and 'JPEGInterchangeFormatLength' in data:
                offs = ifd.getEntryValues(
                    data['JPEGInterchangeFormat'])[0].value
                size = ifd.getEntryValues(
                    data['JPEGInterchangeFormatLength'])[0].value
                if size == 0: continue
                self.seekByte(offs + iff_start // 8, relative=False)
                yield SubFile(self,
                              "thumbnail[]",
                              size,
                              "Thumbnail (JPEG file)",
                              mime_type="image/jpeg")
コード例 #3
0
ファイル: msoffice.py プロジェクト: markogle/hachoir3
 def createFields(self):
     yield RawBytes(self, "identifier", 4,
                    "some kind of marker (A0461DF0)")
     yield UInt32(self, "size")
     yield RawBytes(self, "unknown[]", 16)
     yield RawBytes(self, "unknown[]", 1)
     yield SubFile(self, "image", self["size"].value - 17, "Image Data")
コード例 #4
0
ファイル: prs_pak.py プロジェクト: esc777690/LGK-Hub
 def createFields(self):
     yield String(self, "filename", 56, truncate="\0")
     yield filesizeHandler(UInt32(self, "size"))
     yield SubFile(self,
                   "data",
                   self["size"].value,
                   filename=self["filename"].value)
コード例 #5
0
ファイル: swf.py プロジェクト: markchipman/SickGear
def parseJpeg(parent, size):
    yield UInt16(parent, "char_id", "Character identifier")
    size -= 2

    code = parent["code"].value
    if code != Tag.TAG_BITS:
        if code == Tag.TAG_BITS_JPEG3:
            yield UInt32(parent, "alpha_offset", "Character identifier")
            size -= 4

        addr = parent.absolute_address + parent.current_size + 16
        if parent.stream.readBytes(addr, 2) in ("\xff\xdb", "\xff\xd8"):
            header = JpegHeader(parent, "jpeg_header")
            yield header
            hdr_size = header.size // 8
            size -= hdr_size
        else:
            hdr_size = 0

        if code == Tag.TAG_BITS_JPEG3:
            img_size = parent["alpha_offset"].value - hdr_size
        else:
            img_size = size
    else:
        img_size = size
    yield SubFile(parent, "image", img_size, "JPEG picture", parser=JpegFile)
    if code == Tag.TAG_BITS_JPEG3:
        size = (parent.size - parent.current_size) // 8
        yield RawBytes(parent, "alpha", size, "Image data")
コード例 #6
0
ファイル: mar.py プロジェクト: esc777690/LGK-Hub
 def createFields(self):
     yield String(self,
                  "magic",
                  4,
                  "File signature (MARC)",
                  charset="ASCII")
     yield UInt32(self, "version")
     yield UInt32(self, "nb_file")
     files = []
     for index in range(self["nb_file"].value):
         item = FileIndex(self, "file[]")
         yield item
         if item["filesize"].value:
             files.append(item)
     files.sort(key=lambda item: item["offset"].value)
     for index in files:
         padding = self.seekByte(index["offset"].value)
         if padding:
             yield padding
         size = index["filesize"].value
         desc = "File %s" % index["filename"].value
         yield SubFile(self,
                       "data[]",
                       size,
                       desc,
                       filename=index["filename"].value)
コード例 #7
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))
コード例 #8
0
    def createFields(self):
        yield String(self, "name", 100, "Name", strip="\0", charset="ISO-8859-1")
        yield String(self, "mode", 8, "Mode", strip=" \0", charset="ASCII")
        yield String(self, "uid", 8, "User ID", strip=" \0", charset="ASCII")
        yield String(self, "gid", 8, "Group ID", strip=" \0", charset="ASCII")
        yield String(self, "size", 12, "Size", strip=" \0", charset="ASCII")
        yield String(self, "mtime", 12, "Modification time", strip=" \0", charset="ASCII")
        yield String(self, "check_sum", 8, "Check sum", strip=" \0", charset="ASCII")
        yield Enum(UInt8(self, "type", "Type"), self.type_name)
        yield String(self, "lname", 100, "Link name", strip=" \0", charset="ISO-8859-1")
        yield String(self, "magic", 8, "Magic", strip=" \0", charset="ASCII")
        yield String(self, "uname", 32, "User name", strip=" \0", charset="ISO-8859-1")
        yield String(self, "gname", 32, "Group name", strip=" \0", charset="ISO-8859-1")
        yield String(self, "devmajor", 8, "Dev major", strip=" \0", charset="ASCII")
        yield String(self, "devminor", 8, "Dev minor", strip=" \0", charset="ASCII")
        yield String(self, "prefix", 155, "Prefix for filename", strip="\0", charset="ASCII")
        yield NullBytes(self, "padding", 12, "Padding (zero)")

        filesize = self.getOctal("size")
        if filesize:
            yield SubFile(self, "content", filesize, filename=self["name"].value)

        size = paddingSize(self.current_size // 8, 512)
        if size:
            yield NullBytes(self, "padding_end", size, "Padding (512 align)")
コード例 #9
0
ファイル: gzip_parser.py プロジェクト: markchipman/SickGear
    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"))
コード例 #10
0
    def createFields(self):
        # Header
        yield Header(self, "header")

        # Secure Area
        if self["header"]["arm9_source"].value >= 0x4000 and self["header"][
                "arm9_source"].value < 0x8000:
            secStart = self["header"]["arm9_source"].value & 0xfffff000
            self.seekByte(secStart, relative=False)
            yield SecureArea(self, "secure_area", size=0x8000 - secStart)

        # ARM9 binary
        self.seekByte(self["header"]["arm9_source"].value, relative=False)
        yield RawBytes(self, "arm9_bin", self["header"]["arm9_bin_size"].value)

        # ARM7 binary
        self.seekByte(self["header"]["arm7_source"].value, relative=False)
        yield RawBytes(self, "arm7_bin", self["header"]["arm7_bin_size"].value)

        # File Name Table
        if self["header"]["filename_table_size"].value > 0:
            self.seekByte(self["header"]["filename_table_offset"].value,
                          relative=False)
            yield FileNameTable(
                self,
                "filename_table",
                size=self["header"]["filename_table_size"].value * 8)

        # FAT
        if self["header"]["fat_size"].value > 0:
            self.seekByte(self["header"]["fat_offset"].value, relative=False)
            yield FATContent(self,
                             "fat_content",
                             size=self["header"]["fat_size"].value * 8)

        # banner
        if self["header"]["banner_offset"].value > 0:
            self.seekByte(self["header"]["banner_offset"].value,
                          relative=False)
            yield Banner(self, "banner")

        # ARM9 overlays
        if self["header"]["arm9_overlay_src"].value > 0:
            self.seekByte(self["header"]["arm9_overlay_src"].value,
                          relative=False)
            numOvls = self["header"]["arm9_overlay_size"].value // (8 * 4)
            for i in range(numOvls):
                yield Overlay(self, "arm9_overlay[]")

        # files
        if self["header"]["fat_size"].value > 0:
            for field in self["fat_content"]:
                if field["end"].value > field["start"].value:
                    self.seekByte(field["start"].value, relative=False)
                    yield SubFile(self, "file[]",
                                  field["end"].value - field["start"].value)
コード例 #11
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")
コード例 #12
0
    def createFields(self):
        yield Bytes(self, "signature", 4, r"RPM file signature (\xED\xAB\xEE\xDB)")
        yield UInt8(self, "major_ver", "Major version")
        yield UInt8(self, "minor_ver", "Minor version")
        yield Enum(UInt16(self, "type", "RPM type"), RpmFile.TYPE_NAME)
        yield UInt16(self, "architecture", "Architecture")
        yield String(self, "name", 66, "Archive name", strip="\0", charset="ASCII")
        yield UInt16(self, "os", "OS")
        yield UInt16(self, "signature_type", "Type of signature")
        yield NullBytes(self, "reserved", 16, "Reserved")
        yield PropertySet(self, "checksum", "Checksum (signature)")
        yield PropertySet(self, "header", "Header")

        if self._size is None:  # TODO: is it possible to handle piped input?
            raise NotImplementedError

        size = (self._size - self.current_size) // 8
        if size:
            if 3 <= size and self.stream.readBytes(self.current_size, 3) == b"BZh":
                yield SubFile(self, "content", size, "bzip2 content", parser=Bzip2Parser)
            else:
                yield SubFile(self, "content", size, "gzip content", parser=GzipParser)
コード例 #13
0
 def createFields(self):
     yield PascalString32UTF16(self, "filename")
     yield Bytes(self, "property", 4)
     yield Bytes(self, "type", 4)
     type = self['type'].value
     if type == 'long':
         yield UInt32(self, "value")
     elif type == 'shor':
         yield NullBytes(self, "padding", 2)
         yield UInt16(self, "value")
     elif type == 'bool':
         yield UInt8(self, "value")
     elif type == 'blob':
         yield UInt32(self, "size")
         yield SubFile(self, "value", self['size'].value)
     elif type == 'type':
         yield Bytes(self, "value", 4)
     elif type == 'ustr':
         yield PascalString32UTF16(self, "value")
     else:
         raise ParserError("Unknown record type %s" % type)
コード例 #14
0
ファイル: riff.py プロジェクト: esc777690/LGK-Hub
def parseIcon(self):
    yield SubFile(self, "icon_file", self["size"].value, parser_class=IcoFile)