예제 #1
0
        private static void ExtractAndAdd(BackgroundWorker worker, string name, string extension, string ftffile, string AsFilename = "")
        {
            if (Zipping.ExistsInZip(ftffile, name + ".sin") == false)
            {
                OnError(name, AsFilename);
                return;
            }

            Zipping.UnzipFile(worker, ftffile, name + ".sin", string.Empty, Utility.GetTempPath(), false);
            if (File.Exists(Path.Combine(Utility.GetTempPath(), name + ".sin")))
            {
                Logger.WriteLog("   " + name);
                SinExtract.ExtractSin(worker, Path.Combine(Utility.GetTempPath(), name + ".sin"), Path.Combine(Utility.GetTempPath(), name + extension), false);

                if (PartitionInfo.ScriptMode == PartitionInfo.Mode.LegacyUUID)
                {
                    byte[] UUID = PartitionInfo.ReadSinUUID(Path.Combine(Utility.GetTempPath(), name + ".sin"));
                    Utility.ScriptSetUUID(worker, (AsFilename == "" ? name : AsFilename), UUID);
                }

                File.Delete(Path.Combine(Utility.GetTempPath(), name + ".sin"));
                Zipping.AddToZip(worker, Settings.destinationFile, Path.Combine(Utility.GetTempPath(), name + extension), (AsFilename == "" ? name : AsFilename) + extension, false);
                File.Delete(Path.Combine(Utility.GetTempPath(), name + extension));
            }
        }
예제 #2
0
파일: Job.cs 프로젝트: vaginessa/PRFCreator
 private static void AddSystem(BackgroundWorker worker)
 {
     SetJobNum(++JobNum);
     Logger.WriteLog("Adding system to zip");
     Zipping.AddToZip(worker, Settings.destinationFile, Path.Combine(Utility.GetTempPath(), "system.sin"), "system.sin", true);
     File.Delete(Path.Combine(Utility.GetTempPath(), "system.sin"));
 }
예제 #3
0
파일: Job.cs 프로젝트: vaginessa/PRFCreator
        public static void Worker()
        {
            JobNum = 0;
            int free = Utility.freeSpaceMB(Utility.GetTempPath());

            if (free < 4096)
            {
                Logger.WriteLog("Error: Not enough disk space. Please make sure that you have atleast 4GB free space on drive " + Path.GetPathRoot(Utility.GetTempPath())
                                + ". Currently you only have " + free + "MB available");
                return;
            }
            if (!Zipping.ExistsInZip(Form1.form.ftf_textbox.Text, "system.sin"))
            {
                Logger.WriteLog("Error: system.sin does not exist in file " + Form1.form.ftf_textbox.Text);
                return;
            }
            BackgroundWorker worker = new BackgroundWorker();

            worker.WorkerReportsProgress      = true;
            worker.WorkerSupportsCancellation = true;
            worker.DoWork += (o, _e) =>
            {
                try
                {
                    Form1.form.ControlsEnabled(false);
                    if (Form1.form.options_checklist.CheckedItems.Contains("Legacy mode"))
                    {
                        jobs = legacyjobs;
                    }
                    else
                    {
                        jobs = newjobs;
                    }
                    foreach (Action <BackgroundWorker> action in jobs)
                    {
                        if (worker.CancellationPending)
                        {
                            Cancel(worker);
                            _e.Cancel = true;
                            break;
                        }
                        action(worker);
                    }
                }
                catch (Exception e)
                {
                    Logger.WriteLog(e.Message);
                    //Logger.WriteLog(e.StackTrace);
                }
            };
            worker.ProgressChanged += (o, _e) =>
            {
                Form1.form.progressBar.Value = _e.ProgressPercentage;
            };
            worker.RunWorkerCompleted += (o, _e) =>
            {
                Form1.form.ControlsEnabled(true);
            };
            worker.RunWorkerAsync();
        }
예제 #4
0
        public static void FetchSinFromFTF(string ftf)
        {
            InitDic();
            Utility.InvokeIfNecessary(Form1.form.include_checklist, () => { Form1.form.include_checklist.Items.Clear(); });

            string[] filelist = Zipping.ListZipContent(ftf);
            foreach (string key in extrafilesDic.Keys)
            {
                foreach (string key2 in extrafilesDic[key].Keys)
                {
                    foreach (string name in extrafilesDic[key][key2])
                    {
                        foreach (string f in filelist)
                        {
                            if (Regex.Match(f, name + "\\.sin").Success)
                            {
                                //Logger.WriteLog("Found sinfile: " + key);
                                Utility.InvokeIfNecessary(Form1.form.include_checklist, () =>
                                {
                                    Form1.form.include_checklist.Items.Add(key);
                                });
                                goto OuterLoop;
                            }
                        }
                    }
                }
OuterLoop:
                ;
            }
        }
예제 #5
0
        public static void AddAPKFile(BackgroundWorker worker, string filename, string type)
        {
            Logger.WriteLog("Adding APK: " + Path.GetFileName(filename));
            if (!Zipping.UnzipFile(worker, filename, "AndroidManifest.xml", string.Empty, Utility.GetTempPath(), false))
            {
                Logger.WriteLog("Error adding APK: AndroidManifest.xml not found");
                return;
            }
            string appname = Utility.ManifestGetName(File.ReadAllBytes(Path.Combine(Utility.GetTempPath(), "AndroidManifest.xml")));

            File.Delete(Path.Combine(Utility.GetTempPath(), "AndroidManifest.xml"));
            if (appname == null)
            {
                Logger.WriteLog("Error adding APK: Could not read appname from AndroidManifest.xml");
                return;
            }

            if (type == "App (System)")
            {
                Zipping.AddToZip(worker, Settings.destinationFile, filename, "system/app/" + appname + Path.GetExtension(filename), false);
            }
            else
            {
                Zipping.AddToZip(worker, Settings.destinationFile, filename, "data/app/" + appname + Path.GetExtension(filename), false);
            }
        }
예제 #6
0
파일: Job.cs 프로젝트: vaginessa/PRFCreator
        private static void AddSuperSU(BackgroundWorker worker)
        {
            SetJobNum(++JobNum);
            Logger.WriteLog("Adding " + Path.GetFileName(Form1.form.su_textbox.Text));
            string superSUFile = Form1.form.su_textbox.Text;

            Zipping.AddToZip(worker, Settings.destinationFile, superSUFile, "SuperSU.zip", false);
        }
예제 #7
0
        private void create_button_Click(object sender, EventArgs e)
        {
            if (isWorking)
            {
                return;
            }
            if (!File.Exists(ftf_textbox.Text))
            {
                Logger.WriteLog("Error: Please specify a valid FTF file");
                return;
            }
            if (!File.Exists(su_textbox.Text))
            {
                Logger.WriteLog("Error: Please specify a valid SuperSU.zip");
                return;
            }
            else if (Zipping.ExistsInZip(su_textbox.Text, "updater-script"))
            {
                Logger.WriteLog("Info: No updater-script found in SuperSU zip. Are you sure it's a flashable zip?");
            }
            if (!File.Exists(rec_textbox.Text))
            {
                Logger.WriteLog("Info: Not adding recovery");
            }
            else if (Zipping.ExistsInZip(rec_textbox.Text, "updater-script"))
            {
                Logger.WriteLog("Info: No updater-script found in Recovery zip. Are you sure it's a flashable zip?");
            }

            if (Settings.saveDialog)
            {
                using (SaveFileDialog sfd = new SaveFileDialog())
                {
                    sfd.Filter = "Zip Files (*.zip)|*.zip";
                    if (sfd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    {
                        return;
                    }

                    Settings.destinationFile = sfd.FileName;
                }
            }
            else
            {
                Settings.destinationFile = "flashable-prerooted.zip";
            }

            Utility.WriteResourceToFile("PRFCreator.Resources.flashable-prerooted.zip", Settings.destinationFile);
            if (!File.Exists(Settings.destinationFile))
            {
                Logger.WriteLog("Error: Unable to extract flashable-prerooted.zip from the exe");
                return;
            }

            Job.Worker();
        }
예제 #8
0
        public static void EditScript(BackgroundWorker worker, string search, string replace)
        {
            Zipping.UnzipFile(worker, Settings.destinationFile, "updater-script", "META-INF/com/google/android", Utility.GetTempPath(), false);
            string content = File.ReadAllText(Path.Combine(Utility.GetTempPath(), "updater-script"), Encoding.ASCII);

            content = content.Replace(search, replace);
            File.WriteAllText(Path.Combine(Utility.GetTempPath(), "updater-script"), content, Encoding.ASCII);
            Zipping.AddToZip(worker, Settings.destinationFile, Path.Combine(Utility.GetTempPath(), "updater-script"), "META-INF/com/google/android/updater-script", false);
            File.Delete(Path.Combine(Utility.GetTempPath(), "updater-script"));
        }
예제 #9
0
파일: Job.cs 프로젝트: vaginessa/PRFCreator
        private static void AddRecovery(BackgroundWorker worker)
        {
            if (!File.Exists(Form1.form.rec_textbox.Text))
            {
                return;
            }

            SetJobNum(++JobNum);
            string recoveryFile = Form1.form.rec_textbox.Text;

            Logger.WriteLog("Adding " + Path.GetFileName(recoveryFile));
            Zipping.AddToZip(worker, Settings.destinationFile, recoveryFile, "dualrecovery.zip");
        }
예제 #10
0
        private static string GetModemFilename(string ftffile)
        {
            string[] mdms = { "amss_fsg", "amss_fs_3", "modem" };
            foreach (string mdm in mdms)
            {
                if (Zipping.ExistsInZip(ftffile, mdm + ".sin"))
                {
                    return(mdm);
                }
            }

            return("modem");
        }
예제 #11
0
        private static string GetKernelFilename(string ftffile)
        {
            string[] names = { "kernel", "boot" };
            foreach (string name in names)
            {
                if (Zipping.ExistsInZip(ftffile, name + ".sin"))
                {
                    return(name);
                }
            }

            //if nothing exists, return kernel anyway so the error message makes sense
            return("kernel");
        }
예제 #12
0
        public static string ReadConfig(BackgroundWorker worker, string key)
        {
            Zipping.UnzipFile(worker, Settings.destinationFile, "prfconfig", string.Empty, Utility.GetTempPath(), false);
            string content = File.ReadAllText(Path.Combine(Utility.GetTempPath(), "prfconfig"), Encoding.ASCII);

            File.Delete(Path.Combine(Utility.GetTempPath(), "prfconfig"));

            if (!content.Contains(key + "="))
            {
                return(null);
            }

            return(Regex.Match(content, "^" + key + "=(.*)$", RegexOptions.Multiline).Groups[1].Value);
        }
예제 #13
0
        public static void EditConfig(BackgroundWorker worker, string key, string value)
        {
            Zipping.UnzipFile(worker, Settings.destinationFile, "prfconfig", string.Empty, Utility.GetTempPath(), false);
            string content = File.ReadAllText(Path.Combine(Utility.GetTempPath(), "prfconfig"), Encoding.ASCII);

            if (!content.Contains(key + "="))
            {
                content += "\n" + key + "=" + value;
            }
            else
            {
                content = Regex.Replace(content, "^" + key + "=.*$", key + "=" + value, RegexOptions.Multiline);
            }

            File.WriteAllText(Path.Combine(Utility.GetTempPath(), "prfconfig"), content, Encoding.ASCII);
            Zipping.AddToZip(worker, Settings.destinationFile, Path.Combine(Utility.GetTempPath(), "prfconfig"), "prfconfig", false);
            File.Delete(Path.Combine(Utility.GetTempPath(), "prfconfig"));
        }
예제 #14
0
        private static bool ExtractAndAddSin(BackgroundWorker worker, string name, string ftffile, string AsFilename = "")
        {
            if (Zipping.ExistsInZip(ftffile, name + ".sin") == false)
            {
                OnError(name, AsFilename);
                return(false);
            }

            Zipping.UnzipFile(worker, ftffile, name + ".sin", string.Empty, Utility.GetTempPath(), false);
            if (File.Exists(Path.Combine(Utility.GetTempPath(), name + ".sin")))
            {
                Logger.WriteLog("   " + name);
                Zipping.AddToZip(worker, Settings.destinationFile, Path.Combine(Utility.GetTempPath(), name + ".sin"), (AsFilename == "" ? name : AsFilename) + ".sin", false, Ionic.Zlib.CompressionLevel.None);
                File.Delete(Path.Combine(Utility.GetTempPath(), name + ".sin"));
            }

            return(true);
        }
예제 #15
0
        public static void AddExtraFlashable(BackgroundWorker worker, string filename)
        {
            Logger.WriteLog("Adding flashable zip: " + Path.GetFileName(filename));
            string fixedname = Path.GetFileName(filename).Replace(' ', '_');

            string cmd = "\n# " + fixedname + "\n" +
                         "if\n" +
                         "\tpackage_extract_file(\"" + fixedname + "\", \"/tmp/" + fixedname + "\") == \"t\"\n" +
                         "then\n" +
                         "\trun_program(\"/tmp/busybox\", \"mkdir\", \"/tmp/" + Path.GetFileNameWithoutExtension(fixedname) + "_extracted" + "\");\n" +
                         "\trun_program(\"/tmp/busybox\", \"unzip\", \"-d\", \"/tmp/" + Path.GetFileNameWithoutExtension(fixedname) + "_extracted" + "\", \"/tmp/" + fixedname + "\");\n" +
                         "\tset_perm(0, 0, 0755, \"/tmp/" + Path.GetFileNameWithoutExtension(fixedname) + "_extracted" + "/META-INF/com/google/android/update-binary\");\n" +
                         "\trun_program(\"/tmp/" + Path.GetFileNameWithoutExtension(fixedname) + "_extracted" + "/META-INF/com/google/android/update-binary\", file_getprop(\"/tmp/prfargs\", \"version\"), file_getprop(\"/tmp/prfargs\", \"outfile\"), \"/tmp/" + fixedname + "\");\n" +
                         "\tdelete_recursive(\"/tmp/" + Path.GetFileNameWithoutExtension(fixedname) + "_extracted" + "\");\n" +
                         "\tdelete(\"/tmp/" + fixedname + "\");\n" +
                         "endif;\n" +
                         "#InsertExtra\n";

            Utility.EditScript(worker, "#InsertExtra", cmd);
            Zipping.AddToZip(worker, Settings.destinationFile, filename, fixedname, false);
        }
예제 #16
0
        private static void AddLTALabel(BackgroundWorker worker, string ftffile)
        {
            string ltalname = Zipping.ZipGetFullname(ftffile, "elabel*.sin");

            if (string.IsNullOrEmpty(ltalname))
            {
                Logger.WriteLog("   Error: Could not find LTALabel in FTF");
                return;
            }

            if (PartitionInfo.ScriptMode == PartitionInfo.Mode.Sinflash)
            {
                if (ExtractAndAddSin(worker, Path.GetFileNameWithoutExtension(ltalname), ftffile, "ltalabel"))
                {
                    AddSinToConfig(worker, "ltalabel");
                }
            }
            else
            {
                ExtractAndAdd(worker, Path.GetFileNameWithoutExtension(ltalname), ".ext4", ftffile, "ltalabel");
            }
        }
예제 #17
0
파일: Job.cs 프로젝트: vaginessa/PRFCreator
        private static void UnpackSystem(BackgroundWorker worker)
        {
            SetJobNum(++JobNum);
            Logger.WriteLog("Extracting system.sin from " + System.IO.Path.GetFileName(Form1.form.ftf_textbox.Text));
            if (!Zipping.UnzipFile(worker, Form1.form.ftf_textbox.Text, "system.sin", string.Empty, Utility.GetTempPath()))
            {
                worker.CancelAsync();
                return;
            }

            byte[] UUID = PartitionInfo.ReadSinUUID(Path.Combine(Utility.GetTempPath(), "system.sin"));
            //PartitionInfo.ScriptMode = (UUID != null) ? PartitionInfo.Mode.LegacyUUID : PartitionInfo.Mode.Legacy;
            if (!Form1.form.options_checklist.CheckedItems.Contains("Legacy mode"))
            {
                PartitionInfo.ScriptMode = PartitionInfo.Mode.Sinflash;
            }
            else
            {
                PartitionInfo.ScriptMode = (UUID != null) ? PartitionInfo.Mode.LegacyUUID : PartitionInfo.Mode.Legacy;
            }
            Utility.ScriptSetUUID(worker, "system", UUID);
        }