Example #1
0
def specialHeader(s, is_file):
    yield filesizeHandler(UInt32(s, "compressed_size", "Compressed size (bytes)"))
    yield filesizeHandler(UInt32(s, "uncompressed_size", "Uncompressed size (bytes)"))
    yield Enum(UInt8(s, "host_os", "Operating system used for archiving"), OS_NAME)
    yield textHandler(UInt32(s, "crc32", "File CRC32"), hexadecimal)
    yield TimeDateMSDOS32(s, "ftime", "Date and time (MS DOS format)")
    yield textHandler(UInt8(s, "version", "RAR version needed to extract file"), formatRARVersion)
    yield Enum(UInt8(s, "method", "Packing method"), COMPRESSION_NAME)
    yield filesizeHandler(UInt16(s, "filename_length", "File name size"))
    if s["host_os"].value in (OS_MSDOS, OS_WIN32):
        yield MSDOSFileAttr32(s, "file_attr", "File attributes")
    else:
        yield textHandler(UInt32(s, "file_attr", "File attributes"), hexadecimal)

    # Start additional field from unrar
    if s["flags/is_large"].value:
        yield filesizeHandler(UInt64(s, "large_size", "Extended 64bits filesize"))

    # End additional field
    size = s["filename_length"].value
    if size > 0:
        if s["flags/is_unicode"].value:
            charset = "UTF-8"
        else:
            charset = "ISO-8859-15"
        yield String(s, "filename", size, "Filename", charset=charset)
    # Start additional fields from unrar - file only
    if is_file:
        if s["flags/has_salt"].value:
            yield textHandler(UInt8(s, "salt", "Salt"), hexadecimal)
        if s["flags/has_ext_time"].value:
            yield ExtTime(s, "extra_time", "Extra time info")
Example #2
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")
Example #3
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")
Example #4
0
 def createFields(self):
     yield Integer(self, "time", "Delta time in ticks")
     next = self.stream.readBits(self.absolute_address+self.current_size, 8, self.root.endian)
     if next & 0x80 == 0:
         # "Running Status" command
         if self.prev_command is None:
             raise ParserError("Running Status command not preceded by another command.")
         self.command = self.prev_command.command
     else:
         yield Enum(textHandler(UInt8(self, "command"), hexadecimal), self.COMMAND_DESC)
         self.command = self["command"].value
     if self.command == 0xFF:
         yield Enum(textHandler(UInt8(self, "meta_command"), hexadecimal), self.META_COMMAND_DESC)
         yield UInt8(self, "data_len")
         size = self["data_len"].value
         if size:
             command = self["meta_command"].value
             if command in self.META_COMMAND_PARSER:
                 parser = self.META_COMMAND_PARSER[command]
             else:
                 parser = None
             if parser:
                 for field in parser(self, size):
                     yield field
             else:
                 yield RawBytes(self, "data", size)
     else:
         if self.command not in self.COMMAND_PARSER:
             raise ParserError("Unknown command: %s" % self["command"].display)
         parser = self.COMMAND_PARSER[self.command]
         for field in parser(self):
             yield field
Example #5
0
    def createFields(self):
        while self.stream.readBytes(self.absolute_address+self.current_size, 1) == '%':
            size = getLineEnd(self, 4)
            if size == 2:
                yield textHandler(UInt16(self, "crc32"), hexadecimal)
            elif size == 4:
                yield textHandler(UInt32(self, "crc32"), hexadecimal)
            elif self.stream.readBytes(self.absolute_address+self.current_size, size).isalpha():
                yield String(self, "comment[]", size)
            else:
                RawBytes(self, "unknown_data[]", size)
            yield LineEnd(self, "line_end[]")

        #abs_offset = self.current_size//8
        # TODO: yield objects that read offsets and deduce size from
        # "/cross_ref_table/sub_section[]/entries/item[]"
        offsets = []
        for subsection in self.array("/cross_ref_table/sub_section"):
            for obj in subsection.array("entries/item"):
                if "byte_offset" in obj:
                    # Could be inserted already sorted
                    offsets.append(obj["byte_offset"].value)

        offsets.append(self["/cross_ref_table"].absolute_address//8)
        offsets.sort()
        for index in xrange(len(offsets)-1):
            yield Catalog(self, "object[]", size=offsets[index+1]-offsets[index])
Example #6
0
 def createFields(self):
     yield Enum(Bits(self, "compression_method", 4), {
         8: "deflate",
         15: "reserved"
     })  # CM
     yield Bits(self, "compression_info", 4,
                "base-2 log of the window size")  # CINFO
     yield Bits(self, "flag_check_bits", 5)  # FCHECK
     yield Bit(self, "flag_dictionary_present")  # FDICT
     yield Enum(
         Bits(self, "flag_compression_level", 2),  # FLEVEL
         {
             0: "Fastest",
             1: "Fast",
             2: "Default",
             3: "Maximum, Slowest"
         })
     if self["flag_dictionary_present"].value:
         yield textHandler(
             UInt32(self, "dict_checksum",
                    "ADLER32 checksum of dictionary information"),
             hexadecimal)
     yield DeflateData(self,
                       "data",
                       self.stream,
                       description="Compressed Data")
     yield textHandler(
         UInt32(self, "data_checksum",
                "ADLER32 checksum of compressed data"), hexadecimal)
Example #7
0
 def createFields(self):
     yield String(self, "magic", 4)
     yield String(self, "version", 4, strip='\0')
     yield textHandler(UInt32(self, "checksum"), hexadecimal)
     yield RawBytes(self, "signature", 20, description="SHA1 sum over all subsequent data")
     yield filesizeHandler(UInt32(self, "filesize"))
     yield UInt32(self, "size", description="Header size")
     self._size = self['size'].value*8
     yield textHandler(UInt32(self, "endian"), hexadecimal)
     yield UInt32(self, "link_count")
     yield UInt32(self, "link_offset")
     yield UInt32(self, "map_offset", description="offset to map footer")
     yield UInt32(self, "string_count", description="number of entries in string table")
     yield UInt32(self, "string_offset", description="offset to string table")
     yield UInt32(self, "type_desc_count", description="number of entries in type descriptor table")
     yield UInt32(self, "type_desc_offset", description="offset to type descriptor table")
     yield UInt32(self, "meth_desc_count", description="number of entries in method descriptor table")
     yield UInt32(self, "meth_desc_offset", description="offset to method descriptor table")
     yield UInt32(self, "field_count", description="number of entries in field table")
     yield UInt32(self, "field_offset", description="offset to field table")
     yield UInt32(self, "method_count", description="number of entries in method table")
     yield UInt32(self, "method_offset", description="offset to method table")
     yield UInt32(self, "class_count", description="number of entries in class table")
     yield UInt32(self, "class_offset", description="offset to class table")
     yield UInt32(self, "data_size", description="size of data region")
     yield UInt32(self, "data_offset", description="offset to data region")
Example #8
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")
Example #9
0
 def createFields(self):
     yield Integer(self, "time", "Delta time in ticks")
     yield Enum(textHandler(UInt8(self, "command"), hexadecimal), self.COMMAND_DESC)
     command = self["command"].value
     if command == 0xFF:
         yield Enum(textHandler(UInt8(self, "meta_command"), hexadecimal), self.META_COMMAND_DESC)
         yield UInt8(self, "data_len")
         size = self["data_len"].value
         if size:
             command = self["meta_command"].value
             if command in self.META_COMMAND_PARSER:
                 parser = self.META_COMMAND_PARSER[command]
             else:
                 parser = None
             if parser:
                 for field in parser(self, size):
                     yield field
             else:
                 yield RawBytes(self, "data", size)
     else:
         if command not in self.COMMAND_PARSER:
             raise ParserError("Unknown command: %s" % self["command"].display)
         parser = self.COMMAND_PARSER[command]
         for field in parser(self):
             yield field
Example #10
0
 def createFields(self):
     yield String(self, "header", 2, "File header (MZ)", charset="ASCII")
     yield UInt16(self, "size_mod_512", "File size in bytes modulo 512")
     yield UInt16(self, "size_div_512", "File size in bytes divide by 512")
     yield UInt16(self, "reloc_entries", "Number of relocation entries")
     yield UInt16(self, "code_offset",
                  "Offset to the code in the file (divided by 16)")
     yield UInt16(self, "needed_memory",
                  "Memory needed to run (divided by 16)")
     yield UInt16(self, "max_memory",
                  "Maximum memory needed to run (divided by 16)")
     yield textHandler(
         UInt32(self, "init_ss_sp", "Initial value of SP:SS registers"),
         hexadecimal)
     yield UInt16(self, "checksum", "Checksum")
     yield textHandler(
         UInt32(self, "init_cs_ip", "Initial value of CS:IP registers"),
         hexadecimal)
     yield UInt16(self, "reloc_offset",
                  "Offset in file to relocation table")
     yield UInt16(self, "overlay_number", "Overlay number")
     yield PaddingBytes(self, "reserved[]", 8, "Reserved")
     yield UInt16(self, "oem_id", "OEM id")
     yield UInt16(self, "oem_info", "OEM info")
     yield PaddingBytes(self, "reserved[]", 20, "Reserved")
     yield UInt32(self, "next_offset", "Offset to next header (PE or NE)")
Example #11
0
    def createFields(self):
        yield Enum(textHandler(UInt16(self, "tag", "Tag"), hexadecimal), self.TAG_NAME)
        yield Enum(textHandler(UInt16(self, "type", "Type"), hexadecimal), self.TYPE_NAME)
        yield UInt32(self, "count", "Count")
        if self["type"].value not in (self.TYPE_BYTE, self.TYPE_UNDEFINED) \
        and  MAX_COUNT < self["count"].value:
            raise ParserError("EXIF: Invalid count value (%s)" % self["count"].value)
        value_size, array_size = self.getSizes()

        # Get offset/value
        if not value_size:
            yield NullBytes(self, "padding", 4)
        elif value_size <= 32:
            if 1 < array_size:
                name = "value[]"
            else:
                name = "value"
            kw = {}
            cls = self.value_cls
            if cls is String:
                args = (self, name, value_size/8, "Value")
                kw["strip"] = " \0"
                kw["charset"] = "ISO-8859-1"
            elif cls is Bytes:
                args = (self, name, value_size/8, "Value")
            else:
                args = (self, name, "Value")
            for index in xrange(array_size):
                yield cls(*args, **kw)

            size = array_size * value_size
            if size < 32:
                yield NullBytes(self, "padding", (32-size)//8)
        else:
            yield UInt32(self, "offset", "Value offset")
Example #12
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)
Example #13
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")
Example #14
0
 def createFields(self):
     # This stupid shit gets the LSB, not the MSB...
     self.info(
         "Note info: 0x%02X" %
         self.stream.readBits(self.absolute_address, 8, LITTLE_ENDIAN))
     yield RealBit(self, "is_extended")
     if self["is_extended"].value:
         info = NoteInfo(self, "info")
         yield info
         if info["has_note"].value:
             yield Enum(UInt8(self, "note"), NOTE_NAME)
         if info["has_instrument"].value:
             yield UInt8(self, "instrument")
         if info["has_volume"].value:
             yield textHandler(UInt8(self, "volume"), parseVolume)
         if info["has_type"].value:
             yield Effect(self, "effect_type")
         if info["has_parameter"].value:
             yield textHandler(UInt8(self, "effect_parameter"), hexadecimal)
     else:
         yield Enum(Bits(self, "note", 7), NOTE_NAME)
         yield UInt8(self, "instrument")
         yield textHandler(UInt8(self, "volume"), parseVolume)
         yield Effect(self, "effect_type")
         yield textHandler(UInt8(self, "effect_parameter"), hexadecimal)
Example #15
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
Example #16
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)")
Example #17
0
 def createFields(self):
     yield Integer(self, "time", "Delta time in ticks")
     yield Enum(textHandler(UInt8(self, "command"), hexadecimal),
                self.COMMAND_DESC)
     command = self["command"].value
     if command == 0xFF:
         yield Enum(textHandler(UInt8(self, "meta_command"), hexadecimal),
                    self.META_COMMAND_DESC)
         yield UInt8(self, "data_len")
         size = self["data_len"].value
         if size:
             command = self["meta_command"].value
             if command in self.META_COMMAND_PARSER:
                 parser = self.META_COMMAND_PARSER[command]
             else:
                 parser = None
             if parser:
                 for field in parser(self, size):
                     yield field
             else:
                 yield RawBytes(self, "data", size)
     else:
         if command not in self.COMMAND_PARSER:
             raise ParserError("Unknown command: %s" %
                               self["command"].display)
         parser = self.COMMAND_PARSER[command]
         for field in parser(self):
             yield field
Example #18
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 UInt8(self, "minor_version", "Minor version (should be 3)")
        yield UInt8(self, "major_version", "Major version (should be 1)")
        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, "cabinet_serial", "Zero-based cabinet number")

        if self["flags/has_reserved"].value:
            yield UInt16(self, "reserved_header_size", "Size of per-cabinet reserved area")
            yield UInt8(self, "reserved_folder_size", "Size of per-folder reserved area")
            yield UInt8(self, "reserved_data_size", "Size of per-datablock reserved area")
            if self["reserved_header_size"].value:
                yield RawBytes(self, "reserved_header", self["reserved_header_size"].value, "Per-cabinet reserved area")
        if self["flags/has_previous"].value:
            yield CString(self, "previous_cabinet", "File name of previous cabinet", charset="ASCII")
            yield CString(self, "previous_disk", "Description of disk/media on which previous cabinet resides", charset="ASCII")
        if self["flags/has_next"].value:
            yield CString(self, "next_cabinet", "File name of next cabinet", charset="ASCII")
            yield CString(self, "next_disk", "Description of disk/media on which next cabinet resides", charset="ASCII")

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

        folders = sorted(enumerate(folders), key=lambda x:x[1]["offset"].value)

        for i in xrange(len(folders)):
            index, folder = folders[i]
            padding = self.seekByte(folder["offset"].value)
            if padding:
                yield padding
            files = []
            for file in files:
                if file["folder_index"].value == index:
                    files.append(file)
            if i+1 == len(folders):
                size = (self.size // 8) - folder["offset"].value
            else:
                size = (folders[i+1][1]["offset"].value) - folder["offset"].value
            yield FolderData(self, "folder_data[%i]" % index, folder, files, size=size*8)

        end = self.seekBit(self.size, "endraw")
        if end:
            yield end
Example #19
0
 def createFields(self):
     yield UInt32(self, "size")
     self._size = (self["size"].value + 4) * 8
     yield RawBytes(self, "unknown[]", 10)
     yield textHandler(UInt16(self, "video_pid", "PID of video data in stream file"), hexadecimal)
     yield AVCHDMPLS_StreamAttribs(self, "video_attribs")
     yield textHandler(UInt16(self, "audio_pid", "PID of audio data in stream file"), hexadecimal)
     yield AVCHDMPLS_StreamAttribs(self, "audio_attribs")
Example #20
0
 def createFields(self):
     yield UInt32(self, "unknown[]")
     yield UInt32(self, "index")
     yield UInt32(self, "unknown[]")
     yield textHandler(UInt32(self, "unknown_id"), hexadecimal)
     yield UInt32(self, "unknown[]")
     yield textHandler(UInt32(self, "playlist_id"), lambda field: '%05d'%field.value)
     yield UInt32(self, "unknown[]")
Example #21
0
 def createFields(self):
     yield UInt32(self, "size")
     self._size = (self['size'].value+4)*8
     yield RawBytes(self, "unknown[]", 10)
     yield textHandler(UInt16(self, "video_pid", "PID of video data in stream file"), hexadecimal)
     yield AVCHDMPLS_StreamAttribs(self, "video_attribs")
     yield textHandler(UInt16(self, "audio_pid", "PID of audio data in stream file"), hexadecimal)
     yield AVCHDMPLS_StreamAttribs(self, "audio_attribs")
Example #22
0
 def createFields(self):
     yield textHandler(UInt32(self, "plugin_id1"), hexadecimal)
     yield textHandler(UInt32(self, "plugin_id2"), hexadecimal)
     yield UInt32(self, "input_routing")
     yield UInt32(self, "output_routing")
     yield GenericVector(self, "routing_info", 4, UInt32, "reserved")
     yield String(self, "name", 32, strip='\0')
     yield String(self, "dll_name", 64, desc="Original DLL name", strip='\0')
Example #23
0
 def createFields(self):
     yield textHandler(
         UInt16(self, "class", description="Class containing this method"),
         classIndex)
     yield textHandler(UInt16(self, "sig", description="Method signature"),
                       signatureIndex)
     yield textHandler(UInt32(self, "name", description="Method name"),
                       stringIndex)
Example #24
0
 def createFields(self):
     yield UInt32(self, "unknown[]")
     yield UInt32(self, "index")
     yield UInt32(self, "unknown[]")
     yield textHandler(UInt32(self, "unknown_id"), hexadecimal)
     yield UInt32(self, "unknown[]")
     yield textHandler(UInt32(self, "playlist_id"), lambda field: "%05d" % field.value)
     yield UInt32(self, "unknown[]")
Example #25
0
 def createFields(self):
     yield textHandler(
         UInt16(self, "class", description="Class containing this field"),
         classIndex)
     yield textHandler(UInt16(self, "type", description="Field type"),
                       classIndex)
     yield textHandler(UInt32(self, "name", description="Field name"),
                       stringIndex)
Example #26
0
 def createFields(self):
     value = self.stream.readBits(self.absolute_address, 16, self.endian)
     if value < 1024:
         yield Enum(UInt16(self, "lang"), self.MAC_LANG)
     else:
         yield NullBits(self, "padding[]", 1)
         yield textHandler(Bits(self, "lang[0]", 5), self.fieldHandler)
         yield textHandler(Bits(self, "lang[1]", 5), self.fieldHandler)
         yield textHandler(Bits(self, "lang[2]", 5), self.fieldHandler)
Example #27
0
 def createFields(self):
     yield UInt32(self, "id")
     yield textHandler(UInt32(self, "ram_address"), hexadecimal)
     yield UInt32(self, "ram_size")
     yield UInt32(self, "bss_size")
     yield textHandler(UInt32(self, "init_start_address"), hexadecimal)
     yield textHandler(UInt32(self, "init_end_address"), hexadecimal)
     yield UInt32(self, "file_id")
     yield RawBytes(self, "reserved[]", 4)
Example #28
0
 def createFields(self):
     yield textHandler(UInt32(self, "class", description="Class being described"), classIndex)
     yield AccessFlags(self, "flags")
     yield textHandler(UInt32(self, "superclass", description="Superclass"), classIndex)
     yield UInt32(self, "interfaces_offset", description="Offset to interface list")
     yield textHandler(UInt32(self, "filename", description="Filename"), stringIndex)
     yield UInt32(self, "annotations_offset")
     yield UInt32(self, "class_data_offset")
     yield UInt32(self, "static_values_offset")
Example #29
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"))
Example #30
0
 def createFields(self):
     yield UInt32(self, "id")
     yield textHandler(UInt32(self, "ram_address"), hexadecimal)
     yield UInt32(self, "ram_size")
     yield UInt32(self, "bss_size")
     yield textHandler(UInt32(self, "init_start_address"), hexadecimal)
     yield textHandler(UInt32(self, "init_end_address"), hexadecimal)
     yield UInt32(self, "file_id")
     yield RawBytes(self, "reserved[]", 4)
Example #31
0
 def createFields(self):
     value = self.stream.readBits(self.absolute_address, 16, self.endian)
     if value < 1024:
         yield Enum(UInt16(self, "lang"), self.MAC_LANG)
     else:
         yield NullBits(self, "padding[]", 1)
         yield textHandler(Bits(self, "lang[0]", 5), self.fieldHandler)
         yield textHandler(Bits(self, "lang[1]", 5), self.fieldHandler)
         yield textHandler(Bits(self, "lang[2]", 5), self.fieldHandler)
Example #32
0
 def createFields(self):
     yield Enum(UInt32(self, "type", "Segment type"), ProgramHeader32.TYPE_NAME)
     yield ProgramFlags(self, "flags")
     yield UInt64(self, "offset", "Offset")
     yield textHandler(UInt64(self, "vaddr", "V. address"), hexadecimal)
     yield textHandler(UInt64(self, "paddr", "P. address"), hexadecimal)
     yield UInt64(self, "file_size", "File size")
     yield UInt64(self, "mem_size", "Memory size")
     yield UInt64(self, "align", "Alignment padding")
Example #33
0
 def createFields(self):
     yield Enum(UInt16(self, "type", "Type"), ProgramHeader32.TYPE_NAME)
     yield UInt16(self, "flags", "Flags")
     yield UInt32(self, "offset", "Offset")
     yield textHandler(UInt32(self, "vaddr", "V. address"), hexadecimal)
     yield textHandler(UInt32(self, "paddr", "P. address"), hexadecimal)
     yield UInt32(self, "file_size", "File size")
     yield UInt32(self, "mem_size", "Memory size")
     yield UInt32(self, "align", "Alignment")
     yield UInt32(self, "xxx", "???")
Example #34
0
 def createFields(self):
     yield textHandler(Int32(self, "ns"), stringIndex)
     yield textHandler(Int32(self, "name"), stringIndex)
     yield textHandler(Int32(self, "value_string"), stringIndex)
     yield UInt16(self, "unk[]")
     yield UInt8(self, "unk[]")
     yield Enum(UInt8(self, "value_type"), self.TYPE_NAME)
     func = self.TYPE_FUNC.get(self['value_type'].value, None)
     if not func:
         func = UInt32
     yield func(self, "value_data")
Example #35
0
 def createFields(self):
     yield Enum(Bits(self, "compression_method", 4), {8:"deflate", 15:"reserved"}) # CM
     yield Bits(self, "compression_info", 4, "base-2 log of the window size") # CINFO
     yield Bits(self, "flag_check_bits", 5) # FCHECK
     yield Bit(self, "flag_dictionary_present") # FDICT
     yield Enum(Bits(self, "flag_compression_level", 2), # FLEVEL
                {0:"Fastest", 1:"Fast", 2:"Default", 3:"Maximum, Slowest"})
     if self["flag_dictionary_present"].value:
         yield textHandler(UInt32(self, "dict_checksum", "ADLER32 checksum of dictionary information"), hexadecimal)
     yield DeflateData(self, "data", self.stream, description = "Compressed Data")
     yield textHandler(UInt32(self, "data_checksum", "ADLER32 checksum of compressed data"), hexadecimal)
Example #36
0
 def createFields(self):
     yield SymbolStringTableOffset(self, "name", "Section name (index into section header string table)")
     yield Enum(textHandler(UInt32(self, "type", "Section type"), hexadecimal), self.TYPE_NAME)
     yield SectionFlags(self, "flags", "Section flags")
     yield textHandler(UInt64(self, "VMA", "Virtual memory address"), hexadecimal)
     yield textHandler(UInt64(self, "LMA", "Logical memory address (offset in file)"), hexadecimal)
     yield textHandler(UInt64(self, "size", "Section size (bytes)"), hexadecimal)
     yield UInt32(self, "link", "Index of a related section")
     yield UInt32(self, "info", "Type-dependent information")
     yield UInt64(self, "addr_align", "Address alignment (bytes)")
     yield UInt64(self, "entry_size", "Size of each entry in section")
Example #37
0
 def createFields(self):
     yield UInt32(self, "name", "Name")
     yield Enum(UInt32(self, "type", "Type"), self.TYPE_NAME)
     yield UInt32(self, "flags", "Flags")
     yield textHandler(UInt32(self, "VMA", "Virtual memory address"), hexadecimal)
     yield textHandler(UInt32(self, "LMA", "Logical memory address (in file)"), hexadecimal)
     yield textHandler(UInt32(self, "size", "Size"), hexadecimal)
     yield UInt32(self, "link", "Link")
     yield UInt32(self, "info", "Information")
     yield UInt32(self, "addr_align", "Address alignment")
     yield UInt32(self, "entry_size", "Entry size")
Example #38
0
 def createFields(self):
     yield textHandler(Int32(self, "ns"), stringIndex)
     yield textHandler(Int32(self, "name"), stringIndex)
     yield textHandler(Int32(self, "value_string"), stringIndex)
     yield UInt16(self, "unk[]")
     yield UInt8(self, "unk[]")
     yield Enum(UInt8(self, "value_type"), self.TYPE_NAME)
     func = self.TYPE_FUNC.get(self['value_type'].value, None)
     if not func:
         func = UInt32
     yield func(self, "value_data")
Example #39
0
def TagStart(self):
    yield UInt32(self, "lineno", "Line number from original XML file")
    yield Int32(self, "unk[]", "Always -1")
    yield textHandler(Int32(self, "ns"), stringIndex)
    yield textHandler(Int32(self, "name"), stringIndex)
    yield UInt32(self, "flags")
    yield UInt16(self, "attrib_count")
    yield UInt16(self, "attrib_id")
    yield UInt16(self, "attrib_class")
    yield UInt16(self, "attrib_style")
    for i in xrange(self['attrib_count'].value):
        yield XMLAttribute(self, "attrib[]")
Example #40
0
def TagStart(self):
    yield UInt32(self, "lineno", "Line number from original XML file")
    yield Int32(self, "unk[]", "Always -1")
    yield textHandler(Int32(self, "ns"), stringIndex)
    yield textHandler(Int32(self, "name"), stringIndex)
    yield UInt32(self, "flags")
    yield UInt16(self, "attrib_count")
    yield UInt16(self, "attrib_id")
    yield UInt16(self, "attrib_class")
    yield UInt16(self, "attrib_style")
    for i in xrange(self['attrib_count'].value):
        yield XMLAttribute(self, "attrib[]")
Example #41
0
 def createFields(self):
     yield textHandler(UInt32(self, "plugin_id1"), hexadecimal)
     yield textHandler(UInt32(self, "plugin_id2"), hexadecimal)
     yield UInt32(self, "input_routing")
     yield UInt32(self, "output_routing")
     yield GenericVector(self, "routing_info", 4, UInt32, "reserved")
     yield String(self, "name", 32, strip='\0')
     yield String(self,
                  "dll_name",
                  64,
                  desc="Original DLL name",
                  strip='\0')
Example #42
0
 def createFields(self):
     yield textHandler(Bits(self, "blockheader", 48, "Block header"), hexadecimal)
     if self["blockheader"].value != 0x314159265359: # pi
         raise ParserError("Invalid block header!")
     yield textHandler(UInt32(self, "crc32", "CRC32 for this block"), hexadecimal)
     yield Bit(self, "randomized", "Is this block randomized?")
     yield Bits(self, "orig_bwt_pointer", 24, "Starting pointer into BWT after untransform")
     yield GenericVector(self, "huffman_used_map", 16, Bit, 'block_used', "Bitmap showing which blocks (representing 16 literals each) are in use")
     symbols_used = []
     for index, block_used in enumerate(self["huffman_used_map"].array('block_used')):
         if block_used.value:
             start_index = index*16
             field = Bzip2Bitmap(self, "huffman_used_bitmap[%i]"%index, 16, start_index, "Bitmap for block %i (literals %i to %i) showing which symbols are in use"%(index, start_index, start_index + 15))
             yield field
             for i, used in enumerate(field):
                 if used.value:
                     symbols_used.append(start_index + i)
     yield Bits(self, "huffman_groups", 3, "Number of different Huffman tables in use")
     yield Bits(self, "selectors_used", 15, "Number of times the Huffman tables are switched")
     yield Bzip2Selectors(self, "selectors_list", self["huffman_groups"].value)
     trees = []
     for group in xrange(self["huffman_groups"].value):
         field = Bzip2Lengths(self, "huffman_lengths[]", len(symbols_used)+2)
         yield field
         trees.append(field.tree)
     counter = 0
     rle_run = 0
     selector_tree = None
     while True:
         if counter%50 == 0:
             select_id = self["selectors_list"].array("selector_list")[counter//50].realvalue
             selector_tree = trees[select_id]
         field = HuffmanCode(self, "huffman_code[]", selector_tree)
         if field.realvalue in [0, 1]:
             # RLE codes
             if rle_run == 0:
                 rle_power = 1
             rle_run += (field.realvalue + 1) * rle_power
             rle_power <<= 1
             field._description = "RLE Run Code %i (for %r); Total accumulated run %i (Huffman Code %i)" % (field.realvalue, chr(symbols_used[0]), rle_run, field.value)
         elif field.realvalue == len(symbols_used)+1:
             field._description = "Block Terminator (%i) (Huffman Code %i)"%(field.realvalue, field.value)
             yield field
             break
         else:
             rle_run = 0
             move_to_front(symbols_used, field.realvalue-1)
             field._description = "Literal %r (value %i) (Huffman Code %i)"%(chr(symbols_used[0]), field.realvalue, field.value)
         yield field
         if field.realvalue == len(symbols_used)+1:
             break
         counter += 1
Example #43
0
    def createFields(self):
        yield Bytes(self, "signature", 2, "New executable signature (NE)")
        yield UInt8(self, "link_ver", "Linker version number")
        yield UInt8(self, "link_rev", "Linker revision number")
        yield UInt16(self, "entry_table_ofst", "Offset to the entry table")
        yield UInt16(self, "entry_table_size", "Length (in bytes) of the entry table")
        yield PaddingBytes(self, "reserved[]", 4)

        yield Bit(self, "is_dll", "Is a dynamic-link library (DLL)?")
        yield Bit(self, "is_win_app", "Is a Windows application?")
        yield PaddingBits(self, "reserved[]", 9)
        yield Bit(self, "first_seg_code", "First segment contains code that loads the application?")
        yield NullBits(self, "reserved[]", 1)
        yield Bit(self, "link_error", "Load even if linker detects errors?")
        yield NullBits(self, "reserved[]", 1)
        yield Bit(self, "is_lib", "Is a library module?")

        yield UInt16(self, "auto_data_seg", "Automatic data segment number")
        yield filesizeHandler(UInt16(self, "local_heap_size", "Initial size (in bytes) of the local heap"))
        yield filesizeHandler(UInt16(self, "stack_size", "Initial size (in bytes) of the stack"))
        yield textHandler(UInt32(self, "cs_ip", "Value of CS:IP"), hexadecimal)
        yield textHandler(UInt32(self, "ss_sp", "Value of SS:SP"), hexadecimal)

        yield UInt16(self, "nb_entry_seg_tab", "Number of entries in the segment table")
        yield UInt16(self, "nb_entry_modref_tab", "Number of entries in the module-reference table")
        yield filesizeHandler(UInt16(self, "size_nonres_name_tab", "Number of bytes in the nonresident-name table"))
        yield UInt16(self, "seg_tab_ofs", "Segment table offset")
        yield UInt16(self, "rsrc_ofs", "Resource offset")

        yield UInt16(self, "res_name_tab_ofs", "Resident-name table offset")
        yield UInt16(self, "mod_ref_tab_ofs", "Module-reference table offset")
        yield UInt16(self, "import_tab_ofs", "Imported-name table offset")

        yield UInt32(self, "non_res_name_tab_ofs", "Nonresident-name table offset")
        yield UInt16(self, "nb_mov_ent_pt", "Number of movable entry points")
        yield UInt16(self, "log2_sector_size", "Log2 of the segment sector size")
        yield UInt16(self, "nb_rsrc_seg", "Number of resource segments")

        yield Bit(self, "unknown_os_format", "Operating system format is unknown")
        yield PaddingBits(self, "reserved[]", 1)
        yield Bit(self, "os_windows", "Operating system is Microsoft Windows")
        yield NullBits(self, "reserved[]", 6)
        yield Bit(self, "is_win20_prot", "Is Windows 2.x application running in version 3.x protected mode")
        yield Bit(self, "is_win20_font", "Is Windows 2.x application supporting proportional fonts")
        yield Bit(self, "fast_load", "Contains a fast-load area?")
        yield NullBits(self, "reserved[]", 4)

        yield UInt16(self, "fastload_ofs", "Fast-load area offset (in sector)")
        yield UInt16(self, "fastload_size", "Fast-load area length (in sector)")

        yield NullBytes(self, "reserved[]", 2)
        yield textHandler(UInt16(self, "win_version", "Expected Windows version number"), hexadecimal)
    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"))
Example #45
0
 def createFields(self):
     yield GUID(self, "guid")
     yield filesizeHandler(UInt64(self, "file_size"))
     yield TimestampWin64(self, "creation_date")
     yield UInt64(self, "pckt_count")
     yield textHandler(UInt64(self, "play_duration"), durationWin64)
     yield textHandler(UInt64(self, "send_duration"), durationWin64)
     yield UInt64(self, "preroll")
     yield Bit(self, "broadcast", "Is broadcast?")
     yield Bit(self, "seekable", "Seekable stream?")
     yield PaddingBits(self, "reserved[]", 30)
     yield filesizeHandler(UInt32(self, "min_pckt_size"))
     yield filesizeHandler(UInt32(self, "max_pckt_size"))
     yield displayHandler(UInt32(self, "max_bitrate"), humanBitRate)
Example #46
0
 def createFields(self):
     yield String(self, "magic", 4)
     yield String(self, "version", 4, strip='\0')
     yield textHandler(UInt32(self, "checksum"), hexadecimal)
     yield RawBytes(self,
                    "signature",
                    20,
                    description="SHA1 sum over all subsequent data")
     yield filesizeHandler(UInt32(self, "filesize"))
     yield UInt32(self, "size", description="Header size")
     self._size = self['size'].value * 8
     yield textHandler(UInt32(self, "endian"), hexadecimal)
     yield UInt32(self, "link_count")
     yield UInt32(self, "link_offset")
     yield UInt32(self, "map_offset", description="offset to map footer")
     yield UInt32(self,
                  "string_count",
                  description="number of entries in string table")
     yield UInt32(self,
                  "string_offset",
                  description="offset to string table")
     yield UInt32(self,
                  "type_desc_count",
                  description="number of entries in type descriptor table")
     yield UInt32(self,
                  "type_desc_offset",
                  description="offset to type descriptor table")
     yield UInt32(
         self,
         "meth_desc_count",
         description="number of entries in method descriptor table")
     yield UInt32(self,
                  "meth_desc_offset",
                  description="offset to method descriptor table")
     yield UInt32(self,
                  "field_count",
                  description="number of entries in field table")
     yield UInt32(self, "field_offset", description="offset to field table")
     yield UInt32(self,
                  "method_count",
                  description="number of entries in method table")
     yield UInt32(self,
                  "method_offset",
                  description="offset to method table")
     yield UInt32(self,
                  "class_count",
                  description="number of entries in class table")
     yield UInt32(self, "class_offset", description="offset to class table")
     yield UInt32(self, "data_size", description="size of data region")
     yield UInt32(self, "data_offset", description="offset to data region")
Example #47
0
def newRecoveryHeader(self):
    """
    This header is described nowhere
    """
    if self["flags/extend"].value:
        yield filesizeHandler(UInt32(self, "body_size", "Size of the unknown body following"))
        self.body_size = self["body_size"].value
    yield textHandler(UInt32(self, "unknown[]", "Unknown field, probably 0"),
        hexadecimal)
    yield String(self, "signature", 7, "Signature, normally '**ACE**'")
    yield textHandler(UInt32(self, "relative_start",
        "Offset (=crc16's) of this block in the file"), hexadecimal)
    yield textHandler(UInt32(self, "unknown[]",
        "Unknown field, probably 0"), hexadecimal)
Example #48
0
 def createFields(self):
     yield UInt32(self, "name", "Name")
     yield Enum(UInt32(self, "type", "Type"), self.TYPE_NAME)
     yield UInt32(self, "flags", "Flags")
     yield textHandler(UInt32(self, "VMA", "Virtual memory address"),
                       hexadecimal)
     yield textHandler(
         UInt32(self, "LMA", "Logical memory address (in file)"),
         hexadecimal)
     yield textHandler(UInt32(self, "size", "Size"), hexadecimal)
     yield UInt32(self, "link", "Link")
     yield UInt32(self, "info", "Information")
     yield UInt32(self, "addr_align", "Address alignment")
     yield UInt32(self, "entry_size", "Entry size")
Example #49
0
 def createFields(self):
     yield textHandler(UInt8(self, "sync", 8), hexadecimal)
     if self["sync"].value != 0x47:
         raise ParserError("MPEG-2 TS: Invalid synchronization byte")
     yield Bit(self, "has_error")
     yield Bit(self, "payload_unit_start")
     yield Bit(self, "priority")
     yield Enum(textHandler(Bits(self, "pid", 13, "Program identifier"), hexadecimal), self.PID)
     yield Bits(self, "scrambling_control", 2)
     yield Bit(self, "has_adaptation")
     yield Bit(self, "has_payload")
     yield Bits(self, "counter", 4)
     yield RawBytes(self, "payload", 184)
     if self["has_error"].value:
         yield RawBytes(self, "error_correction", 16)
Example #50
0
 def createFields(self):
     yield textHandler(UInt8(self, "header", "Header"), hexadecimal)
     if self["header"].value != 0xFF:
         raise ParserError("JPEG: Invalid chunk header!")
     yield textHandler(UInt8(self, "type", "Type"), hexadecimal)
     tag = self["type"].value
     if tag in (self.TAG_SOI, self.TAG_EOI):
         return
     yield UInt16(self, "size", "Size")
     size = (self["size"].value - 2)
     if 0 < size:
         if self._parser:
             yield self._parser(self, "content", "Chunk content", size=size*8)
         else:
             yield RawBytes(self, "data", size, "Data")
Example #51
0
def parseSoundHeader(parent, size):
    yield Bit(parent, "playback_is_stereo")
    yield Bit(parent, "playback_is_16bit")
    yield textHandler(Bits(parent, "playback_rate", 2), bit2hertz)
    yield NullBits(parent, "reserved", 4)

    yield Bit(parent, "sound_is_stereo")
    yield Bit(parent, "sound_is_16bit")
    yield textHandler(Bits(parent, "sound_rate", 2), bit2hertz)
    yield Enum(Bits(parent, "codec", 4), SOUND_CODEC)

    yield UInt16(parent, "sample_count")

    if parent["codec"].value == 2:
        yield UInt16(parent, "latency_seek")
Example #52
0
 def createFields(self):
     yield textHandler(
         UInt32(self, "class", description="Class being described"),
         classIndex)
     yield AccessFlags(self, "flags")
     yield textHandler(UInt32(self, "superclass", description="Superclass"),
                       classIndex)
     yield UInt32(self,
                  "interfaces_offset",
                  description="Offset to interface list")
     yield textHandler(UInt32(self, "filename", description="Filename"),
                       stringIndex)
     yield UInt32(self, "annotations_offset")
     yield UInt32(self, "class_data_offset")
     yield UInt32(self, "static_values_offset")
Example #53
0
 def createFields(self):
     yield textHandler(UInt8(self, "header", "Header"), hexadecimal)
     if self["header"].value != 0xFF:
         raise ParserError("JPEG: Invalid chunk header!")
     yield textHandler(UInt8(self, "type", "Type"), hexadecimal)
     tag = self["type"].value
     if tag in (self.TAG_SOI, self.TAG_EOI):
         return
     yield UInt16(self, "size", "Size")
     size = (self["size"].value - 2)
     if 0 < size:
         if self._parser:
             yield self._parser(self, "content", "Chunk content", size=size*8)
         else:
             yield RawBytes(self, "data", size, "Data")
Example #54
0
 def createFields(self):
     yield UInt16(self, "signature",
                  "PE optional header signature (0x010b)")
     # TODO: Support PE32+ (signature=0x020b)
     if self["signature"].value != 0x010b:
         raise ParserError("Invalid PE optional header signature")
     yield UInt8(self, "maj_lnk_ver", "Major linker version")
     yield UInt8(self, "min_lnk_ver", "Minor linker version")
     yield filesizeHandler(UInt32(self, "size_code", "Size of code"))
     yield filesizeHandler(
         UInt32(self, "size_init_data", "Size of initialized data"))
     yield filesizeHandler(
         UInt32(self, "size_uninit_data", "Size of uninitialized data"))
     yield textHandler(
         UInt32(self, "entry_point",
                "Address (RVA) of the code entry point"), hexadecimal)
     yield textHandler(UInt32(self, "base_code", "Base (RVA) of code"),
                       hexadecimal)
     yield textHandler(UInt32(self, "base_data", "Base (RVA) of data"),
                       hexadecimal)
     yield textHandler(UInt32(self, "image_base", "Image base (RVA)"),
                       hexadecimal)
     yield filesizeHandler(UInt32(self, "sect_align", "Section alignment"))
     yield filesizeHandler(UInt32(self, "file_align", "File alignment"))
     yield UInt16(self, "maj_os_ver", "Major OS version")
     yield UInt16(self, "min_os_ver", "Minor OS version")
     yield UInt16(self, "maj_img_ver", "Major image version")
     yield UInt16(self, "min_img_ver", "Minor image version")
     yield UInt16(self, "maj_subsys_ver", "Major subsystem version")
     yield UInt16(self, "min_subsys_ver", "Minor subsystem version")
     yield NullBytes(self, "reserved", 4)
     yield filesizeHandler(UInt32(self, "size_img", "Size of image"))
     yield filesizeHandler(UInt32(self, "size_hdr", "Size of headers"))
     yield textHandler(UInt32(self, "checksum"), hexadecimal)
     yield Enum(UInt16(self, "subsystem"), self.SUBSYSTEM_NAME)
     yield UInt16(self, "dll_flags")
     yield filesizeHandler(UInt32(self, "size_stack_reserve"))
     yield filesizeHandler(UInt32(self, "size_stack_commit"))
     yield filesizeHandler(UInt32(self, "size_heap_reserve"))
     yield filesizeHandler(UInt32(self, "size_heap_commit"))
     yield UInt32(self, "loader_flags")
     yield UInt32(self, "nb_directory", "Number of RVA and sizes")
     for index in xrange(self["nb_directory"].value):
         try:
             name = self.DIRECTORY_NAME[index]
         except KeyError:
             name = "data_dir[%u]" % index
         yield DataDirectory(self, name)
Example #55
0
 def createFields(self):
     # File data
     self.signature = None
     self.central_directory = []
     while not self.eof:
         header = textHandler(UInt32(self, "header[]", "Header"), hexadecimal)
         yield header
         header = header.value
         if header == FileEntry.HEADER:
             yield FileEntry(self, "file[]")
         elif header == ZipDataDescriptor.HEADER:
             yield ZipDataDescriptor(self, "spanning[]")
         elif header == 0x30304b50:
             yield ZipDataDescriptor(self, "temporary_spanning[]")
         elif header == ZipCentralDirectory.HEADER:
             yield ZipCentralDirectory(self, "central_directory[]")
         elif header == ZipEndCentralDirectory.HEADER:
             yield ZipEndCentralDirectory(self, "end_central_directory", "End of central directory")
         elif header == Zip64EndCentralDirectory.HEADER:
             yield Zip64EndCentralDirectory(self, "end64_central_directory", "ZIP64 end of central directory")
         elif header == ZipSignature.HEADER:
             yield ZipSignature(self, "signature", "Signature")
         elif header == Zip64EndCentralDirectoryLocator.HEADER:
             yield Zip64EndCentralDirectoryLocator(self, "end_locator", "ZIP64 Enf of central directory locator")
         else:
             raise ParserError("Error, unknown ZIP header (0x%08X)." % header)
Example #56
0
 def createFields(self):
     yield textHandler(UInt32(self, "file_crc32",
         "Checksum (CRC32)"), hexadecimal)
     yield filesizeHandler(UInt32(self, "file_compressed_size",
         "Compressed size (bytes)"))
     yield filesizeHandler(UInt32(self, "file_uncompressed_size",
          "Uncompressed size (bytes)"))
Example #57
0
    def createFields(self):
        yield textHandler(UInt8(self, "version"), hexadecimal)

        # TODO: sum of :
        # TrackEnabled = 1;
        # TrackInMovie = 2;
        # TrackInPreview = 4;
        # TrackInPoster = 8
        yield RawBytes(self, "flags", 3)

        yield TimestampMac32(self, "creation_date")
        yield TimestampMac32(self, "lastmod_date")
        yield UInt32(self, "track_id")
        yield PaddingBytes(self, "reserved[]", 8)
        yield UInt32(self, "duration")
        yield PaddingBytes(self, "reserved[]", 8)
        yield Int16(self, "video_layer", "Middle is 0, negative in front")
        yield PaddingBytes(self, "other", 2)
        yield QTFloat32(self, "geom_a", "Width scale")
        yield QTFloat32(self, "geom_b", "Width rotate")
        yield QTFloat32(self, "geom_u", "Width angle")
        yield QTFloat32(self, "geom_c", "Height rotate")
        yield QTFloat32(self, "geom_d", "Height scale")
        yield QTFloat32(self, "geom_v", "Height angle")
        yield QTFloat32(self, "geom_x", "Position X")
        yield QTFloat32(self, "geom_y", "Position Y")
        yield QTFloat32(self, "geom_w", "Divider scale")
        yield QTFloat32(self, "frame_size_width")
        yield QTFloat32(self, "frame_size_height")
Example #58
0
 def createFields(self):
     yield textHandler(UInt8(self, "version"), hexadecimal)
     yield RawBytes(self, "flags", 3)
     yield TimestampMac32(self, "creation_date")
     yield TimestampMac32(self, "lastmod_date")
     yield UInt32(self, "time_scale")
     yield UInt32(self, "duration")
     yield QTFloat32(self, "play_speed")
     yield UInt16(self, "volume")
     yield PaddingBytes(self, "reserved[]", 10)
     yield QTFloat32(self, "geom_a", "Width scale")
     yield QTFloat32(self, "geom_b", "Width rotate")
     yield QTFloat32(self, "geom_u", "Width angle")
     yield QTFloat32(self, "geom_c", "Height rotate")
     yield QTFloat32(self, "geom_d", "Height scale")
     yield QTFloat32(self, "geom_v", "Height angle")
     yield QTFloat32(self, "geom_x", "Position X")
     yield QTFloat32(self, "geom_y", "Position Y")
     yield QTFloat32(self, "geom_w", "Divider scale")
     yield UInt32(self, "preview_start")
     yield UInt32(self, "preview_length")
     yield UInt32(self, "still_poster")
     yield UInt32(self, "sel_start")
     yield UInt32(self, "sel_length")
     yield UInt32(self, "current_time")
     yield UInt32(self, "next_track")