Exemplo n.º 1
0
    def pullFstab(self):
        import adb
        with FileTools.newTmpDir() as tmpDir:

            mountCommandOutFile = os.path.join(tmpDir, "mount_out")
            mountCommandOut = self.adb.shell("mount")
            with open(mountCommandOutFile, "w") as out:
                out.write(mountCommandOut)

            try:
                recoveryFstabPath = os.path.join(tmpDir, "recovery.fstab")
                self.adb.pull("/etc/recovery.fstab", recoveryFstabPath)
                parsedRecoveryFstab = Fstab.parseFstab(recoveryFstabPath)
            except adb.usb_exceptions.AdbCommandFailureException as ex:
                parsedRecoveryFstab = Fstab.parseFstab(mountCommandOutFile)

            try:
                fstabPath = os.path.join(tmpDir, "fstab")
                self.adb.pull("/etc/fstab", fstabPath)
                parsedFstab = Fstab.parseFstab(fstabPath)

                for entry in parsedFstab.getEntries():
                    recovFstabEntry = parsedRecoveryFstab.getByMountPoint(entry.getMountPoint())
                    recovFstabEntry.setDevice(entry.getDevice())
                return parsedRecoveryFstab
            except (adb.usb_exceptions.AdbCommandFailureException, adb.usb_exceptions.ReadFailedError) as ex:
                return parsedRecoveryFstab
Exemplo n.º 2
0
    def syncProps(self, apply = False):
        propsDict = {}
        with FileTools.newTmpDir() as tmpDir:
            propsDir = os.path.join(tmpDir, "props")
            self.adb.pull("/data/property", propsDir)
            for f in os.listdir(propsDir):
                if f.startswith("."):
                    continue
                fullPath = os.path.join(propsDir, f)
                with open(fullPath, 'r') as fHandle:
                    currFileVal = fHandle.read()
                    keys = f.split(".")
                    if keys[0] == "persist":
                        keys = keys[1:]

                    if currFileVal == self.config.get("update.property." + (".".join(keys)), None):
                        continue

                    subDict = propsDict
                    for i in range(0, len(keys) - 1):
                        k = keys[i]
                        if not k in subDict:
                            subDict[k] = {}

                        if type(subDict[k]) is not dict:
                            subDict[k] = {"__val__": subDict[k]}
                        subDict = subDict[k]


                    subDict[keys[-1]] = currFileVal

        if apply:
            self.config.setRecursive("update.property", propsDict)

        return propsDict
Exemplo n.º 3
0
    def process(self):
        super(AutorootArgParser, self).process()

        identifier = self.args["base"] or self.args["variant"]

        config = self.configTreeParser.parseJSON(identifier)

        if config.get("__config__") is None:
            sys.stderr.write(
                "You are using an outdated config tree. Please run 'incept sync -v VARIANT_CODE' or set __config__ (see https://goo.gl/aFWPby)\n"
            )
            sys.exit(1)

        autorootBase = identifier if config.isBase() else ".".join(
            identifier.split(".")[:-1])

        config = ConfigV2.new(autorootBase + ".autoroot", "autoroot", config)

        if self.args["output"]:
            config.setOutPath(self.args["output"])

        config.set("update.restore_stock_recovery", True)
        config.set("update.__make__", True)
        config.set("odin.__make__", True)
        config.set("odin.checksum", True)
        config.set("cache.__make__", True)
        config.set("update.databases.__make__", False)
        config.set("update.settings.__make__", False)
        config.set("update.adb.__make__", False)
        config.set("update.property.__make__", False)
        config.set("update.apps.__make__", False)
        config.set("update.network.__make__", False)
        config.set("update.script.format_data", False)
        config.set("update.root_method", "supersu")
        config.set("update.busybox.__make__", False)
        config.set("update.files.__override__", True)
        config.set("update.script.wait", 0)
        config.set("update.keys", "test")
        config.set("recovery.__make__", not self.args["no_recovery"])
        config.set("boot.__make__", False)
        config.set("__config__.target.root.methods.supersu.include_apk", True)
        config.set("__config__.target.root.methods.supersu.include_archs", [])

        if not config.get("recovery.stock"):
            print(
                "Autoroot requires having recovery.stock set, and it's not for %s"
                % identifier)
            sys.exit(1)

        if not self.args["no_recovery"] and not config.get("recovery.img"):
            logger.error(
                "recovery.img is not set, use --no-recovery to not make recovery"
            )
            sys.exit(1)

        with FileTools.newTmpDir() as workDir:
            config.make(workDir)

        return True
Exemplo n.º 4
0
    def process(self):
        super(AutorootArgParser, self).process()

        identifier = self.args["base"] or self.args["variant"]

        config = self.configTreeParser.parseJSON(identifier)

        if config.get("__config__") is None:
            sys.stderr.write("You are using an outdated config tree. Please run 'incept sync -v VARIANT_CODE' or set __config__ (see https://goo.gl/aFWPby)\n")
            sys.exit(1)

        autorootBase = identifier if config.isBase() else ".".join(identifier.split(".")[:-1])

        config = ConfigV2.new(autorootBase + ".autoroot", "autoroot", config)



        if self.args["output"]:
            config.setOutPath(self.args["output"])

        config.set("update.restore_stock_recovery", True)
        config.set("update.__make__", True)
        config.set("odin.__make__", True)
        config.set("odin.checksum", True)
        config.set("cache.__make__", True)
        config.set("update.databases.__make__", False)
        config.set("update.settings.__make__", False)
        config.set("update.adb.__make__", False)
        config.set("update.property.__make__", False)
        config.set("update.apps.__make__", False)
        config.set("update.network.__make__", False)
        config.set("update.script.format_data", False)
        config.set("update.root_method", "supersu")
        config.set("update.busybox.__make__", False)
        config.set("update.files.__override__", True)
        config.set("update.script.wait", 0)
        config.set("update.keys", "test")
        config.set("recovery.__make__", not self.args["no_recovery"])
        config.set("boot.__make__", False)
        config.set("__config__.target.root.methods.supersu.include_apk", True)
        config.set("__config__.target.root.methods.supersu.include_archs", [])


        if not config.get("recovery.stock"):
            print("Autoroot requires having recovery.stock set, and it's not for %s" % identifier)
            sys.exit(1)

        if not self.args["no_recovery"] and not config.get("recovery.img"):
            logger.error("recovery.img is not set, use --no-recovery to not make recovery")
            sys.exit(1)

        with FileTools.newTmpDir() as workDir:
            config.make(workDir)

        return True
Exemplo n.º 5
0
    def pullFstab(self):
        with FileTools.newTmpDir() as tmpDir:
            recoveryFstabPath = os.path.join(tmpDir, "recovery.fstab")
            self.adb.pull("/etc/recovery.fstab", recoveryFstabPath)
            parsedRecoveryFstab = Fstab.parseFstab(recoveryFstabPath)

            fstabPath = os.path.join(tmpDir, "fstab")
            self.adb.pull("/etc/fstab", fstabPath)
            parsedFstab = Fstab.parseFstab(fstabPath)

            for entry in parsedFstab.getEntries():
                recovFstabEntry = parsedRecoveryFstab.getByMountPoint(entry.getMountPoint())
                recovFstabEntry.setDevice(entry.getDevice())


            return parsedRecoveryFstab
Exemplo n.º 6
0
    def pullAndDiff(self):
        import adb

        fullDiff = {
                "settings": {},
                "databases": {}
        }
        with FileTools.newTmpDir() as tmpDir:
            currSettings = self.config.get("update.settings", {})
            tmpDir = os.path.join(tmpDir, "db")
            os.makedirs(tmpDir)
            dbPath = os.path.join(tmpDir, "curr.db")
            dbPathShm = dbPath + "-shm"
            dbPathWal = dbPath + "-wal"

            if not len(currSettings):
                logger.warning("Config does not contain settings data, or overrides settings with no data")


            for identifier, data in currSettings.items():
                if identifier == "__make__":
                    continue
                path = data["path"]

                self.adb.pull(path, dbPath)
                try:
                    self.adb.pull(path + "-shm", dbPathShm)
                except adb.usb_exceptions.AdbCommandFailureException:
                    pass

                try:
                    self.adb.pull(path + "-wal", dbPathWal)
                except (adb.usb_exceptions.AdbCommandFailureException, adb.usb_exceptions.ReadFailedError):
                    pass

                # databaseConfig = self.config.get("update.databases.%s" % identifier.replace(".", "\."), {"data": {}})
                schemaProperty = self.config.getProperty("update.settings.%s.schema" % identifier.replace(".", "\."))
                data["schema"] = schemaProperty.resolveAsRelativePath()
                if data["schema"] and not os.path.exists(data["schema"]):
                    data["schema"] = schemaProperty.getValue()
                diffSettingsConfig, databaseConfig = self.diffSettings(data, dbPath)

                databaseConfig["__depend__"] = "update.settings.%s" % identifier.replace(".", "\.")

                fullDiff["settings"][identifier] = diffSettingsConfig
                fullDiff["databases"][identifier] = databaseConfig
        return fullDiff
Exemplo n.º 7
0
    def pullAndDiff(self):
        import adb

        fullDiff = {
                "settings": {},
                "databases": {}
        }
        with FileTools.newTmpDir() as tmpDir:
            currSettings = self.config.get("update.settings", {})
            tmpDir = os.path.join(tmpDir, "db")
            os.makedirs(tmpDir)
            dbPath = os.path.join(tmpDir, "curr.db")
            dbPathShm = dbPath + "-shm"
            dbPathWal = dbPath + "-wal"

            if not len(currSettings):
                logger.warning("Config does not contain settings data, or overrides settings with no data")


            for identifier, data in currSettings.items():
                if identifier == "__make__":
                    continue
                path = data["path"]

                self.adb.pull(path, dbPath)
                try:
                    self.adb.pull(path + "-shm", dbPathShm)
                except adb.usb_exceptions.AdbCommandFailureException:
                    pass

                try:
                    self.adb.pull(path + "-wal", dbPathWal)
                except (adb.usb_exceptions.AdbCommandFailureException, adb.usb_exceptions.ReadFailedError):
                    pass

                # databaseConfig = self.config.get("update.databases.%s" % identifier.replace(".", "\."), {"data": {}})
                schemaProperty = self.config.getProperty("update.settings.%s.schema" % identifier.replace(".", "\."))
                data["schema"] = schemaProperty.resolveAsRelativePath()
                if data["schema"] and not os.path.exists(data["schema"]):
                    data["schema"] = schemaProperty.getValue()
                diffSettingsConfig, databaseConfig = self.diffSettings(data, dbPath)

                databaseConfig["__depend__"] = "update.settings.%s" % identifier.replace(".", "\.")

                fullDiff["settings"][identifier] = diffSettingsConfig
                fullDiff["databases"][identifier] = databaseConfig
        return fullDiff
Exemplo n.º 8
0
    def process(self):
        super(AutorootArgParser, self).process()

        identifier = self.args["base"] or self.args["variant"]

        config = self.configTreeParser.parseJSON(identifier)

        autorootBase = identifier if config.isBase() else ".".join(identifier.split(".")[:-1])

        config = Config.new(autorootBase + ".autoroot", "autoroot", config)
        if self.args["output"]:
            config.setOutPath(self.args["output"])

        config.set("update.restore_stock_recovery", True)
        config.set("update.__make__", True)
        config.set("odin.__make__", True)
        config.set("odin.checksum", True)
        config.set("cache.__make__", True)
        config.set("update.databases.__make__", False)
        config.set("update.settings.__make__", False)
        config.set("update.adb.__make__", False)
        config.set("update.property.__make__", False)
        config.set("update.apps.__make__", False)
        config.set("update.network.__make__", False)
        config.set("update.script.format_data", False)
        config.set("update.root_method", "supersu")
        config.set("update.busybox.__make__", False)
        config.set("update.files.__override__", True)
        config.set("update.keys", "test")
        config.set("recovery.__make__", True)
        config.set("boot.__make__", False)
        config.set("common.root.methods.supersu.include_apk", True)
        config.set("commont.root.methods.supersu.include_archs", [])


        if not config.get("recovery.stock"):
            print("Autoroot requires having recovery.stock set, and it's not for %s" % identifier)
            sys.exit(1)

        with FileTools.newTmpDir() as workDir:
            config.make(workDir)

        return True
Exemplo n.º 9
0
    def process(self):
        super(BusyboxArgParser, self).process()

        identifier = self.args["base"] or self.args["variant"]

        config = self.configTreeParser.parseJSON(identifier)

        autorootBase = identifier if config.isBase() else ".".join(identifier.split(".")[:-1])

        config = Config.new(autorootBase + ".busybox", "busybox", config)

        if self.args["output"]:
            config.setOutPath(self.args["output"])

        config.set("update.__make__", True)
        config.set("odin.__make__", True)
        config.set("odin.checksum", True)
        config.set("cache.__make__", True)
        config.set("update.databases.__make__", False)
        config.set("update.settings.__make__", False)
        config.set("update.adb.__make__", False)
        config.set("update.property.__make__", False)
        config.set("update.apps.__make__", False)
        config.set("update.network.__make__", False)
        config.set("update.script.format_data", False)
        config.set("update.root_method", None)
        config.set("update.busybox.__make__", True)
        config.set("update.files.__override__", True)
        config.set("update.keys", "test")
        config.set("recovery.__make__", True)
        config.set("boot.__make__", False)
        config.set("update.restore_stock_recovery", not self.args["ignore_stock"])

        if not self.args["ignore_stock"] and not config.get("recovery.stock"):
            logger.error("recovery.stock is not set, use --ignore-stock to not restore stock recovery when done." )
            sys.exit(1)

        with FileTools.newTmpDir() as workDir:
            config.make(workDir)

        return True
Exemplo n.º 10
0
    def syncProps(self, apply = False):
        propsDict = {}
        with FileTools.newTmpDir() as tmpDir:
            propsDir = os.path.join(tmpDir, "props")
            os.makedirs(propsDir)
            self.adb.superPull("/data/property", propsDir, fallback=True)
            for f in os.listdir(propsDir):
                if f.startswith("."):
                    continue
                fullPath = os.path.join(propsDir, f)
                with open(fullPath, 'r') as fHandle:
                    currFileVal = fHandle.read()
                    keys = f.split(".")
                    if keys[0] == "persist":
                        keys = keys[1:]

                    if currFileVal == self.config.get("update.property." + (".".join(keys)), None):
                        continue

                    subDict = propsDict
                    for i in range(0, len(keys) - 1):
                        k = keys[i]
                        if not k in subDict:
                            subDict[k] = {}

                        if type(subDict[k]) is not dict:
                            subDict[k] = {"__val__": subDict[k]}
                        subDict = subDict[k]


                    subDict[keys[-1]] = currFileVal

        if apply:
            self.config.setRecursive("update.property", propsDict)

        return propsDict