Example #1
0
    def extract(self, icon):
        for index, header in enumerate(icon.array("icon_header")):
            image = Metadata(self)

            # Read size and colors from header
            image.width = header["width"].value
            image.height = header["height"].value
            bpp = header["bpp"].value
            nb_colors = header["nb_color"].value
            if nb_colors != 0:
                image.nb_colors = nb_colors
                if bpp == 0 and nb_colors in self.color_to_bpp:
                    bpp = self.color_to_bpp[nb_colors]
            elif bpp == 0:
                bpp = 8
            image.bits_per_pixel = bpp
            image.setHeader(
                "Icon #%u (%sx%s)" %
                (1 + index, image.get("width", "?"), image.get("height", "?")))

            # Read compression from data (if available)
            key = "icon_data[%u]/header/codec" % index
            if key in icon:
                image.compression = icon[key].display
            key = "icon_data[%u]/pixels" % index
            if key in icon:
                computeComprRate(image, icon[key].size)

            # Store new image
            self.addGroup("image[%u]" % index, image)
Example #2
0
    def extract(self, icon):
        for index, header in enumerate(icon.array("icon_header")):
            image = Metadata(self)

            # Read size and colors from header
            image.width = header["width"].value
            image.height = header["height"].value
            bpp = header["bpp"].value
            nb_colors = header["nb_color"].value
            if nb_colors != 0:
                image.nb_colors = nb_colors
                if bpp == 0 and nb_colors in self.color_to_bpp:
                    bpp = self.color_to_bpp[nb_colors]
            elif bpp == 0:
                bpp = 8
            image.bits_per_pixel = bpp
            image.setHeader(_("Icon #%u (%sx%s)")
                            % (1 + index,
                               image.get("width", "?"),
                               image.get("height", "?")))

            # Read compression from data (if available)
            key = "icon_data[%u]/header/codec" % index
            if key in icon:
                image.compression = icon[key].display
            key = "icon_data[%u]/pixels" % index
            if key in icon:
                computeComprRate(image, icon[key].size)

            # Store new image
            self.addGroup("image[%u]" % index, image)
Example #3
0
 def processSubtitle(self, track):
     sub = Metadata(self)
     self.trackCommon(track, sub)
     try:
         sub.compression = track["CodecID/string"].value
     except MissingField:
         pass
     self.addGroup("subtitle[]", sub, "Subtitle")
Example #4
0
 def processSubtitle(self, track):
     sub = Metadata(self)
     self.trackCommon(track, sub)
     try:
         sub.compression = track["CodecID/string"].value
     except MissingField:
         pass
     self.addGroup("subtitle[]", sub, "Subtitle")
Example #5
0
 def processVideo(self, track):
     video = Metadata(self)
     self.trackCommon(track, video)
     try:
         video.compression = track["CodecID/string"].value
         if "Video" in track:
             video.width = track["Video/PixelWidth/unsigned"].value
             video.height = track["Video/PixelHeight/unsigned"].value
     except MissingField:
         pass
     self.addGroup("video[]", video, "Video stream")
Example #6
0
 def processVideo(self, track):
     video = Metadata(self)
     self.trackCommon(track, video)
     try:
         video.compression = track["CodecID/string"].value
         if "Video" in track:
             video.width = track["Video/PixelWidth/unsigned"].value
             video.height = track["Video/PixelHeight/unsigned"].value
     except MissingField:
         pass
     self.addGroup("video[]", video, "Video stream")
Example #7
0
 def processAudio(self, track):
     audio = Metadata(self)
     self.trackCommon(track, audio)
     if "Audio" in track:
         frequency = self.getDouble(track, "Audio/SamplingFrequency")
         if frequency is not None:
             audio.sample_rate = frequency
         if "Audio/Channels/unsigned" in track:
             audio.nb_channel = track["Audio/Channels/unsigned"].value
         if "Audio/BitDepth/unsigned" in track:
             audio.bits_per_sample = track["Audio/BitDepth/unsigned"].value
     if "CodecID/string" in track:
         audio.compression = track["CodecID/string"].value
     self.addGroup("audio[]", audio, "Audio stream")
Example #8
0
 def processAudio(self, track):
     audio = Metadata(self)
     self.trackCommon(track, audio)
     if "Audio" in track:
         frequency = self.getDouble(track, "Audio/SamplingFrequency")
         if frequency is not None:
             audio.sample_rate = frequency
         if "Audio/Channels/unsigned" in track:
             audio.nb_channel = track["Audio/Channels/unsigned"].value
         if "Audio/BitDepth/unsigned" in track:
             audio.bits_per_sample = track["Audio/BitDepth/unsigned"].value
     if "CodecID/string" in track:
         audio.compression = track["CodecID/string"].value
     self.addGroup("audio[]", audio, "Audio stream")
Example #9
0
 def processFile(self, field):
     meta = Metadata(self)
     meta.filename = field["filename"].value
     meta.creation_date = field["last_mod"].value
     meta.compression = field["compression"].display
     if "data_desc" in field:
         meta.file_size = field["data_desc/file_uncompressed_size"].value
         if field["data_desc/file_compressed_size"].value:
             meta.compr_size = field["data_desc/file_compressed_size"].value
     else:
         meta.file_size = field["uncompressed_size"].value
         if field["compressed_size"].value:
             meta.compr_size = field["compressed_size"].value
     computeCompressionRate(meta)
     self.addGroup(field.name, meta, "File \"%s\"" % meta.get('filename'))
Example #10
0
 def processFile(self, field):
     meta = Metadata(self)
     meta.filename = field["filename"].value
     meta.creation_date = field["last_mod"].value
     meta.compression = field["compression"].display
     if "data_desc" in field:
         meta.file_size = field["data_desc/file_uncompressed_size"].value
         if field["data_desc/file_compressed_size"].value:
             meta.compr_size = field["data_desc/file_compressed_size"].value
     else:
         meta.file_size = field["uncompressed_size"].value
         if field["compressed_size"].value:
             meta.compr_size = field["compressed_size"].value
     computeCompressionRate(meta)
     self.addGroup(field.name, meta, "File \"%s\"" % meta.get('filename'))
Example #11
0
 def extract(self, mar):
     self.comment = "Contains %s files" % mar["nb_file"].value
     self.format_version = ("Microsoft Archive version %s" %
                            mar["version"].value)
     max_nb = maxNbFile(self)
     for index, field in enumerate(mar.array("file")):
         if max_nb is not None and max_nb <= index:
             self.warning("MAR archive contains many files, "
                          "but only first %s files are processed" % max_nb)
             break
         meta = Metadata(self)
         meta.filename = field["filename"].value
         meta.compression = "None"
         meta.file_size = field["filesize"].value
         self.addGroup(field.name, meta,
                       "File \"%s\"" % meta.getText('filename'))
Example #12
0
 def extract(self, mar):
     self.comment = "Contains %s files" % mar["nb_file"].value
     self.format_version = "Microsoft Archive version %s"\
                           % mar["version"].value
     max_nb = maxNbFile(self)
     for index, field in enumerate(mar.array("file")):
         if max_nb is not None and max_nb <= index:
             self.warning("MAR archive contains many files, "
                          "but only first %s files are processed"
                          % max_nb)
             break
         meta = Metadata(self)
         meta.filename = field["filename"].value
         meta.compression = "None"
         meta.file_size = field["filesize"].value
         self.addGroup(field.name, meta,
                       "File \"%s\"" % meta.getText('filename'))
Example #13
0
    def extract(self, rar):
        l_max_nb = maxNbFile(self)

        l_rarformat = rar["signature"].value
        if l_rarformat == b"RE~^":
            l_format_version = "1.4"
        elif l_rarformat[0:6] == b"Rar!\x1A\x07":
            if l_rarformat[6:7] == b"\x00":
                l_format_version = "1.5"  # RAR 4
            elif l_rarformat[6:7] == b"\x01":
                l_format_version = "5.0"
            elif l_rarformat[6:7] == b"\x02":
                l_format_version = "> 5.0"

        self.format_version = "RAR version %s" % l_format_version

        if l_format_version != "1.5":
            self.warning("RAR TODO: unknown format_version \"%s\" " %
                         l_format_version)

        l_has_recovery_record = False
        l_has_auth_verification = False
        l_has_password = False
        l_is_multivolume = False
        l_is_solid = False

        if rar["/archive_start/flags/has_comment"].value:
            self.warning("RAR TODO: comment extraction not implemented")
            self.comment = "HACHOIR: comment extraction not implemented"

        l_has_recovery_record = rar[
            "/archive_start/flags/has_recovery_record"].value
        l_has_auth_verification = rar[
            "/archive_start/flags/has_auth_information"].value
        l_has_password = rar["/archive_start/flags/is_locked"].value
        l_is_multivolume = rar["/archive_start/flags/vol"].value
        l_is_solid = rar["/archive_start/flags/is_solid"].value
        is_first_vol = rar["/archive_start/flags/is_first_vol"].value

        for l_index, l_field in enumerate(rar.array("new_sub_block")):
            if l_field["filename"].value == "CMT":
                self.warning("RAR TODO: comment unpacking not implemented")
                self.comment = "HACHOIR: comment unpacking not implemented"
            elif l_field["filename"].value == "AV":
                l_has_auth_verification = True
            elif l_field["filename"].value == "RR":
                l_has_recovery_record = True
            else:
                self.warning("RAR TODO: unknown sub_block \"%s\" " %
                             l_field["filename"].value)

        self.has_recovery_record = l_has_recovery_record
        self.has_auth_verification = l_has_auth_verification
        self.has_password = l_has_password
        self.is_multivolume = l_is_multivolume
        self.is_solid = l_is_solid
        self.is_first_vol = is_first_vol

        for l_index, l_field in enumerate(rar.array("file")):
            if l_max_nb is not None and l_max_nb <= l_index:
                self.warning(
                    "RAR archive contains many files, but only first %s files are processed"
                    % l_max_nb)
                break
            l_meta = Metadata(self)
            l_meta.filename = l_field["filename"].value
            l_meta.last_modification = l_field["ftime"].value
            l_meta.os = l_field["host_os"].display
            l_meta.application_version = l_field["version"].display
            l_meta.compression = l_field["method"].display
            l_meta.file_size = l_field["uncompressed_size"].value
            l_meta.compr_size = l_field["compressed_size"].value
            self.addGroup(l_field.name, l_meta,
                          "File \"%s\"" % l_meta.get('filename'))