Exemple #1
0
        public void installFiles(Session session)
        {
            if (session.FileExists("/entitlements.ent"))
            {
                session.RemoveFiles("/entitlements.ent");
                if (verbose)
                {
                    log("Removed old entitlements file from the device");
                }
            }
            createDirIfDoesntExist("backup");
            if (Directory.Exists("files\\Applications") && jtool)
            {
                File.Copy("entitlements.ent", "files\\entitlements.ent", true);
                if (verbose)
                {
                    log("Entitlements needed. Copying entitlements file");
                }
            }
            if (Directory.Exists("files\\Applications\\electra.app"))
            {
                if (verbose)
                {
                    log("please no");
                }
                var f = MessageBox.Show("Please do not try this");
                Environment.Exit(0);
            }
            if (verbose)
            {
                log("Creating directory list");
            }
            string[] directories = Directory.GetDirectories("files", "*", searchOption: System.IO.SearchOption.AllDirectories);
            if (verbose)
            {
                log("Got list. Creating backup folders");
            }
            foreach (string dir in directories)
            {
                if (!Directory.Exists("backup\\" + dir.Replace("files\\", "\\")))
                {
                    Directory.CreateDirectory("backup\\" + dir.Replace("files\\", "\\"));
                }
            }
            log("Preparing to install");

            if (verbose)
            {
                log("Creating local file list");
            }
            List <string> local = new List <string>();

            crawler.Files.ForEach(i => local.Add(convert_path(i)));

            if (verbose)
            {
                log("Creating remote file list");
            }
            List <string> remote = new List <string>();

            foreach (string i in Directory.GetDirectories("files"))
            {
                string dir = new DirectoryInfo(i).Name;
                if (dir == "System")
                {
                    log("This tweak may take longer than usual to process (45 second max)");
                }
                session.ExecuteCommand("find /" + dir + " > ~/files.list");
                session.GetFiles("/var/root/files.list", "files.list");
                foreach (string file in File.ReadAllLines("files.list"))
                {
                    remote.Add(file);
                }
                File.Delete("files.list");
            }

            List <string> duplicates = new List <string>();

            foreach (string i in local)
            {
                if (remote.Contains(i))
                {
                    duplicates.Add(i);
                }
            }
            bool overwrite = false;

            foreach (var i in duplicates)
            {
                bool go = false, action = false;
                if (!overwrite)
                {
                    if (verbose)
                    {
                        log(convert_path(i) + " already exists");
                    }
                    var dialog = new YNAD("Do you want to backup and overwrite " + convert_path(i) + "? (y/n/a)");
                    dialog.ShowDialog();
                    while (true)
                    {
                        switch (dialog.result)
                        {
                        case 1:
                            go     = true;
                            action = true;
                            break;

                        case 3:
                            go        = true;
                            action    = true;
                            overwrite = true;
                            break;

                        case 2:
                            action = false;
                            go     = true;
                            break;
                        }
                        log("\n");
                        if (go)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    action = true;
                }
                if (!action)
                {
                    if (verbose)
                    {
                        log("Skipping file " + i);
                    }
                    File.Delete("files\\" + i);
                    if (!skip.Contains(i))
                    {
                        skip.Add(i);
                    }
                }
                session.GetFiles(convert_path(i), @"backup\" + i.Replace("/", "\\"));
            }
            log("Installing");
            foreach (string dir in Directory.GetDirectories("files"))
            {
                if (verbose)
                {
                    log("Installing directory " + dir);
                }
                session.PutFiles(dir, "/"); //put directories
            }
            foreach (string file in Directory.GetFiles("files"))
            {
                if (verbose)
                {
                    log("Installing file " + file);
                }
                session.PutFiles(file, "/"); //put files
            }
            File.WriteAllLines("skip.list", skip);
            if (Directory.Exists("files\\Applications") && jtool)
            {
                if (verbose)
                {
                    log("Entitlements needed");
                }
                session.PutFiles("entitlements.ent", "/");
                if (verbose)
                {
                    log("Sending entitlements");
                }
                log("Signing applications");
                foreach (var app in Directory.GetDirectories("files\\Applications\\"))
                {
                    uicache = true;
                    if (verbose)
                    {
                        log("Signing " + convert_path(app.Replace("files\\", "\\")));
                    }
                    crawler = new Crawler(app, true);
                    crawler.Files.ForEach(i =>
                    {
                        bool sign = false;
                        if (new FileInfo(i).Name.Split('.').Length < 2)
                        {
                            sign = true;
                        }
                        if (!sign)
                        {
                            if (i.Split('.').Last() == "dylib")
                            {
                                sign = true;
                            }
                        }
                        i = convert_path(i);
                        if (File.Exists(app + "\\skip-signing"))
                        {
                            sign = false;
                            if (verbose)
                            {
                                log("Skipped Signing " + i);
                            }
                        }
                        if (sign && !dont_sign)
                        {
                            session.ExecuteCommand("jtool -e arch -arch arm64 " + convert_path(app.Replace("files\\", "\\")) + i);
                            session.ExecuteCommand("mv " + convert_path(app.Replace("files\\", "\\")) + i + ".arch_arm64 " + convert_path(app.Replace("files\\", "\\")) + i);
                            session.ExecuteCommand("jtool --sign --ent /entitlements.ent --inplace " + convert_path(app.Replace("files\\", "\\")) + i);
                            if (verbose)
                            {
                                log("Signed " + convert_path(app.Replace("files\\", "\\")) + i);
                            }
                        }
                    });
                    crawler = new Crawler("files");
                    crawler.Files.ForEach(i =>
                    {
                        session.ExecuteCommand("chmod 777 " + convert_path(i.Replace("\\files", "")));
                    });
                }
            }
            if (File.Exists("postinst"))
            {
                if (verbose)
                {
                    log("Running postinst script");
                }
                session.PutFiles("postinst", "script");
                session.ExecuteCommand("./script && rm script");
            }
            clean();
            finish(session);
            log("Done");
        }
Exemple #2
0
        public void uninstallFiles(Session session)
        {
            log("Preparing to uninstall");
            bool          overwrite = false;
            List <string> remove    = new List <string>();

            crawler.Files.ForEach(i =>
            {
                if (!skip.Contains(i))
                {
                    bool go = false, action = false;
                    if (File.Exists("backup" + i) && !overwrite)
                    {
                        if (verbose)
                        {
                            log("You have a backup of this file");
                        }
                        var dialog = new YNAD("Do you want to restore " + convert_path(i) + " from your backup? (y/n/a)");
                        dialog.ShowDialog();
                        while (true)
                        {
                            switch (dialog.result)
                            {
                            case 1:
                                go     = true;
                                action = true;
                                break;

                            case 3:
                                go        = true;
                                action    = true;
                                overwrite = true;
                                break;

                            case 2:
                                action = false;
                                go     = true;
                                break;
                            }
                            log("\n");
                            if (go)
                            {
                                break;
                            }
                        }
                    }
                    if (action || overwrite)
                    {
                        string path = i.Replace(i.Substring(i.LastIndexOf('\\')), "");
                        session.PutFiles(new FileInfo("backup" + convert_path(i)).ToString().Replace("/", "\\"), convert_path(path) + "/" + new FileInfo(i).Name);
                        if (verbose)
                        {
                            log("Reinstalled " + i);
                        }
                    }
                    else
                    {
                        remove.Add(convert_path(i, true));
                    }
                }
            });
            log("Uninstalling");
            string script = "";

            foreach (string i in remove)
            {
                script += "rm " + i + "\n";
            }
            File.WriteAllText("script.sh", script);
            session.PutFiles("script.sh", "script.sh");
            session.ExecuteCommand("sh script.sh");
            if (Directory.Exists("files\\Applications"))
            {
                if (verbose)
                {
                    log("uicache refresh required");
                }
                uicache = true;
            }
            log("Locating and removing *some* empty folders");
            session.ExecuteCommand("find /System/Library/Themes/ -type d -empty -delete");
            session.ExecuteCommand("find /usr/ -type d -empty -delete");
            session.ExecuteCommand("find /Applications/ -type d -empty -delete");
            session.ExecuteCommand("find /Library/ -type d -empty -delete");
            session.ExecuteCommand("find /bootstrap/Library/Themes/* -type d -empty -delete");
            session.ExecuteCommand("find /bootstrap/Library/PreferenceLoader/* -type d -empty -delete");
            session.ExecuteCommand("find /bootstrap/Library/PreferenceBundles/* -type d -empty -delete");
            session.ExecuteCommand("find /bootstrap/Library/SBInject/* -type d -empty -delete");
            if (File.Exists("postrm"))
            {
                if (verbose)
                {
                    log("Running postrm script");
                }
                session.PutFiles("postrm", "script");
                session.ExecuteCommand("./script && rm script");
            }
            clean();
            finish(session);
            log("Done");
        }