Пример #1
0
    def createFields(self):
        # Version 2 (12 bytes)
        yield UInt32(self, "header_size", "Header size")
        yield UInt32(self, "width", "Width (pixels)")
        yield UInt32(self, "height", "Height (pixels)")
        yield UInt16(self, "nb_plan", "Number of plan (=1)")
        yield UInt16(self, "bpp",
                     "Bits per pixel")  # may be zero for PNG/JPEG picture

        # Version 3 (40 bytes)
        if self["header_size"].value < 40:
            return
        yield Enum(UInt32(self, "compression", "Compression method"),
                   BmpFile.COMPRESSION_NAME)
        yield UInt32(self, "image_size", "Image size (bytes)")
        yield UInt32(self, "horizontal_dpi", "Horizontal DPI")
        yield UInt32(self, "vertical_dpi", "Vertical DPI")
        yield UInt32(self, "used_colors", "Number of color used")
        yield UInt32(self, "important_color", "Number of import colors")

        # Version 4 (108 bytes)
        if self["header_size"].value < 108:
            return
        yield textHandler(UInt32(self, "red_mask"), hexadecimal)
        yield textHandler(UInt32(self, "green_mask"), hexadecimal)
        yield textHandler(UInt32(self, "blue_mask"), hexadecimal)
        yield textHandler(UInt32(self, "alpha_mask"), hexadecimal)
        yield Enum(UInt32(self, "color_space"), self.color_space_name)
        yield CIEXYZ(self, "red_primary")
        yield CIEXYZ(self, "green_primary")
        yield CIEXYZ(self, "blue_primary")
        yield UInt32(self, "gamma_red")
        yield UInt32(self, "gamma_green")
        yield UInt32(self, "gamma_blue")
Пример #2
0
def fileHeader(self):
    yield filesizeHandler(
        UInt32(self, "compressed_size", "Size of the compressed file"))
    yield filesizeHandler(
        UInt32(self, "uncompressed_size", "Uncompressed file size"))
    yield TimeDateMSDOS32(self, "ftime", "Date and time (MS DOS format)")
    if self["/header/host_os"].value in (OS_MSDOS, OS_WIN32):
        yield MSDOSFileAttr32(self, "file_attr", "File attributes")
    else:
        yield textHandler(UInt32(self, "file_attr", "File attributes"),
                          hexadecimal)
    yield textHandler(
        UInt32(self, "file_crc32", "CRC32 checksum over the compressed file)"),
        hexadecimal)
    yield Enum(UInt8(self, "compression_type", "Type of compression"),
               COMPRESSION_TYPE)
    yield Enum(UInt8(self, "compression_mode", "Quality of compression"),
               COMPRESSION_MODE)
    yield textHandler(UInt16(self, "parameters", "Compression parameters"),
                      hexadecimal)
    yield textHandler(UInt16(self, "reserved", "Reserved data"), hexadecimal)
    # Filename
    yield PascalString16(self, "filename", "Filename")
    # Comment
    if self["flags/has_comment"].value:
        yield filesizeHandler(
            UInt16(self, "comment_size", "Size of the compressed comment"))
        if self["comment_size"].value > 0:
            yield RawBytes(self, "comment_data", self["comment_size"].value,
                           "Comment data")
Пример #3
0
    def createFields(self):
        yield textHandler(
            UInt32(self, "magic", "File information magic (0xFEEF04BD)"),
            hexadecimal)
        if self["magic"].value != 0xFEEF04BD:
            raise ParserError("EXE resource: invalid file info magic")
        yield Version(self, "struct_ver", "Structure version (1.0)")
        yield Version(self, "file_ver_ms", "File version MS")
        yield Version(self, "file_ver_ls", "File version LS")
        yield Version(self, "product_ver_ms", "Product version MS")
        yield Version(self, "product_ver_ls", "Product version LS")
        yield textHandler(UInt32(self, "file_flags_mask"), hexadecimal)

        yield Bit(self, "debug")
        yield Bit(self, "prerelease")
        yield Bit(self, "patched")
        yield Bit(self, "private_build")
        yield Bit(self, "info_inferred")
        yield Bit(self, "special_build")
        yield NullBits(self, "reserved", 26)

        yield Enum(textHandler(UInt16(self, "file_os_major"), hexadecimal),
                   MAJOR_OS_NAME)
        yield Enum(textHandler(UInt16(self, "file_os_minor"), hexadecimal),
                   MINOR_OS_NAME)
        yield Enum(textHandler(UInt32(self, "file_type"), hexadecimal),
                   FILETYPE_NAME)
        field = textHandler(UInt32(self, "file_subfile"), hexadecimal)
        if field.value == FILETYPE_DRIVER:
            field = Enum(field, DRIVER_SUBTYPE_NAME)
        elif field.value == FILETYPE_FONT:
            field = Enum(field, FONT_SUBTYPE_NAME)
        yield field
        yield TimestampUnix32(self, "date_ms")
        yield TimestampUnix32(self, "date_ls")
Пример #4
0
    def createFields(self):
        yield Enum(UInt16(self, "src"), self.port_name)
        yield Enum(UInt16(self, "dst"), self.port_name)
        yield UInt32(self, "seq_num")
        yield UInt32(self, "ack_num")

        yield Bits(self, "hdrlen", 6, "Header lenght")
        yield NullBits(self, "reserved", 2, "Reserved")

        yield Bit(self, "cgst", "Congestion Window Reduced")
        yield Bit(self, "ecn-echo", "ECN-echo")
        yield Bit(self, "urg", "Urgent")
        yield Bit(self, "ack", "Acknowledge")
        yield Bit(self, "psh", "Push mmode")
        yield Bit(self, "rst", "Reset connection")
        yield Bit(self, "syn", "Synchronize")
        yield Bit(self, "fin", "Stop the connection")

        yield UInt16(self, "winsize", "Windows size")
        yield textHandler(UInt16(self, "checksum"), hexadecimal)
        yield UInt16(self, "urgent")

        size = self["hdrlen"].value * 8 - self.current_size
        while 0 < size:
            option = TCP_Option(self, "option[]")
            yield option
            size -= option.size
Пример #5
0
 def createFields(self):
     yield NullBytes(self, "options", 4)
     yield TimestampUnix32(self, "creation_date")
     yield UInt16(self, "maj_ver", "Major version")
     yield UInt16(self, "min_ver", "Minor version")
     yield UInt16(self, "nb_name", "Number of named entries")
     yield UInt16(self, "nb_index", "Number of indexed entries")
Пример #6
0
 def createFields(self):
     yield Enum(UInt16(self, "field_id", "Extra field ID"),
                self.EXTRA_FIELD_ID)
     size = UInt16(self, "field_data_size", "Extra field data size")
     yield size
     if size.value > 0:
         yield RawBytes(self, "field_data", size, "Unknown field data")
Пример #7
0
 def createFields(self):
     yield textHandler(UInt32(self, "signature", "Placeable Metafiles signature (0x9AC6CDD7)"), hexadecimal)
     yield UInt16(self, "handle")
     yield RECT16(self, "rect")
     yield UInt16(self, "inch")
     yield NullBytes(self, "reserved", 4)
     yield textHandler(UInt16(self, "checksum"), hexadecimal)
Пример #8
0
def parseCommon(self):
    yield UInt16(self, "nb_channel")
    yield UInt32(self, "nb_sample")
    yield UInt16(self, "sample_size")
    yield Float80(self, "sample_rate")
    yield Enum(String(self, "codec", 4, strip="\0", charset="ASCII"),
               CODEC_NAME)
Пример #9
0
    def createFields(self):
        yield String(self, "magic", 4, "Magic (MSCF)", charset="ASCII")
        yield textHandler(UInt32(self, "hdr_checksum", "Header checksum (0 if not used)"), hexadecimal)
        yield filesizeHandler(UInt32(self, "filesize", "Cabinet file size"))
        yield textHandler(UInt32(self, "fld_checksum", "Folders checksum (0 if not used)"), hexadecimal)
        yield UInt32(self, "off_file", "Offset of first file")
        yield textHandler(UInt32(self, "files_checksum", "Files checksum (0 if not used)"), hexadecimal)
        yield textHandler(UInt16(self, "cab_version", "Cabinet version"), hexadecimal)
        yield UInt16(self, "nb_folder", "Number of folders")
        yield UInt16(self, "nb_files", "Number of files")
        yield Flags(self, "flags")
        yield UInt16(self, "setid")
        yield UInt16(self, "number", "Zero-based cabinet number")

        # --- TODO: Support flags
        if self["flags/has_reserved"].value:
            yield Reserved(self, "reserved")
        #(3) Previous cabinet name, if CAB_HEADER.flags & CAB_FLAG_HASPREV
        #(4) Previous disk name, if CAB_HEADER.flags & CAB_FLAG_HASPREV
        #(5) Next cabinet name, if CAB_HEADER.flags & CAB_FLAG_HASNEXT
        #(6) Next disk name, if CAB_HEADER.flags & CAB_FLAG_HASNEXT
        # ----

        for index in xrange(self["nb_folder"].value):
            yield Folder(self, "folder[]")
        for index in xrange(self["nb_files"].value):
            yield File(self, "file[]")

        end = self.seekBit(self.size, "endraw")
        if end:
            yield end
Пример #10
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)
Пример #11
0
    def createUnpaddedFields(self):
        yield String(self, "title", 28, strip='\0')
        yield textHandler(UInt8(self, "marker[]"), hexadecimal)
        for field in self.getFileVersionField():
            yield field

        yield UInt16(self, "num_orders")
        yield UInt16(self, "num_instruments")
        yield UInt16(self, "num_patterns")

        for field in self.getFirstProperties():
            yield field
        yield String(self, "marker[]", 4)
        for field in self.getLastProperties():
            yield field

        yield GenericVector(self, "channel_settings", 32, ChannelSettings,
                            "channel")

        # Orders
        yield GenericVector(self, "orders", self.getNumOrders(), UInt8,
                            "order")

        for field in self.getHeaderEndFields():
            yield field
Пример #12
0
    def createFields(self):
        yield UInt16(self, "size", "Node size (in bytes)")
        yield UInt16(self, "data_size")
        yield Enum(UInt16(self, "type"), self.TYPE_NAME)
        yield CString(self, "name", charset="UTF-16-LE")

        size = paddingSize(self.current_size // 8, 4)
        if size:
            yield NullBytes(self, "padding[]", size)
        size = self["data_size"].value
        if size:
            if self["type"].value == self.TYPE_STRING:
                if self.is_32bit:
                    size *= 2
                yield String(self,
                             "value",
                             size,
                             charset="UTF-16-LE",
                             truncate="\0")
            elif self["name"].value == "VS_VERSION_INFO":
                yield VersionInfoBinary(self, "value", size=size * 8)
                if self["value/file_flags_mask"].value == 0:
                    self.is_32bit = False
            else:
                yield RawBytes(self, "value", size)
        while 12 <= (self.size - self.current_size) // 8:
            yield VersionInfoNode(self, "node[]", self.is_32bit)
        size = (self.size - self.current_size) // 8
        if size:
            yield NullBytes(self, "padding[]", size)
Пример #13
0
    def createFields(self):
        LONG = Int32
        yield UInt32(self, "type", "Record type (always 1)")
        yield UInt32(self, "size", "Size of the header in bytes")
        yield RECT32(self, "Bounds", "Inclusive bounds")
        yield RECT32(self, "Frame", "Inclusive picture frame")
        yield textHandler(UInt32(self, "signature", "Signature ID (always 0x464D4520)"), hexadecimal)
        yield UInt16(self, "min_ver", "Minor version")
        yield UInt16(self, "maj_ver", "Major version")
        yield UInt32(self, "file_size", "Size of the file in bytes")
        yield UInt32(self, "NumOfRecords", "Number of records in the metafile")
        yield UInt16(self, "NumOfHandles", "Number of handles in the handle table")
        yield NullBytes(self, "reserved", 2)
        yield UInt32(self, "desc_size", "Size of description in 16-bit words")
        yield UInt32(self, "desc_ofst", "Offset of description string in metafile")
        yield UInt32(self, "nb_colors", "Number of color palette entries")
        yield LONG(self, "width_px", "Width of reference device in pixels")
        yield LONG(self, "height_px", "Height of reference device in pixels")
        yield LONG(self, "width_mm", "Width of reference device in millimeters")
        yield LONG(self, "height_mm", "Height of reference device in millimeters")

        # Read description (if any)
        offset = self["desc_ofst"].value
        current = (self.absolute_address + self.current_size) // 8
        size = self["desc_size"].value * 2
        if offset == current and size:
            yield String(self, "description", size, charset="UTF-16-LE", strip="\0 ")

        # Read padding (if any)
        size = self["size"].value - self.current_size//8
        if size:
            yield RawBytes(self, "padding", size)
def parseDeclareFunction(parent, size):
    yield CString(parent, "name")
    argCount = UInt16(parent, "arg_count")
    yield argCount
    for i in range(argCount.value):
        yield CString(parent, "arg[]")
    yield UInt16(parent, "function_length")
Пример #15
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")
Пример #16
0
    def createFields(self):
        yield ZipVersion(self, "version_made_by", "Version made by")
        for field in ZipStartCommonFields(self):
            yield field

        # Check unicode status
        charset = zipGetCharset(self)

        yield UInt16(self, "comment_length", "Comment length")
        yield UInt16(self, "disk_number_start", "Disk number start")
        yield UInt16(self, "internal_attr", "Internal file attributes")
        yield UInt32(self, "external_attr", "External file attributes")
        yield UInt32(self, "offset_header", "Relative offset of local header")
        yield String(self,
                     "filename",
                     self["filename_length"].value,
                     "Filename",
                     charset=charset)
        if 0 < self["extra_length"].value:
            yield RawBytes(self, "extra", self["extra_length"].value,
                           "Extra fields")
        if 0 < self["comment_length"].value:
            yield String(self,
                         "comment",
                         self["comment_length"].value,
                         "Comment",
                         charset=charset)
Пример #17
0
 def createFields(self):
     yield String(self, "name", 22, strip='\0')
     yield UInt16(self, "sample_count")
     yield textHandler(UInt8(self, "fine_tune"), getFineTune)
     yield textHandler(UInt8(self, "volume"), getVolume)
     yield UInt16(self, "loop_start", "Loop start offset in samples")
     yield UInt16(self, "loop_len", "Loop length in samples")
Пример #18
0
    def createFields(self):
        yield String(self,
                     "signature",
                     4,
                     "PSD signature (8BPS)",
                     charset="ASCII")
        yield UInt16(self, "version")
        yield NullBytes(self, "reserved[]", 6)
        yield UInt16(self, "nb_channels")
        yield UInt32(self, "width")
        yield UInt32(self, "height")
        yield UInt16(self, "depth")
        yield Enum(UInt16(self, "color_mode"), self.COLOR_MODE)

        # Mode data
        yield UInt32(self, "mode_data_size")
        size = self["mode_data_size"].value
        if size:
            yield RawBytes(self, "mode_data", size)

        # Resources
        yield Config(self, "config")

        # Reserved
        yield UInt32(self, "reserved_data_size")
        size = self["reserved_data_size"].value
        if size:
            yield RawBytes(self, "reserved_data", size)

        yield Enum(UInt16(self, "compression"), self.COMPRESSION_NAME)

        size = (self.size - self.current_size) // 8
        if size:
            yield RawBytes(self, "end", size)
def parseCode(parent):
    if 0x3000000 <= parent.root.getVersion():
        yield UInt32(parent, "arg_count", "Argument count")
        yield UInt32(parent, "kwonlyargcount", "Keyword only argument count")
        yield UInt32(parent, "nb_locals", "Number of local variables")
        yield UInt32(parent, "stack_size", "Stack size")
        yield UInt32(parent, "flags")
    elif 0x2030000 <= parent.root.getVersion():
        yield UInt32(parent, "arg_count", "Argument count")
        yield UInt32(parent, "nb_locals", "Number of local variables")
        yield UInt32(parent, "stack_size", "Stack size")
        yield UInt32(parent, "flags")
    else:
        yield UInt16(parent, "arg_count", "Argument count")
        yield UInt16(parent, "nb_locals", "Number of local variables")
        yield UInt16(parent, "stack_size", "Stack size")
        yield UInt16(parent, "flags")
    yield Object(parent, "compiled_code")
    yield Object(parent, "consts")
    yield Object(parent, "names")
    yield Object(parent, "varnames")
    if 0x2000000 <= parent.root.getVersion():
        yield Object(parent, "freevars")
        yield Object(parent, "cellvars")
    yield Object(parent, "filename")
    yield Object(parent, "name")
    if 0x2030000 <= parent.root.getVersion():
        yield UInt32(parent, "firstlineno", "First line number")
    else:
        yield UInt16(parent, "firstlineno", "First line number")
    yield Object(parent, "lnotab")
    def createFields(self):
        # Header
        yield NullBytes(self, "zero_vector", 16)
        yield GUID(self, "fs_guid")
        yield UInt64(self, "volume_len")
        yield String(self, "signature", 4)
        yield UInt32(self, "attributes")
        yield UInt16(self, "header_len")
        yield UInt16(self, "checksum")
        yield UInt16(self, "ext_header_offset")
        yield UInt8(self, "reserved")
        yield UInt8(self, "revision")
        while True:
            bm = BlockMap(self, "block_map[]")
            yield bm
            if bm['num_blocks'].value == 0 and bm['len'].value == 0:
                break
        # TODO must handle extended header

        # Content
        while not self.eof:
            padding = paddingSize(self.current_size // 8, 8)
            if padding:
                yield PaddingBytes(self, "padding[]", padding)
            yield File(self, "file[]")
Пример #21
0
    def createFields(self):
        yield Bits(self, "version", 4, "Version")
        yield Bits(self, "hdr_size", 4, "Header size divided by 5")

        # Type of service
        yield Enum(Bits(self, "precedence", 3, "Precedence"),
                   self.precedence_name)
        yield Bit(self, "low_delay", "If set, low delay, else normal delay")
        yield Bit(self, "high_throu",
                  "If set, high throughput, else normal throughput")
        yield Bit(self, "high_rel", "If set, high relibility, else normal")
        yield NullBits(self, "reserved[]", 2, "(reserved for future use)")

        yield UInt16(self, "length")
        yield UInt16(self, "id")

        yield NullBits(self, "reserved[]", 1)
        yield Bit(self, "df", "Don't fragment")
        yield Bit(self, "more_frag",
                  "There are more fragments? if not set, it's the last one")
        yield Bits(self, "frag_ofst_lo", 5)
        yield UInt8(self, "frag_ofst_hi")
        yield UInt8(self, "ttl", "Type to live")
        yield Enum(UInt8(self, "protocol"), self.PROTOCOL_NAME)
        yield textHandler(UInt16(self, "checksum"), hexadecimal)
        yield IPv4_Address(self, "src")
        yield IPv4_Address(self, "dst")

        size = (self.size - self.current_size) // 8
        if size:
            yield RawBytes(self, "options", size)
Пример #22
0
    def createFields(self):
        yield UInt16(self, "length", "Length of Item ID Entry")
        if not self["length"].value:
            return

        yield Enum(UInt8(self, "type"),self.ITEM_TYPE)
        entrytype=self["type"].value
        if entrytype in (0x1F, 0x2E, 0x70):
            # GUID
            yield RawBytes(self, "dummy", 1, "should be 0x50")
            yield GUID(self, "guid")

        elif entrytype in (0x23, 0x25, 0x29, 0x2F):
            # Drive
            yield String(self, "drive", self["length"].value-3, strip="\0")

        elif entrytype in (0x30, 0x31, 0x32):
            yield RawBytes(self, "dummy", 1, "should be 0x00")
            yield UInt32(self, "size", "size of file; 0 for folders")
            yield DateTimeMSDOS32(self, "date_time", "File/folder date and time")
            yield MSDOSFileAttr16(self, "attribs", "File/folder attributes")
            yield CString(self, "name", "File/folder name")
            if self.root.hasUnicodeNames():
                # Align to 2-bytes
                n = paddingSize(self.current_size//8, 2)
                if n:
                    yield PaddingBytes(self, "pad", n)

                yield UInt16(self, "length_w", "Length of wide struct member")
                yield RawBytes(self, "unknown[]", 6)
                yield DateTimeMSDOS32(self, "creation_date_time", "File/folder creation date and time")
                yield DateTimeMSDOS32(self, "access_date_time", "File/folder last access date and time")
                yield RawBytes(self, "unknown[]", 4)
                yield CString(self, "unicode_name", "File/folder name", charset="UTF-16-LE")
                yield RawBytes(self, "unknown[]", 2)
            else:
                yield CString(self, "name_short", "File/folder short name")

        elif entrytype in (0x41, 0x42, 0x46):
            yield RawBytes(self, "unknown[]", 2)
            yield CString(self, "name")
            yield CString(self, "protocol")
            yield RawBytes(self, "unknown[]", 2)

        elif entrytype == 0x47:
            # Whole Network
            yield RawBytes(self, "unknown[]", 2)
            yield CString(self, "name")

        elif entrytype == 0xC3:
            # Network Share
            yield RawBytes(self, "unknown[]", 2)
            yield CString(self, "name")
            yield CString(self, "protocol")
            yield CString(self, "description")
            yield RawBytes(self, "unknown[]", 2)

        else:
            yield RawBytes(self, "raw", self["length"].value-3)
Пример #23
0
    def createFields(self):
        yield Enum(UInt8(self, "type"), self.TYPE_DESC)
        yield UInt8(self, "code")
        yield textHandler(UInt16(self, "checksum"), hexadecimal)

        if self['type'].value in (self.ECHO_REQUEST, self.ECHO_REPLY):
            yield UInt16(self, "id")
            yield UInt16(self, "sequence")
Пример #24
0
def commentHeader(s):
    yield filesizeHandler(
        UInt16(s, "total_size", "Comment header size + comment size"))
    yield filesizeHandler(
        UInt16(s, "uncompressed_size", "Uncompressed comment size"))
    yield UInt8(s, "required_version", "RAR version needed to extract comment")
    yield UInt8(s, "packing_method", "Comment packing method")
    yield UInt16(s, "comment_crc16", "Comment CRC")
 def createFields(self):
     yield Enum(UInt16(self, "type"), self.BLOCK_TYPE)
     if self["type"].value == 0:
         return
     yield UInt16(self, "size")
     size = self["size"].value
     if size:
         yield RawBytes(self, "data", size)
Пример #26
0
 def createFields(self):
     yield UInt8(self, "width", "Width")
     yield UInt8(self, "height", "Height")
     yield UInt8(self, "nb_color", "Number of colors")
     yield UInt8(self, "reserved", "(reserved)")
     yield UInt16(self, "planes", "Color planes (=1)")
     yield UInt16(self, "bpp", "Bits per pixel")
     yield UInt32(self, "size", "Content size in bytes")
     yield UInt32(self, "offset", "Data offset")
Пример #27
0
 def createFields(self):
     yield UInt16(self, "width", "Width")
     yield UInt16(self, "height", "Height")
     yield Bits(self, "bpp", 3, "Bits per pixel minus one")
     yield Bit(self, "reserved", "(reserved)")
     yield Bits(self, "color_res", 3, "Color resolution minus one")
     yield Bit(self, "global_map", "Has global map?")
     yield UInt8(self, "background", "Background color")
     yield UInt8(self, "pixel_aspect_ratio", "Pixel Aspect Ratio")
    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"))
Пример #29
0
 def createFields(self):
     yield UInt32(self, "block_bitmap", "Points to the blocks bitmap block")
     yield UInt32(self, "inode_bitmap", "Points to the inodes bitmap block")
     yield UInt32(self, "inode_table", "Points to the inodes table first block")
     yield UInt16(self, "free_blocks_count", "Number of free blocks")
     yield UInt16(self, "free_inodes_count", "Number of free inodes")
     yield UInt16(self, "used_dirs_count", "Number of inodes allocated to directories")
     yield UInt16(self, "padding", "Padding")
     yield NullBytes(self, "reserved", 12, "Reserved")
Пример #30
0
 def createFields(self):
     yield UInt32(self, "header_size", r"Header length (9)")
     yield UInt8(self, "packing_type", r"Packing type (always 0)")
     yield UInt16(self, "rows", r"Number of rows in pattern (1..256)")
     yield UInt16(self, "data_size", r"Packed patterndata size")
     rows = self["rows"].value
     self.info("Pattern: %i rows" % rows)
     for index in xrange(rows):
         yield Row(self, "row[]")