Ejemplo n.º 1
0
    def read_bundle_info(self, path):
        """Read Contents/Info.plist inside a bundle."""

        plistpath = os.path.join(path, "Contents", "Info.plist")
        info, format, error = \
            NSPropertyListSerialization.propertyListFromData_mutabilityOption_format_errorDescription_(
                NSData.dataWithContentsOfFile_(plistpath),
                NSPropertyListMutableContainers,
                None,
                None
            )
        if error:
            raise ProcessorError("Can't read %s: %s" % (plistpath, error))

        return info
Ejemplo n.º 2
0
 def main(self):
     # Mount the image.
     mount_point = self.mount(self.env["dmg_path"])
     # Temporary paths that should be deleted afterwards.
     temp_path = None
     sevenzip_path = None
     # Wrap all other actions in a try/finally so the image is always
     # unmounted.
     try:
         pkg_path = os.path.join(mount_point, "Adobe Reader X Installer.pkg")
         
         # Create temporary directory.
         temp_path = tempfile.mkdtemp(prefix="adobereader", dir="/private/tmp")
         expand_path = os.path.join(temp_path, "pkg")
         
         # Expand package.
         self.cmdexec(("/usr/sbin/pkgutil", "--expand",
                       pkg_path, expand_path),
                      "Unpacking Adobe Reader installer")
         
         for name in os.listdir(expand_path):
             if name.endswith(".pkg"):
                 self.unpack_payload(os.path.join(expand_path, name))
         
         app_path = os.path.join(self.env['pkgroot'],
                                 "Applications",
                                 "Adobe Reader.app",
                                 "Contents")
         
         # FIXME: Rewrite this with proper error handling.
         z = zipfile.ZipFile(os.path.join(app_path, "7za.zip"))
         f = z.open("7za")
         fd, sevenzip_path = tempfile.mkstemp()
         print repr(fd), repr(sevenzip_path)
         sevenzip_f = os.fdopen(fd, "wb")
         sevenzip_f.write(f.read())
         f.close()
         sevenzip_f.close()
         os.chmod(sevenzip_path, 0700)
         
         f = z.open("setX.txt")
         xfiles = list()
         for line in f:
             filename = line.partition("#")[0].rstrip()
             if filename:
                 xfiles.append(filename)
         f.close()
         
         self.unsevenzip(app_path, sevenzip_path)
         self.setmodes(app_path, xfiles)
         
         os.unlink(os.path.join(app_path, "7za.zip"))
         os.unlink(os.path.join(app_path, "decompress"))
         
         # Read versions.
         app_info_path = os.path.join(app_path, "Info.plist")
         self.env["app_version"] = self.read_info_plist_version(app_info_path)
         plugin_info_path = os.path.join(self.env['pkgroot'],
                                         "Library",
                                         "Internet Plug-Ins",
                                         "AdobePDFViewer.plugin",
                                         "Contents",
                                         "Info.plist")
         self.env["plugin_version"] = self.read_info_plist_version(plugin_info_path)
         
     except BaseException as e:
         raise ProcessorError(e)
     finally:
         self.unmount(self.env["dmg_path"])
         for path in (temp_path, sevenzip_path):
             if os.path.isdir(path):
                 shutil.rmtree(path)
             elif os.path.isfile(path):
                 os.unlink(path)
Ejemplo n.º 3
0
    def main(self):
        # Mount the image.
        mount_point = self.mount(self.env["dmg_path"])
        temp_path = None
        # Wrap all other actions in a try/finally so the image is always
        # unmounted.
        try:
            pkg_path = os.path.join(mount_point,
                                    "Install Adobe Flash Player.app",
                                    "Contents", "Resources",
                                    "Adobe Flash Player.pkg", "Contents")

            # Create temporary directory.
            temp_path = tempfile.mkdtemp(prefix="flashXX", dir="/private/tmp")
            if len(temp_path) != len("/Library/Internet Plug-Ins"):
                raise ProcessorError("temp_path length mismatch.")

            # Unpack payload.
            try:
                p = subprocess.Popen(("/usr/bin/ditto", "-x", "-z",
                                      pkg_path + "/Archive.pax.gz", temp_path),
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.PIPE)
                (out, err) = p.communicate()
            except OSError as e:
                raise ProcessorError(
                    "ditto execution failed with error code %d: %s" %
                    (e.errno, e.strerror))
            if p.returncode != 0:
                raise ProcessorError("Unpacking Flash payload failed: %s" %
                                     err)

            # Move payload up out of Internet Plug-Ins if necessary.
            temp_plugins_path = os.path.join(temp_path, "Internet Plug-Ins")
            if os.path.isdir(temp_plugins_path):
                for item in os.listdir(temp_plugins_path):
                    src = os.path.join(temp_plugins_path, item)
                    dst = os.path.join(temp_path, item)
                    try:
                        os.rename(src, dst)
                    except OSError as e:
                        raise ProcessorError("Couldn't move %s to %s" %
                                             (src, dst))
                os.rmdir(temp_plugins_path)

            # Patch postflight executable.
            with open(pkg_path + "/Resources/postflight", "rb") as f:
                postflight = f.read()
            postflight_path = os.path.join(temp_path, "postflight")
            with open(postflight_path, "wb") as f:
                f.write(
                    postflight.replace("/Library/Internet Plug-Ins",
                                       temp_path))
            os.chmod(postflight_path, 0700)

            # Run patched postflight to unpack plugin.
            subprocess.check_call(postflight_path)

            # Check plugin paths.
            plugin_path = os.path.join(temp_path, "Flash Player.plugin")
            xpt_path = os.path.join(temp_path, "flashplayer.xpt")
            if not os.path.isdir(plugin_path):
                raise ProcessorError("Unpacking Flash plugin failed.")

            # Read version.
            info = self.read_bundle_info(plugin_path)
            self.env["version"] = info["CFBundleShortVersionString"]

            # Copy files to destination.
            plugin_destination = os.path.join(self.env["unpack_dir"],
                                              "Flash Player.plugin")
            xpt_destination = os.path.join(self.env["unpack_dir"],
                                           "flashplayer.xpt")
            shutil.copytree(plugin_path, plugin_destination, symlinks=True)
            shutil.copy2(xpt_path, xpt_destination)

            self.env["unpacked_items"] = [
                "Flash Player.plugin", "flashplayer.xpt"
            ]
        except BaseException as e:
            raise ProcessorError(e)
        finally:
            if temp_path:
                shutil.rmtree(temp_path)
            self.unmount(self.env["dmg_path"])