Exemplo n.º 1
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)")
Exemplo n.º 2
0
 def createFields(self):
     yield Bytes(self, "jmp", 3, "Jump instruction (to skip over header on boot)")
     yield String(self, "oem_name", 8, "OEM Name (padded with spaces)", charset="ASCII")
     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)")
Exemplo n.º 3
0
    def __init__(self,
                 parent,
                 name,
                 length,
                 description=None,
                 parser=None,
                 filename=None,
                 mime_type=None,
                 parser_class=None):
        if filename:
            if not isinstance(filename, unicode):
                filename = makePrintable(filename, "ISO-8859-1")
            if not description:
                description = 'File "%s" (%s)' % (filename,
                                                  humanFilesize(length))
        Bytes.__init__(self, parent, name, length, description)

        def createInputStream(cis, **args):
            tags = args.setdefault("tags", [])
            if parser_class:
                tags.append(("class", parser_class))
            if parser is not None:
                tags.append(("id", parser.PARSER_TAGS["id"]))
            if mime_type:
                tags.append(("mime", mime_type))
            if filename:
                tags.append(("filename", filename))
            return cis(**args)

        self.setSubIStream(createInputStream)
Exemplo n.º 4
0
 def __init__(self, parent, name, nbytes,
              description="Padding", pattern=None):
     """ pattern is None or repeated string """
     assert (pattern is None) or (isinstance(pattern, str))
     Bytes.__init__(self, parent, name, nbytes, description)
     self.pattern = pattern
     self._display_pattern = self.checkPattern()
Exemplo n.º 5
0
    def createFields(self):
        yield FIB(self, "FIB", "File Information Block")

        padding = (self['FIB/fcMin'].value - self.current_size // 8)
        if padding:
            yield NullBytes(self, "padding[]", padding)
        if self['FIB/ccpText'].value:
            yield Bytes(self, "text", self['FIB/ccpText'].value)
        if self['FIB/ccpFtn'].value:
            yield Bytes(self, "text_footnote", self['FIB/ccpFtn'].value)
        if self['FIB/ccpHdr'].value:
            yield Bytes(self, "text_header", self['FIB/ccpHdr'].value)
        if self['FIB/ccpMcr'].value:
            yield Bytes(self, "text_macro", self['FIB/ccpMcr'].value)
        if self['FIB/ccpAtn'].value:
            yield Bytes(self, "text_annotation", self['FIB/ccpAtn'].value)

        padding = (self['FIB/fcMax'].value - self.current_size // 8)
        if padding:
            yield RawBytes(self, "padding[]", padding)

        sepx_size = (self['FIB/pnChpFirst'].value * 512 -
                     self.current_size // 8)
        if sepx_size:
            yield SEPXGroup(self, "sepx", sepx_size)
Exemplo n.º 6
0
    def createFields(self):
        yield String(self,
                     "signature",
                     3,
                     "SWF format signature",
                     charset="ASCII")
        yield UInt8(self, "version")
        yield filesizeHandler(UInt32(self, "filesize"))
        if self["signature"].value != "CWS":
            yield RECT(self, "rect")
            yield FixedFloat16(self, "frame_rate")
            yield UInt16(self, "frame_count")

            while not self.eof:
                yield Tag(self, "tag[]")
        else:
            size = (self.size - self.current_size) // 8
            if has_deflate:
                data = Deflate(Bytes(self, "compressed_data", size), False)

                def createInputStream(cis, source=None, **args):
                    stream = cis(source=source)
                    header = StringInputStream("FWS" +
                                               self.stream.readBytes(3 * 8, 5))
                    args.setdefault("tags", []).append(("class", SwfFile))
                    return ConcatStream((header, stream),
                                        source=stream.source,
                                        **args)

                data.setSubIStream(createInputStream)
                yield data
            else:
                yield Bytes(self, "compressed_data", size)
Exemplo n.º 7
0
 def __init__(self, parent, name, nbytes,
              description="Padding", pattern=None):
     """ pattern is None or repeated string """
     assert (pattern is None) or (isinstance(pattern, bytes))
     Bytes.__init__(self, parent, name, nbytes, description)
     self.pattern = pattern
     self._display_pattern = self.checkPattern()
Exemplo n.º 8
0
 def createFields(self):
     if self.rarformat == self.RARFMT14:
         yield Bytes(self, "signature", 4, "RAR signature")
     else:
         yield Bytes(self, "signature", 7, "RAR signature")
     while not self.eof:
         # rar file is build from Blocks, therefore parse each block separately
         yield Block(self, "block[]")
Exemplo n.º 9
0
 def createFields(self):
     yield Bytes(self, "filetype", 4, "File type (INDX)")
     yield Bytes(self, "fileversion", 4, "File version (0?00)")
     yield UInt32(self, "offset[0]")
     yield UInt32(self, "offset[1]")
     self.seekByte(self['offset[0]'].value)
     yield AVCHDINDX_0(self, "chunk[]")
     self.seekByte(self['offset[1]'].value)
     yield AVCHDChunkWithHeader(self, "chunk[]")
Exemplo n.º 10
0
 def createFields(self):
     yield Bytes(self, "filetype", 4, "File type (MOBJ)")
     yield Bytes(self, "fileversion", 4, "File version (0?00)")
     yield RawBytes(self, "unknown[]", 32)
     yield UInt32(self, "size")
     yield UInt32(self, "unknown[]")
     yield UInt16(self, "count")
     yield textHandler(UInt32(self, "unknown_id"), hexadecimal)
     for i in xrange(1, self['count'].value):
         yield AVCHDMOBJ_Chunk(self, "movie_object[]")
Exemplo n.º 11
0
 def createFields(self):
     yield UInt16(self, "size")
     self._size = (self['size'].value + 2) * 8
     yield Bytes(self, "clip_id", 5)
     yield Bytes(self, "clip_type", 4)
     yield RawBytes(self, "unknown[]", 3)
     yield UInt32(self, "clip_start_time[]",
                  "clip start time (units unknown)")
     yield UInt32(self, "clip_end_time[]", "clip end time (units unknown)")
     yield RawBytes(self, "unknown[]", 10)
     yield AVCHDMPLS_PlayItem(self, "playitem")
Exemplo n.º 12
0
 def __init__(self, parent, name, length, decompressor, description=None,
              parser=None, filename=None, mime_type=None, parser_class=None):
     if filename:
         if not isinstance(filename, unicode):
             filename = makePrintable(filename, "ISO-8859-1")
         if not description:
             description = 'File "%s" (%s)' % (
                 filename, humanFilesize(length))
     Bytes.__init__(self, parent, name, length, description)
     self.setupInputStream(decompressor, parser,
                           filename, mime_type, parser_class)
Exemplo n.º 13
0
 def createFields(self):
     yield textHandler(UInt64(self, "id"), hexadecimal)
     if self["id"].value == 0xe7ffdeffe7ffdeff:  # indicates that secure area is decrypted
         yield Bytes(self, "fixed[]", 6)  # always \xff\xde\xff\xe7\xff\xde
         yield Crc16(
             self, "header_crc16",
             self.stream.readBytes(self.absolute_address + (16 * 8),
                                   2048 - 16))
         yield RawBytes(self, "unknown[]", 2048 - 16 - 2)
         yield Bytes(self, "fixed[]", 2)  # always \0\0
     else:
         yield RawBytes(self, "encrypted[]", 2048 - 8)
Exemplo n.º 14
0
    def __init__(self, parent, name, description=None,
                 strip=None, nbytes=None, truncate=None):
        Bytes.__init__(self, parent, name, 1, description)

        self._format = "WidePascalString16"
        self._strip = strip
        self._truncate = truncate
        self._character_size = 2
        self._charset = "UTF-16-LE"
        self._content_offset = 2
        self._content_size = self._character_size * self._parent.stream.readBits(
            self.absolute_address, self._content_offset * 8, self._parent.endian)
        self._size = (self._content_size + self.content_offset) * 8
Exemplo n.º 15
0
    def __init__(self, parent, name, description=None,
                 strip=None, nbytes=None, truncate=None):
        Bytes.__init__(self, parent, name, 1, description)

        self._format = "WidePascalString16"
        self._strip = strip
        self._truncate = truncate
        self._character_size = 2
        self._charset = "UTF-16-LE"
        self._content_offset = 2
        self._content_size = self._character_size * self._parent.stream.readBits(
            self.absolute_address, self._content_offset * 8, self._parent.endian)
        self._size = (self._content_size + self.content_offset) * 8
Exemplo n.º 16
0
    def createFields(self):
        yield Bytes(self, "signature", 4, "Usually the magic is 'FILE'")
        yield UInt16(self, "usa_offset", "Update Sequence Array offset")
        yield UInt16(self, "usa_count", "Update Sequence Array count")
        yield UInt64(self, "lsn", "$LogFile sequence number for this record")
        yield UInt16(self, "sequence_number",
                     "Number of times this mft record has been reused")
        yield UInt16(self, "link_count", "Number of hard links")
        yield UInt16(self, "attrs_offset",
                     "Byte offset to the first attribute")
        yield MFT_Flags(self, "flags")
        yield UInt32(self, "bytes_in_use",
                     "Number of bytes used in this record")
        yield UInt32(self, "bytes_allocated",
                     "Number of bytes allocated for this record")
        yield UInt64(self, "base_mft_record")
        yield UInt16(self, "next_attr_instance")

        # The below fields are specific to NTFS 3.1+ (Windows XP and above)
        yield NullBytes(self, "reserved", 2)
        yield UInt32(self, "mft_record_number", "Number of this mft record")

        if self["usa_offset"].value:
            padding = self.seekByte(self["usa_offset"].value, relative=True)
            if padding:
                yield padding

            yield UInt16(self, "usa_number")
            for i in range(self["usa_count"].value):
                yield UInt16(self, "usa_value[]")

        padding = self.seekByte(self["attrs_offset"].value, relative=True)
        if padding:
            yield padding

        while not self.eof:
            addr = self.absolute_address + self.current_size
            if self.stream.readBytes(addr, 4) == b"\xFF\xFF\xFF\xFF":
                yield Bytes(self, "attr_end_marker", 8)
                break
            yield Attribute(self, "attr[]")

        size = self["bytes_in_use"].value - self.current_size // 8
        if size:
            yield RawBytes(self, "end_rawdata", size)

        size = (self.size - self.current_size) // 8
        if size:
            yield RawBytes(self, "end_padding", size,
                           "Unused but allocated bytes")
Exemplo n.º 17
0
 def createFields(self):
     yield Bytes(self, "signature", 6, "Signature Header")
     yield UInt8(self, "major_ver", "Archive major version")
     yield UInt8(self, "minor_ver", "Archive minor version")
     yield textHandler(UInt32(self, "start_hdr_crc", "Start header CRC"),
                       hexadecimal)
     yield StartHeader(self, "start_hdr", "Start header")
Exemplo n.º 18
0
    def createFields(self):
        yield FIB(self, "FIB", "File Information Block")
        getOLE2Parser(self.ole2, "table" +
                      str(self["FIB/fWhichTblStm"].value))

        padding = (self['FIB/fcMin'].value - self.current_size // 8)
        if padding:
            yield NullBytes(self, "padding[]", padding)

        # Guess whether the file uses UTF16 encoding.
        is_unicode = False
        if self['FIB/array2/ccpText'].value * 2 == self['FIB/fcMax'].value - self['FIB/fcMin'].value:
            is_unicode = True
        for fieldname, textname in [('Text', 'text'), ('Ftn', 'text_footnote'),
                                    ('Hdr', 'text_header'), ('Mcr',
                                                             'text_macro'), ('Atn', 'text_annotation'),
                                    ('Edn', 'text_endnote'), ('Txbx', 'text_textbox'), ('HdrTxbx', 'text_header_textbox')]:
            size = self['FIB/array2/ccp' + fieldname].value
            if size:
                if is_unicode:
                    yield String(self, textname, size * 2, charset="UTF-16-LE")
                else:
                    yield Bytes(self, textname, size)

        padding = (self['FIB/fcMax'].value - self.current_size // 8)
        if padding:
            yield RawBytes(self, "padding[]", padding)
Exemplo n.º 19
0
    def createFields(self):
        yield Bytes(self, "magic", 8, "File magic (BOMStore)")
        yield UInt32(self, "version")  # ?
        yield UInt32(self, "num_objects")
        yield UInt32(self, "trailer_offset")
        yield UInt32(self, "trailer_size")
        yield UInt32(self, "header_offset")
        yield UInt32(self, "header_size")

        yield RawBytes(self, "object[]", 512 - 32, "Null object (size 0, offset 0)")

        self.seekByte(self['trailer_offset'].value)
        yield BomTrailer(self, "trailer")

        self.seekByte(self['header_offset'].value)
        yield RawBytes(self, "header", self['header_size'].value)

        for entry in self['trailer'].array('entry'):
            if entry['size'].value == 0:
                continue
            self.seekByte(entry['offset'].value)
            yield RawBytes(self, "object[]", entry['size'].value)

        for entry in self['trailer'].array('trail'):
            self.seekByte(entry['offset'].value)
            yield RawBytes(self, "trail[]", entry['size'].value)
Exemplo n.º 20
0
 def parseFrameAddress(self):
     yield textHandler(Bytes(self, 'target', 8), formatTargetField)  # MAC or Zeroes
     yield NullBits(self, 'reserved[]', 48)
     yield NullBits(self, 'reserved[]', 6)
     yield Bit(self, 'ack_required')
     yield Bit(self, 'res_required')
     yield UInt8(self, 'sequence')
Exemplo n.º 21
0
    def createFields(self):
        yield Bytes(self, "endian", 2, "Endian (\\xfe\\xff for little endian)")
        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 range(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)
Exemplo n.º 22
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")
Exemplo n.º 23
0
    def createFields(self):
        # Read chunk header
        yield Bytes(self, "signature", 3, r"Property signature (\x8E\xAD\xE8)")
        if self["signature"].value != b"\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(key=lambda field: field["offset"].value)

        # 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)
Exemplo n.º 24
0
    def createFields(self):
        yield Bytes(self, "header", 4, r"PE header signature (PE\0\0)")
        if self["header"].value != b"PE\0\0":
            raise ParserError("Invalid PE header signature")
        yield Enum(UInt16(self, "cpu", "CPU type"), self.cpu_name)
        yield UInt16(self, "nb_section", "Number of sections")
        yield TimestampUnix32(self, "creation_date", "Creation date")
        yield UInt32(self, "ptr_to_sym", "Pointer to symbol table")
        yield UInt32(self, "nb_symbols", "Number of symbols")
        yield UInt16(self, "opt_hdr_size", "Optional header size")

        yield Bit(self, "reloc_stripped",
                  "If true, don't contain base relocations.")
        yield Bit(self, "exec_image", "Executable image?")
        yield Bit(self, "line_nb_stripped", "COFF line numbers stripped?")
        yield Bit(self, "local_sym_stripped",
                  "COFF symbol table entries stripped?")
        yield Bit(self, "aggr_ws", "Aggressively trim working set")
        yield Bit(self, "large_addr",
                  "Application can handle addresses greater than 2 GB")
        yield NullBits(self, "reserved", 1)
        yield Bit(self, "reverse_lo",
                  "Little endian: LSB precedes MSB in memory")
        yield Bit(self, "32bit", "Machine based on 32-bit-word architecture")
        yield Bit(self, "is_stripped", "Debugging information removed?")
        yield Bit(
            self, "swap",
            "If image is on removable media, copy and run from swap file")
        yield PaddingBits(self, "reserved2", 1)
        yield Bit(self, "is_system", "It's a system file")
        yield Bit(self, "is_dll", "It's a dynamic-link library (DLL)")
        yield Bit(self, "up", "File should be run only on a UP machine")
        yield Bit(self, "reverse_hi", "Big endian: MSB precedes LSB in memory")
Exemplo n.º 25
0
 def getFieldType(self):
     info = self.charset
     if self._strip:
         if isinstance(self._strip, (str, unicode)):
             info += ",strip=%s" % makePrintable(self._strip, "ASCII", quote="'")
         else:
             info += ",strip=True"
     return "%s<%s>" % (Bytes.getFieldType(self), info)
Exemplo n.º 26
0
 def getFieldType(self):
     info = self.charset
     if self._strip:
         if isinstance(self._strip, str):
             info += ",strip=%s" % makePrintable(
                 self._strip, "ASCII", quote="'")
         else:
             info += ",strip=True"
     return "%s<%s>" % (Bytes.getFieldType(self), info)
Exemplo n.º 27
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"))
Exemplo n.º 28
0
 def createFields(self):
     yield Bytes(self, "filetype", 4, "File type (HDMV)")
     yield Bytes(self, "fileversion", 4, "File version (0?00)")
     yield UInt32(self, "offset[]")
     yield UInt32(self, "offset[]")
     yield UInt32(self, "offset[]")
     yield UInt32(self, "offset[]")
     yield UInt32(self, "offset[]")
     self.seekByte(self['offset[0]'].value)
     yield AVCHDGenericChunk(self, "chunk[]")
     self.seekByte(self['offset[1]'].value)
     yield AVCHDCLPI_1(self, "chunk[]")
     self.seekByte(self['offset[2]'].value)
     yield AVCHDGenericChunk(self, "chunk[]")
     self.seekByte(self['offset[3]'].value)
     yield AVCHDGenericChunk(self, "chunk[]")
     self.seekByte(self['offset[4]'].value)
     yield AVCHDChunkWithHeader(self, "chunk[]")
Exemplo n.º 29
0
 def createFields(self):
     yield Bytes(self, "sync", 3)
     yield textHandler(UInt8(self, "tag"), hexadecimal)
     if self.parser:
         if self.parser != PackHeader:
             yield UInt16(self, "length")
             if not self["length"].value:
                 return
         yield self.parser(self, "content")
Exemplo n.º 30
0
 def _createInputStream(self, **args):
     tags = args.setdefault("tags", [])
     try:
         tags.append(("mime", self["../../FileMimeType/string"].value))
     except MissingField:
         pass
     filename = self._getFilename()
     if filename:
         tags.append(("filename", filename))
     return Bytes._createInputStream(self, **args)
Exemplo n.º 31
0
 def __init__(self,
              parent,
              name,
              length,
              decompressor,
              description=None,
              parser=None,
              filename=None,
              mime_type=None,
              parser_class=None):
     if filename:
         if not isinstance(filename, str):
             filename = makePrintable(filename, "ISO-8859-1")
         if not description:
             description = 'File "%s" (%s)' % (filename,
                                               humanFilesize(length))
     Bytes.__init__(self, parent, name, length, description)
     self.setupInputStream(decompressor, parser, filename, mime_type,
                           parser_class)
Exemplo n.º 32
0
 def _createInputStream(self, **args):
     tags = args.setdefault("tags", [])
     try:
         tags.append(("mime", self["../../FileMimeType/string"].value))
     except MissingField:
         pass
     filename = self._getFilename()
     if filename:
         tags.append(("filename", filename))
     return Bytes._createInputStream(self, **args)
Exemplo n.º 33
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 != b"\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)")
Exemplo n.º 34
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)
Exemplo n.º 35
0
 def createFields(self):
     yield UInt32(self, "size")
     self._size = (self['size'].value + 4) * 8
     yield UInt32(self, "unknown[]", "24")
     yield UInt32(self, "unknown[]", "1")
     yield UInt32(self, "unknown[]", "0x10000100")
     yield UInt32(self, "unknown[]", "24")
     yield UInt32(self, "size2")
     assert self['size'].value == self['size2'].value + 20
     yield Bytes(self, "magic", 4)
     yield RawBytes(self, "unknown[]", 36)
     for field in self.TYPES[self['magic'].value](self):
         yield field
Exemplo n.º 36
0
    def __init__(self, parent, name, length, description=None,
                 parser=None, filename=None, mime_type=None, parser_class=None):
        if filename:
            if not isinstance(filename, unicode):
                filename = makePrintable(filename, "ISO-8859-1")
            if not description:
                description = 'File "%s" (%s)' % (filename, humanFilesize(length))
        Bytes.__init__(self, parent, name, length, description)

        def createInputStream(cis, **args):
            tags = args.setdefault("tags", [])
            if parser_class:
                tags.append(("class", parser_class))
            if parser is not None:
                tags.append(("id", parser.PARSER_TAGS["id"]))
            if mime_type:
                tags.append(("mime", mime_type))
            if filename:
                tags.append(("filename", filename))
            return cis(**args)

        self.setSubIStream(createInputStream)
Exemplo n.º 37
0
 def createDisplay(self):
     if self._display_pattern:
         return "<null>"
     else:
         return Bytes.createDisplay(self)
Exemplo n.º 38
0
    def __init__(self, parent, name, format, description=None,
                 strip=None, charset=None, nbytes=None, truncate=None):
        Bytes.__init__(self, parent, name, 1, description)

        # Is format valid?
        assert format in self.VALID_FORMATS

        # Store options
        self._format = format
        self._strip = strip
        self._truncate = truncate

        # Check charset and compute character size in bytes
        # (or None when it's not possible to guess character size)
        if not charset or charset in self.CHARSET_8BIT:
            self._character_size = 1  # one byte per character
        elif charset in self.UTF_CHARSET:
            self._character_size = None
        else:
            raise FieldError("Invalid charset for %s: \"%s\"" %
                             (self.path, charset))
        self._charset = charset

        # It is a fixed string?
        if nbytes is not None:
            assert self._format == "fixed"
            # Arbitrary limits, just to catch some bugs...
            if not (1 <= nbytes <= 0xffff):
                raise FieldError("Invalid string size for %s: %s" %
                                 (self.path, nbytes))
            self._content_size = nbytes  # content length in bytes
            self._size = nbytes * 8
            self._content_offset = 0
        else:
            # Format with a suffix: Find the end of the string
            if self._format in self.SUFFIX_FORMAT:
                self._content_offset = 0

                # Choose the suffix
                suffix = self.suffix_str

                # Find the suffix
                length = self._parent.stream.searchBytesLength(
                    suffix, False, self.absolute_address)
                if length is None:
                    raise FieldError("Unable to find end of string %s (format %s)!"
                                     % (self.path, self._format))
                if 1 < len(suffix):
                    # Fix length for little endian bug with UTF-xx charset:
                    #   u"abc" -> "a\0b\0c\0\0\0" (UTF-16-LE)
                    #   search returns length=5, whereas real lenght is 6
                    length = alignValue(length, len(suffix))

                # Compute sizes
                self._content_size = length  # in bytes
                self._size = (length + len(suffix)) * 8

            # Format with a prefix: Read prefixed length in bytes
            else:
                assert self._format in self.PASCAL_FORMATS

                # Get the prefix size
                prefix_size = self.PASCAL_FORMATS[self._format]
                self._content_offset = prefix_size

                # Read the prefix and compute sizes
                value = self._parent.stream.readBits(
                    self.absolute_address, prefix_size * 8, self._parent.endian)
                self._content_size = value  # in bytes
                self._size = (prefix_size + value) * 8

        # For UTF-16 and UTF-32, choose the right charset using BOM
        if self._charset in self.UTF_CHARSET:
            # Charset requires a BOM?
            bomsize, endian = self.UTF_CHARSET[self._charset]
            if endian == "BOM":
                # Read the BOM value
                nbytes = bomsize // 8
                bom = self._parent.stream.readBytes(self.absolute_address, nbytes)

                # Choose right charset using the BOM
                bom_endian = self.UTF_BOM[bomsize]
                if bom not in bom_endian:
                    raise FieldError("String %s has invalid BOM (%s)!"
                                     % (self.path, repr(bom)))
                self._charset = bom_endian[bom]
                self._content_size -= nbytes
                self._content_offset += nbytes

        # Compute length in character if possible
        if self._character_size:
            self._length = self._content_size // self._character_size
        else:
            self._length = None
Exemplo n.º 39
0
 def createDisplay(self):
     if self._display_pattern:
         return u"<padding pattern=%s>" % makePrintable(self.pattern, "ASCII", quote="'")
     else:
         return Bytes.createDisplay(self)
Exemplo n.º 40
0
 def createRawDisplay(self):
     return Bytes.createDisplay(self)
Exemplo n.º 41
0
 def __init__(self, parent):
     Bytes.__init__(self, parent, 'file', parent['size'].value, None)