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)")
Ejemplo n.º 2
0
 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)")
Ejemplo n.º 3
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)
Ejemplo n.º 4
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")
Ejemplo n.º 5
0
 def createFields(self):
     yield Bytes(self, "signature", 4, r"RealAudio identifier ('.ra\xFD')")
     yield UInt16(self, "version", "Version")
     if self["version"].value == 3:
         yield UInt16(self, "header_size", "Header size")
         yield RawBytes(self, "Unknown1", 10)
         yield UInt32(self, "data_size", "Data size")
         yield Metadata(self, "metadata")
         yield UInt8(self, "Unknown2")
         yield PascalString8(self, "FourCC")
         audio_size = self["data_size"].value
     else: # version = 4
         yield UInt16(self, "reserved1", "Reserved, should be 0")
         yield String(self, "ra4sig", 4, "'.ra4' signature")
         yield UInt32(self, "filesize", "File size (minus 40 bytes)")
         yield UInt16(self, "version2", "Version 2 (always equal to version)")
         yield UInt32(self, "headersize", "Header size (minus 16)")
         yield UInt16(self, "codec_flavor", "Codec flavor")
         yield UInt32(self, "coded_frame_size", "Coded frame size")
         yield RawBytes(self, "unknown1", 12)
         yield UInt16(self, "subpacketh", "Subpacket h (?)")
         yield UInt16(self, "frame_size", "Frame size")
         yield UInt16(self, "sub_packet_size", "Subpacket size")
         yield UInt16(self, "unknown2", "Unknown")
         yield displayHandler(UInt16(self, "sample_rate", "Sample rate"), humanFrequency)
         yield UInt16(self, "unknown3", "Unknown")
         yield UInt16(self, "sample_size", "Sample size")
         yield UInt16(self, "channels", "Channels")
         yield PascalString8(self, "Interleaving ID String")
         yield PascalString8(self, "FourCC")
         yield RawBytes(self, "unknown4", 3)
         yield Metadata(self, "metadata")
         audio_size = (self["filesize"].value + 40) - (self["headersize"].value + 16)
     if 0 < audio_size:
         yield RawBytes(self, "audio_data", audio_size)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
 def createFields(self):
     datas = {}
     for entry in self._ifd:
         if type(entry) != IFDEntry:
             continue
         for c in entry:
             if c.name != "offset":
                 continue
             self.seekByte(c.value, False)
             desc = "data of ifd entry " + entry.name,
             entryType = BasicIFDEntry.ENTRY_FORMAT[entry["type"].value]
             count = entry["count"].value
             if entryType == String:
                 yield String(self, entry.name, count, desc, "\0",
                              "ISO-8859-1")
             else:
                 d = Data(self, entry.name, desc, entryType, count)
                 datas[d.name] = d
                 yield d
             break
     # image data
     if "strip_ofs" in datas and "strip_byte" in datas:
         for i in xrange(datas["strip_byte"]._count):
             self.seekByte(
                 datas["strip_ofs"]["value[" + str(i) + "]"].value, False)
             yield Bytes(self, "strip[]",
                         datas["strip_byte"]["value[" + str(i) + "]"].value)
Ejemplo n.º 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)
Ejemplo n.º 9
0
 def createFields(self):
     yield Bytes(self, "signature", 4, r'File signature ("\1pcf")')
     yield UInt32(self, "nb_toc")
     entries = []
     for index in xrange(self["nb_toc"].value):
         entry = TOC(self, "toc[]")
         yield entry
         entries.append(entry)
     entries.sort(key=lambda entry: entry["offset"].value)
     for entry in entries:
         size = entry["size"].value
         padding = self.seekByte(entry["offset"].value)
         if padding:
             yield padding
         maxsize = (self.size-self.current_size)//8
         if maxsize < size:
             self.warning("Truncate content of %s to %s bytes (was %s)" % (entry.path, maxsize, size))
             size = maxsize
         if not size:
             continue
         if entry["type"].value == 1:
             yield Properties(self, "properties", entry, "Properties", size=size*8)
         elif entry["type"].value == 128:
             yield GlyphNames(self, "glyph_names", entry, "Glyph names", size=size*8)
         else:
             yield RawBytes(self, "data[]", size, "Content of %s" % entry.path)
Ejemplo n.º 10
0
    def createFields(self):
        yield Bytes(self, "header", 4, r"PE header signature (PE\0\0)")
        if self["header"].value != "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")
Ejemplo n.º 11
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")
    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"))
Ejemplo n.º 13
0
    def createFields(self):
        yield Bytes(self, "signature", 4, "Usually the magic is 'FILE'")
        yield UInt16(self, "usa_ofs", "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")

        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) == "\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")
Ejemplo n.º 14
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 != "\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)")
Ejemplo n.º 15
0
 def createFields(self):
     yield Bytes(self, "id", 4, "Tcpdump identifier")
     yield UInt16(self, "maj_ver", "Major version")
     yield UInt16(self, "min_ver", "Minor version")
     yield Int32(self, "this_zone", "GMT to local time zone correction")
     yield Int32(self, "sigfigs", "accuracy of timestamps")
     yield UInt32(self, "snap_len", "max length saved portion of each pkt")
     yield Enum(UInt32(self, "link_type", "data link type"),
                self.LINK_TYPE_DESC)
     link = self["link_type"].value
     if link not in self.LINK_TYPE:
         raise ParserError("Unknown link type: %s" % link)
     name, parser = self.LINK_TYPE[link]
     while self.current_size < self.size:
         yield Packet(self, "packet[]", parser, name)
Ejemplo n.º 16
0
    def createFields(self):
        # Signature
        yield Bytes(self, "ole_id", 8, "OLE object signature")

        header = Header(self, "header")
        yield header

        # Configure values
        self.sector_size = (8 << header["bb_shift"].value)
        self.fat_count = header["bb_count"].value
        self.items_per_bbfat = self.sector_size / SECT.static_size
        self.ss_size = (8 << header["sb_shift"].value)
        self.items_per_ssfat = self.items_per_bbfat

        # Read DIFAT (one level of indirection)
        yield DIFat(self, "difat", header["db_start"].value,
                    header["db_count"].value, "Double Indirection FAT")

        # Read FAT (one level of indirection)
        for field in self.readBFAT():
            yield field

        # Read SFAT
        for field in self.readSFAT():
            yield field

        # Read properties
        chain = self.getChain(self["header/bb_start"].value)
        prop_per_sector = self.sector_size // Property.static_size
        self.properties = []
        for block in chain:
            self.seekBlock(block)
            for index in xrange(prop_per_sector):
                property = Property(self, "property[]")
                yield property
                self.properties.append(property)

        # Parse first property
        for index, property in enumerate(self.properties):
            if index == 0:
                name = "root"
            else:
                try:
                    name = PROPERTY_NAME[property["name"].value]
                except LookupError:
                    name = property.name + "content"
            for field in self.parseProperty(property, name):
                yield field
 def createFields(self):
     if self.version == 1:
         yield TimestampUUID60(self, "time")
         yield Enum(Bits(self, "version", 4), self.VERSION_NAME)
         yield Enum(Bits(self, "variant", 3), self.VARIANT_NAME)
         yield textHandler(Bits(self, "clock", 13), hexadecimal)
         #            yield textHandler(Bits(self, "clock", 16), hexadecimal)
         if self.version == 1:
             yield MAC48_Address(self, "mac", "IEEE 802 MAC address")
         else:
             yield Bytes(self, "node", 6)
     else:
         namea, nameb = self.FIELD_NAMES.get(self.version,
                                             ("data_a", "data_b"))
         yield textHandler(Bits(self, namea, 60), hexadecimal)
         yield Enum(Bits(self, "version", 4), self.VERSION_NAME)
         yield Enum(Bits(self, "variant", 3), self.VARIANT_NAME)
         yield textHandler(Bits(self, nameb, 61), hexadecimal)
Ejemplo n.º 18
0
    def createFields(self):
        yield String(self, "id", 3, "Identifier (BZh)", charset="ASCII")
        yield Character(self, "blocksize",
                        "Block size (KB of memory needed to uncompress)")

        yield UInt8(self, "blockheader", "Block header")
        if self["blockheader"].value == 0x17:
            yield String(self, "id2", 4, "Identifier2 (re8P)", charset="ASCII")
            yield UInt8(self, "id3", "Identifier3 (0x90)")
        elif self["blockheader"].value == 0x31:
            yield String(self,
                         "id2",
                         5,
                         "Identifier 2 (AY&SY)",
                         charset="ASCII")
            if self["id2"].value != "AY&SY":
                raise ParserError("Invalid identifier 2 (AY&SY)!")
        else:
            raise ParserError("Invalid block header!")
        yield textHandler(UInt32(self, "crc32", "CRC32"), hexadecimal)

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

        size = (self._size - self.current_size) / 8
        if size:
            for tag, filename in self.stream.tags:
                if tag == "filename" and filename.endswith(".bz2"):
                    filename = filename[:-4]
                    break
            else:
                filename = None
            data = Bytes(self, "file", size)
            if has_deflate:
                CompressedField(self, Bunzip2)

                def createInputStream(**args):
                    if filename:
                        args.setdefault("tags", []).append(
                            ("filename", filename))
                    return self._createInputStream(**args)

                data._createInputStream = createInputStream
            yield data
Ejemplo n.º 19
0
    def createFields(self):
        yield ZSTHeader(self, "header", "ZST header")  # Offset: 0
        yield ZSTcpu(self, "cpu", "ZST cpu registers")  # 41
        yield ZSTppu(self, "ppu", "ZST CPU registers")  # 72
        yield RawBytes(self, "wram7E", 65536)  # 3091
        yield RawBytes(self, "wram7F", 65536)  # 68627
        yield RawBytes(self, "vram", 65536)  # 134163

        # TODO: Interpret extra on-cart chip data found at/beyond... 199699

        # TODO: Interpret Thumbnail/Screenshot data found at 275291
        # 64*56*2(16bit colors) = 7168
        padding = self.seekByte(275291, relative=False)
        if padding is not None:
            yield padding
        yield Bytes(
            self, "thumbnail", 7168,
            "Thumbnail of playing game in some sort of raw 64x56x16-bit RGB mode?"
        )
Ejemplo n.º 20
0
 def createFields(self):
     yield Bytes(self, "signature", 4, r'ELF signature ("\x7fELF")')
     yield Enum(UInt8(self, "class", "Class"), self.CLASS_NAME)
     yield Enum(UInt8(self, "endian", "Endian"), self.ENDIAN_NAME)
     yield UInt8(self, "file_version", "File version")
     yield String(self, "pad", 8, "Pad")
     yield UInt8(self, "nb_ident", "Size of ident[]")
     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 UInt32(self, "entry", "Number of entries")
     yield UInt32(self, "phoff", "Program header offset")
     yield UInt32(self, "shoff", "Section header offset")
     yield UInt32(self, "flags", "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 entre count")
     yield UInt16(self, "shstrndx", "Section header strtab index")
Ejemplo n.º 21
0
 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")
Ejemplo n.º 22
0
 def createFields(self):
     yield Bytes(self, "magic", 8, "File magic (bplist00)")
     if self.size:
         self.seekByte(self.size // 8 - 32, True)
     else:
         # FIXME: UNTESTED
         while True:
             try:
                 self.seekByte(1024)
             except:
                 break
         self.seekByte(self.size // 8 - 32)
     yield BPListTrailer(self, "trailer")
     self.seekByte(self['trailer/offsetTableOffset'].value)
     yield BPListOffsetTable(self, "offset_table")
     for i in self.array("offset_table/offset"):
         if self.current_size > i.value * 8:
             self.seekByte(i.value)
         elif self.current_size < i.value * 8:
             # try to detect files with gaps or unparsed content
             yield RawBytes(self, "padding[]",
                            i.value - self.current_size // 8)
         yield BPListObject(self, "object[]")
Ejemplo n.º 23
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) == "BZh":
                yield SubFile(self,
                              "content",
                              size,
                              "bzip2 content",
                              parser=Bzip2Parser)
            else:
                yield SubFile(self,
                              "content",
                              size,
                              "gzip content",
                              parser=GzipParser)
Ejemplo n.º 24
0
 def createFields(self):
     if self._size is None:
         self._size = self._getSize()
     yield Bytes(self, "data", self._size / 8)
Ejemplo n.º 25
0
def readOctetString(self, content_size):
    yield Bytes(self, "value", content_size)
Ejemplo n.º 26
0
def readBitString(self, content_size):
    yield UInt8(self, "padding_size", description="Number of unused bits")
    if content_size > 1:
        yield Bytes(self, "value", content_size-1)
Ejemplo n.º 27
0
 def createFields(self):
     yield Bytes(self, "sync", 3)
     yield textHandler(UInt8(self, "tag"), hexadecimal)
     if self.parser and self['tag'].value != 0xb7:
         yield self.parser(self, "content")
Ejemplo n.º 28
0
    def createFields(self):
        yield Enum(
            Bits(self, "marker_type", 4), {
                0: "Simple",
                1: "Int",
                2: "Real",
                3: "Date",
                4: "Data",
                5: "ASCII String",
                6: "UTF-16-BE String",
                8: "UID",
                10: "Array",
                13: "Dict",
            })
        markertype = self['marker_type'].value
        if markertype == 0:
            # Simple (Null)
            yield Enum(Bits(self, "value", 4), {
                0: "Null",
                8: "False",
                9: "True",
                15: "Fill Byte",
            })
            if self['value'].display == "False":
                self.xml = lambda prefix: prefix + "<false/>"
            elif self['value'].display == "True":
                self.xml = lambda prefix: prefix + "<true/>"
            else:
                self.xml = lambda prefix: prefix + ""

        elif markertype == 1:
            # Int
            yield Bits(self, "size", 4, "log2 of number of bytes")
            size = self['size'].value
            # 8-bit (size=0), 16-bit (size=1) and 32-bit (size=2) numbers are unsigned
            # 64-bit (size=3) numbers are signed
            yield GenericInteger(self, "value", (size >= 3), (2**size) * 8)
            self.xml = lambda prefix: prefix + "<integer>%s</integer>" % self[
                'value'].value

        elif markertype == 2:
            # Real
            yield Bits(self, "size", 4, "log2 of number of bytes")
            if self['size'].value == 2:  # 2**2 = 4 byte float
                yield Float32(self, "value")
            elif self['size'].value == 3:  # 2**3 = 8 byte float
                yield Float64(self, "value")
            else:
                # FIXME: What is the format of the real?
                yield Bits(self, "value", (2**self['size'].value) * 8)
            self.xml = lambda prefix: prefix + "<real>%s</real>" % self['value'
                                                                        ].value

        elif markertype == 3:
            # Date
            yield Bits(self, "extra", 4, "Extra value, should be 3")
            cvt_time = lambda v: datetime(2001, 1, 1) + timedelta(seconds=v)
            yield displayHandler(Float64(self, "value"),
                                 lambda x: humanDatetime(cvt_time(x)))
            self.xml = lambda prefix: prefix + "<date>%s</date>" % (cvt_time(
                self['value'].value).isoformat())

        elif markertype == 4:
            # Data
            yield BPListSize(self, "size")
            if self['size'].value:
                yield Bytes(self, "value", self['size'].value)
                self.xml = lambda prefix: prefix + "<data>\n%s\n%s</data>" % (
                    self['value'].value.encode('base64').strip(), prefix)
            else:
                self.xml = lambda prefix: prefix + '<data></data>'

        elif markertype == 5:
            # ASCII String
            yield BPListSize(self, "size")
            if self['size'].value:
                yield String(self,
                             "value",
                             self['size'].value,
                             charset="ASCII")
                self.xml = lambda prefix: prefix + "<string>%s</string>" % (
                    self['value'].value.encode('iso-8859-1'))
            else:
                self.xml = lambda prefix: prefix + '<string></string>'

        elif markertype == 6:
            # UTF-16-BE String
            yield BPListSize(self, "size")
            if self['size'].value:
                yield String(self,
                             "value",
                             self['size'].value * 2,
                             charset="UTF-16-BE")
                self.xml = lambda prefix: prefix + "<string>%s</string>" % (
                    self['value'].value.encode('utf-8'))
            else:
                self.xml = lambda prefix: prefix + '<string></string>'

        elif markertype == 8:
            # UID
            yield Bits(self, "size", 4, "Number of bytes minus 1")
            yield GenericInteger(self, "value", False,
                                 (self['size'].value + 1) * 8)
            self.xml = lambda prefix: prefix + ""  # no equivalent?

        elif markertype == 10:
            # Array
            yield BPListSize(self, "size")
            size = self['size'].value
            if size:
                yield BPListArray(self, "value", size)
                self.xml = lambda prefix: self['value'].createXML(prefix)

        elif markertype == 13:
            # Dict
            yield BPListSize(self, "size")
            yield BPListDict(self, "value", self['size'].value)
            self.xml = lambda prefix: self['value'].createXML(prefix)

        else:
            yield Bits(self, "value", 4)
            self.xml = lambda prefix: ''
Ejemplo n.º 29
0
 def parseData(self):
     size = (self.size - self.current_size) // 8
     if size:
         yield Bytes(self, "data", size)
Ejemplo n.º 30
0
 def createFields(self):
     yield Bytes(self, "id", 8, r"PNG identifier ('\x89PNG\r\n\x1A\n')")
     while not self.eof:
         yield Chunk(self, "chunk[]")