예제 #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
파일: swf.py 프로젝트: tattoomees/SickRage
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")
예제 #3
0
파일: mar.py 프로젝트: tattoomees/SickRage
 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 xrange(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)
 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!")
     yield String(self, "byte_order", 2, "Byte order", charset="ASCII")
     if self["byte_order"].value not in ("II", "MM"):
         raise ParserError("Invalid endian!")
     if self["byte_order"].value == "II":
         self.endian = LITTLE_ENDIAN
     else:
         self.endian = BIG_ENDIAN
     yield UInt16(self, "version", "TIFF version number")
     yield UInt32(self, "img_dir_ofs", "Next image directory offset")
     while not self.eof:
         addr = self.absolute_address + self.current_size
         tag = self.stream.readBits(addr, 16, NETWORK_ENDIAN)
         if tag == 0xFFD8:
             size = (self._size - self.current_size) // 8
             yield SubFile(self,
                           "thumbnail",
                           size,
                           "Thumbnail (JPEG file)",
                           mime_type="image/jpeg")
             break
         elif tag == 0xFFFF:
             break
         yield ExifIFD(self, "ifd[]", "IFD")
     padding = self.seekBit(self._size)
     if padding is not None:
         yield padding
    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"))
예제 #6
0
파일: rpm.py 프로젝트: tattoomees/SickRage
    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) == "BZh":
                yield SubFile(self,
                              "content",
                              size,
                              "bzip2 content",
                              parser=Bzip2Parser)
            else:
                yield SubFile(self,
                              "content",
                              size,
                              "gzip content",
                              parser=GzipParser)
예제 #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))
    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 NullBytes(self, "padding", 167, "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)")
def parseIcon(self):
    yield SubFile(self, "icon_file", self["size"].value, parser_class=IcoFile)