Beispiel #1
0
 private void Read_SFO_Load(object sender, EventArgs e)
 {
     try
     {
         if (Directory.Exists(pkgpath + @"\C00\"))
         {
             PARAM_SFO para = new PARAM_SFO(pkgpath + @"\C00\PARAM.SFO");
             backgroundWorker1.RunWorkerAsync();
             textBox1.Text = para.TitleID;
             textBox2.Text = para.Title;
             textBox3.Text = para.DataType.ToString();
             textBox4.Text = para.ContentID;
             if (textBox4.Text != "")
             {
                 lblEdat.Text = "Edat Enabled";
             }
             this.Text += " : " + para.Title.Replace("???", "-");
         }
         else
         {
             PARAM_SFO para = new PARAM_SFO(pkgpath + @"\PARAM.SFO");
             textBox1.Text = para.TitleID;
             textBox2.Text = para.Title.Replace("???", "(TM)");
             textBox3.Text = para.DataType.ToString();
             textBox4.Text = para.ContentID;
             this.Text    += " : " + para.Title.Replace("???", "-");
             if (textBox4.Text != "")
             {
                 lblEdat.Text = "Edat Enabled";
                 backgroundWorker1.RunWorkerAsync();
                 return;
             }
             backgroundWorker1.RunWorkerAsync();
             textBox4.Visible = false;
             label4.Visible   = false;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #2
0
        private void btnPKG_Click(object sender, EventArgs e)
        {
            #region << PeXploit PKG(s) >>
            if (radioButton2.Checked == true) //Package Install
            {
                openFileDialog2.Title = "Select PS3 PKG File";
                openFileDialog2.Filter = "PS3 PKG Files|*.pkg";
                openFileDialog2.InitialDirectory = System.Environment.SpecialFolder.MyComputer.ToString();
                if (openFileDialog2.ShowDialog() == DialogResult.OK)
                {
                    txtPKG.Text = openFileDialog2.FileName.ToString();
                    FileInfo ini = new FileInfo(txtPKG.Text);
                    pkgcount++;
                    string ReadPKGFileName = this.ReadPKGFile(txtPKG.Text,ini);
                    radioButton1.Enabled = false;
                    radioButton2.Enabled = false;
                    radioButton3.Enabled = false;
                    pkglist.Add(new DirectoryInfo(txtPKG.Text).FullName);//add the pkg to a list so we can do batch install still working out the kinks
                    packagelist.Items.Add(new FileInfo(txtPKG.Text).Name);
                    pkgcopyworker.RunWorkerAsync();
                }
            }
            #endregion << PeXploit PKG(s) >>

            #region << Bubble Install Method >>
            else if (radioButton1.Checked == true) // Bubble INstall Method
            {
                openFileDialog2.Title = "Select PS3 PKG File";
                openFileDialog2.Filter = "PS3 PKG Files|*.pkg";
                openFileDialog2.InitialDirectory = System.Environment.SpecialFolder.MyComputer.ToString();
                if (openFileDialog2.ShowDialog() == DialogResult.OK)
                {
                    txtPKG.Text = openFileDialog2.FileName.ToString();
                    FileInfo ini = new FileInfo(txtPKG.Text);
                    pkgcount++;
                    radioButton1.Enabled = false;
                    radioButton2.Enabled = false;
                    radioButton3.Enabled = false;
                    string decryptedPKGFileName = this.ReadPKGFile(txtPKG.Text, ini);
                    if ((decryptedPKGFileName != null) && (decryptedPKGFileName != string.Empty))
                    {
                        string str = null;
                        str = new pkg2sfo().DecryptPKGFile(decryptedPKGFileName);
                        if (Directory.Exists(Application.StartupPath + "\\edats"))
                        {
                            Directory.Delete(Application.StartupPath + "\\edats", true);
                        }
                    }
                    if (lblPackageType.Text != "Retail Package")
                    {
                        MessageBox.Show("Bubble Install Only Supports Retail C00 Packages");
                        return;
                    }
                    pkglist.Add(new DirectoryInfo(txtPKG.Text).FullName);//add the pkg to a list so we can do batch install still working out the kinks
                    packagelist.Items.Add(new FileInfo(txtPKG.Text).Name);
                    pkgcopyworker.RunWorkerAsync();
                }

            }
            #endregion << Bubble Install Method >>

            #region << PKG_View Extracted >>
            else if (radioButton3.Checked == true)
            {
                //open the browser to get the folder
                FolderBrowserDialog theDialog = new FolderBrowserDialog();
                theDialog.RootFolder = System.Environment.SpecialFolder.MyComputer;
                if (theDialog.ShowDialog() == DialogResult.OK)
                {
                    SFO_link.Visible = true;
                    pictureBox1.Visible = true;
                    radioButton1.Enabled = false;
                    radioButton2.Enabled = false;
                    radioButton3.Enabled = false;
                    try
                    {
                        this.Text = "PeXploit";
                        txtPKG.Text = theDialog.SelectedPath.ToString();
                        //Adding PKG(s) to the list
                        pkgcount++;
                        pkglist.Add(new DirectoryInfo(txtPKG.Text).FullName);//add the pkg to a list so we can do batch install still working out the kinks
                        packagelist.Items.Add(new FileInfo(txtPKG.Text).Name);
                        //Log it
                        log(new DirectoryInfo(txtPKG.Text).Name + " Added To List");
                        if (Directory.Exists(txtPKG.Text + @"\C00\"))
                        {
                            PARAM_SFO para = new PARAM_SFO(txtPKG.Text + @"\C00\PARAM.SFO");
                            pictureBox1.ImageLocation = theDialog.SelectedPath.ToString() + @"\C00\ICON0.PNG";
                            try
                            {
                                var file = File.ReadAllBytes(theDialog.SelectedPath.ToString() + @"\C00\PIC1.PNG");

                                pictureBox1.BackgroundImage = getImageFromBytes(file);
                            }
                            catch (Exception ee)
                            {

                            }
                            txtTitle.Text += para.TitleID;
                            txtDATA.Text += para.DataType;
                            this.Text += " : " + para.Title.Replace("???", "-");
                        }
                        else
                        {
                            PARAM_SFO para = new PARAM_SFO(txtPKG.Text + @"\PARAM.SFO");
                            pictureBox1.ImageLocation = theDialog.SelectedPath.ToString() + @"\ICON0.PNG";
                            try
                            {

                                var file = File.ReadAllBytes(theDialog.SelectedPath.ToString() + @"\PIC1.PNG");

                                pictureBox1.BackgroundImage = getImageFromBytes(file);
                            }
                            catch (Exception ee)
                            {

                            }
                            txtTitle.Text += para.TitleID;
                            txtDATA.Text += para.DataType;
                            this.Text += " : " + para.Title.Replace("???", "-");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("The Incorect PKG File Was Selected \n\rPKG Names Usally Starts With BLES,BLUS,NPEA\n\rA More Spesific Error Can Be Found Within The Errorlog", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        if (File.Exists("errorlog.txt"))
                            File.Delete("errorLog.txt");
                        System.IO.File.WriteAllText(Application.StartupPath + "\\errorlog.txt", ex.ToString());
                    }
                }
            }
            #endregion << PKG_View Extracted >>
        }
Beispiel #3
0
        private void pkginstallworker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {

                #region << Bubble Install >>
                if (radioButton1.Checked == true) //bubbel install mode via ps3 Only C00 games
                {

                    #region << Foreach the games selected >>
                    foreach (string line in pkglist)
                    {
                        FileInfo ini = new FileInfo(line);
                        Tracker.Invoke(new Action(() => log("Creating Bubbel Install " + ini.Name + " And Adding To Environment")));//invoke a list box element
                        string decryptedPKGFileName = this.ReadPKGFile(line, ini);
                        if ((decryptedPKGFileName != null) && (decryptedPKGFileName != string.Empty))
                        {
                            File.Copy(line, Application.StartupPath + "\\" + ini.Name, true);
                            CreatePDBFiles(ini.Name);
                        }
                    }
                    #endregion << Foreach the games selected >>
                    Tracker.Invoke(new Action(() => log("All .pkg(s) Ready For Bubbel Install")));
                    Tracker.Invoke(new Action(() => log("Copying important backup data to working directory...This May Take Some Time")));
                    Tracker.Invoke(new Action(() => log("Cleaning Up Files If Any Are Found")));
                    string exdata = Application.StartupPath + @"\\exdata\\dev_hdd0\\home\\" + usernum + "\\exdata"; //usernumber and exdata directory
                    #region //Step 3 - Settup Directories so we can add all the info needed well anything u want really

                    Tracker.Invoke(new Action(() => log("Setting up directories..")));
                    Tracker.Invoke(new Action(() => log("Creating Custom Environment..")));

                    string dir = Application.StartupPath + "\\CustomEnvoirment"; //start building the path could propebly do it like below

                    string xDPxdir = Application.StartupPath + "\\CustomEnvoirment\\dev_hdd0\\game\\XDPX00008"; //dont know why sometimes gives a corrupt data on the xmb ? but makes a nice icon in game utility

                    string mms = Application.StartupPath + "\\CustomEnvoirment"; //build for recovery rebuild but started to use it for more than just the recovery rebuild

                    string restore = Application.StartupPath + "\\db.err"; //if u know code ull see what this does later
                    #endregion
                    FileInfo fi = new FileInfo(txtBack.Text); //info from the backup folder
                    string dirPath = fi.Directory.FullName.Replace("\\", "/"); //Ensure a working directory
                    #region //Build The Directory
                    if (!Directory.Exists(dir))
                        Directory.CreateDirectory(dir);
                    dir += "\\dev_hdd0";
                    if (!Directory.Exists(dir))
                        Directory.CreateDirectory(dir);
                    dir += "\\game";
                    if (!Directory.Exists(dir))
                        Directory.CreateDirectory(dir);

                    if (!Directory.Exists(mms))
                        Directory.CreateDirectory(mms);
                    mms += "\\dev_hdd0";
                    if (!Directory.Exists(mms))
                        Directory.CreateDirectory(mms);
                    mms += "\\mms";
                    if (!Directory.Exists(mms))
                        Directory.CreateDirectory(mms);
                    #endregion
                    //Cleanup Could Have Been Done Another Way i Guess But I Wanted To Ensure That This Part is NOOBproof(or Atleast Somewhat)
                    #region << Archive Handeling - Deleting >>

                    #region //Check And Delete archive.dat if it exists

                    #region << Archive 1>>
                    if (File.Exists(Application.StartupPath + "\\archive.dat"))
                        File.Delete(Application.StartupPath + "\\archive.dat");
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_0" + i + ".dat"))
                            File.Delete(Application.StartupPath + "\\archive_0" + i + ".dat");
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_" + i + ".dat"))
                            File.Delete(Application.StartupPath + "\\archive_" + i + ".dat");
                    }
                    #endregion << Archive 1>>
                    #region << Archive 2 >>
                    if (File.Exists(Application.StartupPath + "\\archive2.dat"))
                        File.Delete(Application.StartupPath + "\\archive2.dat");
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive2_0" + i + ".dat"))
                            File.Delete(Application.StartupPath + "\\archive2_0" + i + ".dat");
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive2_" + i + ".dat"))
                            File.Delete(Application.StartupPath + "\\archive2_" + i + ".dat");
                    }
                    #endregion << Archive 2 >>

                    #endregion //Check And Delete archive.dat if it exists

                    #region //start deleting backups if there are any

                    #region << Archive 1_00 >>
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_0" + i + ".bak"))
                            File.Delete(Application.StartupPath + "\\archive_0" + i + ".bak");
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_" + i + ".bak"))
                            File.Delete(Application.StartupPath + "\\archive_" + i + ".bak");
                    }

                    #endregion << Archive 1_00 >>

                    #region << Archive 2_00 >>
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive2_0" + i + ".bak"))
                            File.Delete(Application.StartupPath + "\\archive2_0" + i + ".bak");
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive2_" + i + ".bak"))
                            File.Delete(Application.StartupPath + "\\archive2_" + i + ".bak");
                    }

                    #endregion << Archive 2_00 >>

                    #region //archive.bak

                    #region << Archive 1 >>
                    if (File.Exists(Application.StartupPath + "\\archive.bak"))
                        File.Delete(Application.StartupPath + "\\archive.bak");
                    #endregion << Archive 1 >>

                    #region << Archive 2 >>
                    if (File.Exists(Application.StartupPath + "\\archive2.bak"))
                        File.Delete(Application.StartupPath + "\\archive2.bak");
                    #endregion << Archive 2 >>

                    #endregion

                    #endregion//end backups archive_00

                    #region //tmp file check

                    #region << Archive 1_00 >>
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_0" + i + ".tmp"))
                            File.Delete(Application.StartupPath + "\\archive_0" + i + ".tmp");
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_" + i + ".tmp"))
                            File.Delete(Application.StartupPath + "\\archive_" + i + ".tmp");
                    }

                    #endregion << Archive1_00 >>

                    #region << Archive 2_00 >>
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive2_0" + i + ".tmp"))
                            File.Delete(Application.StartupPath + "\\archive2_0" + i + ".tmp");
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive2_" + i + ".tmp"))
                            File.Delete(Application.StartupPath + "\\archive2_" + i + ".tmp");
                    }

                    #endregion << Archive 2_00 >>

                    #endregion

                    #endregion << Archive Handeling - Deleting >>

                    #region << Archive Handeling - Copying >>
                    Tracker.Invoke(new Action(() => log("Copying archive.dat ....")));
                    File.Copy(dirPath + "/archive.dat", Application.StartupPath + "\\archive.dat");
                    #region //copy archive.dat
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(dirPath + "/archive_0" + i + ".dat"))
                        {
                            Tracker.Invoke(new Action(() => log("Copying archive_0" + i + ".dat ....")));
                            File.Copy(dirPath + "/archive_0" + i + ".dat", Application.StartupPath + "\\archive_0" + i + ".dat");
                        }
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(dirPath + "/archive_" + i + ".dat"))
                        {
                            Tracker.Invoke(new Action(() => log("Copying archive_" + i + ".dat ....")));
                            File.Copy(dirPath + "/archive_" + i + ".dat", Application.StartupPath + "\\archive_" + i + ".dat");
                        }
                    }

                    #endregion

                    #endregion << Archive Handeling - Copying >>
                    Tracker.Invoke(new Action(() => log("=======All Archives Coppied=========")));
                    Tracker.Invoke(new Action(() => log("Adding Files To Environment ....")));
                    #region Batch Install edats
                    scan_files();
                    IEnumerable<string> enumerable;
                    string edatsf = Application.StartupPath + @"\edats\";
                    try
                    {
                        enumerable = Directory.EnumerateFiles(edatsf, "*.edat", SearchOption.AllDirectories);
                        foreach (string str4 in enumerable)
                        {
                            FileInfo edatname = new FileInfo(str4);
                            if (!Directory.Exists(exdata))
                                Directory.CreateDirectory(exdata);
                            File.Move(str4, exdata + @"\\" + edatname.Name);
                        }
                    }
                    catch
                    {
                    }
                    #endregion
                    #region //custom edats
                    if (txtEdat.Text != "")
                    {
                        foreach (string line in edats)
                        {
                            Tracker.Invoke(new Action(() => log("Adding " + System.IO.Path.GetFileName(line))));
                            if (!Directory.Exists(exdata))
                                Directory.CreateDirectory(exdata);
                            File.Copy(line, exdata + "\\" + System.IO.Path.GetFileName(line), true);
                        }
                        Tracker.Invoke(new Action(() => log("========All Edat(s) Added=========")));
                    }
                    #endregion
                    File.Copy(restore, mms + "\\db.err");
                    string vsh = Application.StartupPath + "\\CustomEnvoirment\\dev_hdd0\\vsh\\game_pkg";
                    if (!Directory.Exists(vsh))
                    {
                        Directory.CreateDirectory(vsh);
                    }
                    DirectoryCopy(Application.StartupPath + @"\\game_pkg", vsh + "\\", true);
                    if (Directory.Exists(Application.StartupPath + "\\exdata"))
                    {
                        DirectoryCopy(Application.StartupPath + "\\exdata", Application.StartupPath + "\\CustomEnvoirment\\", true);
                    }

                    #region //Check for any existing duplicates and delete them from the backup
                    Tracker.Invoke(new Action(() => log("Deleting any potential duplicate files in backup...")));
                    string com;
                    string ret;
                    foreach (string info in pkglist)
                    {
                        FileInfo PKGNAme = new FileInfo(info);
                        com = "ps3xport.exe ExtractPSID ./ psid.bin SetPSID psid.bin DeletePath ./ /dev_hdd0/game/" + PKGNAme.Name + "/";
                        ret = CMD(com);
                    }
                    File.Delete("out.txt");
                    Tracker.Invoke(new Action(() => log("======Dublicates have been cleared=======")));
                    #endregion
                    #region//Install Custom PKG Files
                    this.notifyIcon1.ShowBalloonTip(0x7d0, "PeXploit", "Installing Pkg(s)", ToolTipIcon.Info);
                    Tracker.Invoke(new Action(() => log("Installing PKG(s) files...")));
                    Tracker.Invoke(new Action(() => log("This May Take A While ...")));
                    com = "ps3xport.exe ExtractPSID ./ psid.bin SetPSID psid.bin Add ./ CustomEnvoirment";
                    ret = CMD(com);
                    while (File.Exists(Application.StartupPath + "\\archive_00.tmp"))
                    {
                        Tracker.Invoke(new Action(() => log("Busy.......")));
                        Thread.Sleep(1000);
                    }
                    Tracker.Invoke(new Action(() => log("================PKG(s) Installed============= ")));
                    File.Delete("out.txt");
                    #endregion
                    #region//Copy backup files back to actual backup

                    Tracker.Invoke(new Action(() => log("Moving backup files from working directory...")));
                    //archive
                    if (File.Exists(dirPath + "/archive.dat"))
                    {
                        if (backupdata == true)
                        {
                            if (File.Exists(dirPath + "/archive.dat.bak"))
                                File.Delete(dirPath + "/archive.dat.bak");
                            Tracker.Invoke(new Action(() => log("Checking archive.dat")));
                            File.Copy(dirPath + "/archive.dat", dirPath + "/archive.dat.bak", true);
                        }
                        File.Delete(dirPath + "/archive.dat");
                    }
                    //archive0
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(dirPath + "/archive_0" + i + ".dat"))
                        {
                            if (backupdata == true)
                            {
                                if (File.Exists(dirPath + "/archive_0" + i + ".dat.bak"))
                                    File.Delete(dirPath + "/archive_0" + i + ".dat.bak");
                                Tracker.Invoke(new Action(() => log("Checking Archive_0" + i + ".dat")));
                                File.Copy(dirPath + "/archive_0" + i + ".dat", dirPath + "/archive_0" + i + ".dat.bak", true);
                            }
                            File.Delete(dirPath + "/archive_0" + i + ".dat");
                        }
                    }
                    //archive00
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(dirPath + "/archive_" + i + ".dat"))
                        {
                            if (backupdata == true)
                            {
                                if (File.Exists(dirPath + "/archive_" + i + ".dat.bak"))
                                    File.Delete(dirPath + "/archive_" + i + ".dat.bak");
                                Tracker.Invoke(new Action(() => log("Checking Archive_" + i + ".dat")));
                                File.Copy(dirPath + "/archive_" + i + ".dat", dirPath + "/archive_" + i + ".dat.bak", true);
                            }
                            File.Delete(dirPath + "/archive_" + i + ".dat");
                        }
                    }
                    if (backupdata == true)
                        Tracker.Invoke(new Action(() => log("========Archive Passed Checks========")));
                    #endregion
                    #region //copy archive
                    Tracker.Invoke(new Action(() => log("Copying Archive")));
                    File.Copy(Application.StartupPath + "\\archive.dat", dirPath + "/archive.dat");
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_0" + i + ".dat"))
                        {
                            Tracker.Invoke(new Action(() => log("Copying Archive_0" + i + "")));
                            File.Copy(Application.StartupPath + "\\archive_0" + i + ".dat", dirPath + "/archive_0" + i + ".dat");
                        }
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_" + i + ".dat"))
                        {
                            Tracker.Invoke(new Action(() => log("Copying Archive_" + i + "")));
                            File.Copy(Application.StartupPath + "\\archive_" + i + ".dat", dirPath + "/archive_" + i + ".dat");
                        }
                    }
                    Tracker.Invoke(new Action(() => log("=======Archive Completed ======")));
                    #endregion

                    #region//Step 9 - Remove files from working directory
                    Tracker.Invoke(new Action(() => log("Deleting final files from working directory...")));
                    if (File.Exists("psid.bin"))
                        File.Delete("psid.bin");
                    if (Directory.Exists(Application.StartupPath + "\\exdata"))
                        Directory.Delete(Application.StartupPath + "\\exdata", true);
                    if (Directory.Exists(Application.StartupPath + "\\mms"))
                        Directory.Delete(Application.StartupPath + "\\mms", true);
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_0" + i + ".tmp"))
                            File.Delete(Application.StartupPath + "\\archive_0" + i + ".tmp");
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_" + i + ".tmp"))
                            File.Delete(Application.StartupPath + "\\archive_" + i + ".tmp");
                    }
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive2_0" + i + ".tmp"))
                            File.Delete(Application.StartupPath + "\\archive2_0" + i + ".tmp");
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive2_" + i + ".tmp"))
                            File.Delete(Application.StartupPath + "\\archive2_" + i + ".tmp");
                    }
                    if (Directory.Exists(Application.StartupPath + "\\CustomEnvoirment"))
                        Directory.Delete(Application.StartupPath + "\\CustomEnvoirment", true);
                    try
                    {
                        if (Directory.Exists(Application.StartupPath + @"\\game_pkg"))
                            Directory.Delete(Application.StartupPath + @"\\game_pkg", true);
                    }
                    catch { }

                    string path = Application.StartupPath;
                    try
                    {
                        enumerable = Directory.EnumerateFiles(path, "*.DEC", SearchOption.AllDirectories);
                        foreach (string str4 in enumerable)
                        {
                            FileInfo decdelete = new FileInfo(str4);
                            Tracker.Invoke(new Action(() => log("Deleting " + decdelete.Name)));
                            File.Delete(str4);
                        }
                    }
                    catch
                    {
                    }
                    try
                    {
                        enumerable = Directory.EnumerateFiles(path, "*.pkg", SearchOption.AllDirectories);
                        foreach (string str4 in enumerable)
                        {
                            FileInfo pkgdelete = new FileInfo(str4);
                            Tracker.Invoke(new Action(() => log("Deleting " + pkgdelete.Name)));
                            File.Delete(str4);
                        }
                    }
                    catch
                    {
                    }
                    try
                    {
                        enumerable = Directory.EnumerateFiles(path, "*.bak", SearchOption.AllDirectories);
                        foreach (string str4 in enumerable)
                        {
                            FileInfo pkgdelete = new FileInfo(str4);
                            Tracker.Invoke(new Action(() => log("Deleting " + pkgdelete.Name)));
                            File.Delete(str4);
                        }
                    }
                    catch
                    {
                    }
                    this.notifyIcon1.ShowBalloonTip(0x7d, "PeXploit", "PKG(s) Injected", ToolTipIcon.Info);
                    SystemSounds.Beep.Play();
                    MessageBox.Show("Complete.\r\nBackup saved to " + dirPath + "\n Restore Your Backup");
                    progressBar1.Invoke(new Action(() => progressBar1.Visible = false));
                }
                    #endregion

                #endregion << Bubble Install >>

                #region << PeXploit PKG(s) >>
                else if (radioButton2.Checked == true) //PeXploit Decrypt
                {

                    foreach (string line in pkglist)
                    {
                        FileInfo ini = new FileInfo(line);
                        Tracker.Invoke(new Action(() => log("Decrypted " + ini.Name + " And Adding To Environment")));
                        string decryptedPKGFileName = this.DecryptPKGFile(line, ini);
                        if ((decryptedPKGFileName != null) && (decryptedPKGFileName != string.Empty))
                        {
                            // File.Copy(line, Application.StartupPath + "\\" + ini.Name, true);
                            this.ExtractFiles(decryptedPKGFileName, line, ini);
                        }
                    }
                    Tracker.Invoke(new Action(() => log("All .pkg(s) Decrypted")));
                    Tracker.Invoke(new Action(() => log("Copying important backup data to working directory...This May Take Some Time")));
                    Tracker.Invoke(new Action(() => log("Cleaning Up Files If Any Are Found")));
                    string exdata = Application.StartupPath + @"\\exdata\\dev_hdd0\\home\\" + usernum + "\\exdata"; //usernumber and exdata directory
                    #region //Step 3 - Settup Directories so we can add all the info needed well anything u want really

                    Tracker.Invoke(new Action(() => log("Setting up directories..")));
                    Tracker.Invoke(new Action(() => log("Creating Custom Environment..")));

                    string dir = Application.StartupPath + "\\CustomEnvoirment"; //start building the path could propebly do it like below

                    string xDPxdir = Application.StartupPath + "\\CustomEnvoirment\\dev_hdd0\\game\\XDPX00008"; //dont know why sometimes gives a corrupt data on the xmb ? but makes a nice icon in game utility

                    string mms = Application.StartupPath + "\\CustomEnvoirment"; //build for recovery rebuild but started to use it for more than just the recovery rebuild

                    string restore = Application.StartupPath + "\\db.err"; //if u know code ull see what this does later
                    #endregion
                    FileInfo fi = new FileInfo(txtBack.Text); //info from the backup folder
                    string dirPath = fi.Directory.FullName.Replace("\\", "/"); //Ensure a working directory
                    #region //Build The Directory
                    if (!Directory.Exists(dir))
                        Directory.CreateDirectory(dir);
                    dir += "\\dev_hdd0";
                    if (!Directory.Exists(dir))
                        Directory.CreateDirectory(dir);
                    dir += "\\game";
                    if (!Directory.Exists(dir))
                        Directory.CreateDirectory(dir);

                    if (!Directory.Exists(xDPxdir))
                        Directory.CreateDirectory(xDPxdir);
                    if (!Directory.Exists(mms))
                        Directory.CreateDirectory(mms);
                    mms += "\\dev_hdd0";
                    if (!Directory.Exists(mms))
                        Directory.CreateDirectory(mms);
                    mms += "\\mms";
                    if (!Directory.Exists(mms))
                        Directory.CreateDirectory(mms);
                    #endregion
                    //Cleanup Could Have Been Done Another Way i Guess But I Wanted To Ensure That This Part is fullproof
                    //archive 15 ? 1arch = 4gb 14 = 60gb ?
                    //so if i add 30arhives means 120 gb x2 for archive and archive2 = 320gb standard ps3 hdd size
                    //soo if archive 99 = 4gb each == 396gb *2 for archive2 = 792GB +8GBreally why would u need more ???
                    #region //Check And Delete archive.dat if it exists
                    if (File.Exists(Application.StartupPath + "\\archive.dat"))
                        File.Delete(Application.StartupPath + "\\archive.dat");
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_0" + i + ".dat"))
                            File.Delete(Application.StartupPath + "\\archive_0" + i + ".dat");
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_" + i + ".dat"))
                            File.Delete(Application.StartupPath + "\\archive_" + i + ".dat");
                    }

                    #endregion//end for 30 archives
                    #region //start deleting backups if there are any

                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_0" + i + ".bak"))
                            File.Delete(Application.StartupPath + "\\archive_0" + i + ".bak");
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_" + i + ".bak"))
                            File.Delete(Application.StartupPath + "\\archive_" + i + ".bak");
                    }

                    #endregion//end backups archive_00
                    #region //archive.bak

                    if (File.Exists(Application.StartupPath + "\\archive.bak"))
                        File.Delete(Application.StartupPath + "\\archive.bak");

                    #endregion
                    #region //tmp file check
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_0" + i + ".tmp"))
                            File.Delete(Application.StartupPath + "\\archive_0" + i + ".tmp");
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_" + i + ".tmp"))
                            File.Delete(Application.StartupPath + "\\archive_" + i + ".tmp");
                    }
                    #endregion

                    Tracker.Invoke(new Action(() => log("Copying archive.dat ....")));
                    File.Copy(dirPath + "/archive.dat", Application.StartupPath + "\\archive.dat");
                    #region //copy archive.dat
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(dirPath + "/archive_0" + i + ".dat"))
                        {
                            Tracker.Invoke(new Action(() => log("Copying archive_0" + i + ".dat ....")));
                            File.Copy(dirPath + "/archive_0" + i + ".dat", Application.StartupPath + "\\archive_0" + i + ".dat");
                        }
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(dirPath + "/archive_" + i + ".dat"))
                        {
                            Tracker.Invoke(new Action(() => log("Copying archive_" + i + ".dat ....")));
                            File.Copy(dirPath + "/archive_" + i + ".dat", Application.StartupPath + "\\archive_" + i + ".dat");
                        }
                    }

                    #endregion
                    Tracker.Invoke(new Action(() => log("=======All Archives Coppied=========")));
                    Tracker.Invoke(new Action(() => log("Adding Files To Environment ....")));
                    #region Batch Install edats
                    scan_files();
                    IEnumerable<string> enumerable;
                    string edatsf = Application.StartupPath + @"\edats\";
                    try
                    {
                        enumerable = Directory.EnumerateFiles(edatsf, "*.edat", SearchOption.AllDirectories);
                        foreach (string str4 in enumerable)
                        {
                            FileInfo edatname = new FileInfo(str4);
                            if (!Directory.Exists(exdata))
                                Directory.CreateDirectory(exdata);
                            File.Move(str4, exdata + @"\\" + edatname.Name);
                        }
                    }
                    catch
                    {
                    }
                    #endregion
                    #region //custom edats
                    if (txtEdat.Text != "")
                    {
                        foreach (string line in edats)
                        {
                            Tracker.Invoke(new Action(() => log("Adding " + System.IO.Path.GetFileName(line))));
                            if (!Directory.Exists(exdata))
                                Directory.CreateDirectory(exdata);
                            File.Copy(line, exdata + "\\" + System.IO.Path.GetFileName(line), true);
                        }
                        Tracker.Invoke(new Action(() => log("========All Edat(s) Added=========")));
                    }
                    #endregion
                    File.Copy(restore, mms + "\\db.err");
                    if (Directory.Exists(Application.StartupPath + "\\exdata"))
                    {
                        DirectoryCopy(Application.StartupPath + "\\exdata", Application.StartupPath + "\\CustomEnvoirment\\", true);
                    }

                    #region //Check for any existing duplicates and delete them from the backup
                    Tracker.Invoke(new Action(() => log("Deleting any potential duplicate files in backup...")));
                    string com;
                    string ret;
                    foreach (string info in pkglist)
                    {
                        FileInfo PKGNAme = new FileInfo(info);
                        com = "ps3xport.exe ExtractPSID ./ psid.bin SetPSID psid.bin DeletePath ./ /dev_hdd0/game/" + PKGNAme.Name + "/";
                        ret = CMD(com);
                    }
                    File.Delete("out.txt");
                    Tracker.Invoke(new Action(() => log("======Dublicates have been cleared=======")));
                    #endregion
                    #region//Install Custom PKG Files
                    this.notifyIcon1.ShowBalloonTip(0x7d0, "PeXploit", "Installing Pkg(s)", ToolTipIcon.Info);
                    Tracker.Invoke(new Action(() => log("Installing PKG(s) files...")));
                    Tracker.Invoke(new Action(() => log("This May Take A While ...")));
                    com = "ps3xport.exe ExtractPSID ./ psid.bin SetPSID psid.bin Add ./ CustomEnvoirment";
                    ret = CMD(com);
                    while (File.Exists(Application.StartupPath + "\\archive_00.tmp"))
                    {
                        Tracker.Invoke(new Action(() => log("Busy.......")));
                        Thread.Sleep(1000);
                    }
                    Tracker.Invoke(new Action(() => log("================PKG(s) Installed============= ")));
                    File.Delete("out.txt");
                    #endregion
                    #region//Copy backup files back to actual backup

                    Tracker.Invoke(new Action(() => log("Moving backup files from working directory...")));
                    //archive
                    if (File.Exists(dirPath + "/archive.dat"))
                    {
                        if (backupdata == true)
                        {
                            if (File.Exists(dirPath + "/archive.dat.bak"))
                                File.Delete(dirPath + "/archive.dat.bak");
                            Tracker.Invoke(new Action(() => log("Checking archive.dat")));
                            File.Copy(dirPath + "/archive.dat", dirPath + "/archive.dat.bak", true);
                        }
                        File.Delete(dirPath + "/archive.dat");
                    }
                    //archive0
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(dirPath + "/archive_0" + i + ".dat"))
                        {
                            if (backupdata == true)
                            {
                                if (File.Exists(dirPath + "/archive_0" + i + ".dat.bak"))
                                    File.Delete(dirPath + "/archive_0" + i + ".dat.bak");
                                Tracker.Invoke(new Action(() => log("Checking Archive_0" + i + ".dat")));
                                File.Copy(dirPath + "/archive_0" + i + ".dat", dirPath + "/archive_0" + i + ".dat.bak", true);
                            }
                            File.Delete(dirPath + "/archive_0" + i + ".dat");
                        }
                    }
                    //archive00
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(dirPath + "/archive_" + i + ".dat"))
                        {
                            if (backupdata == true)
                            {
                                if (File.Exists(dirPath + "/archive_" + i + ".dat.bak"))
                                    File.Delete(dirPath + "/archive_" + i + ".dat.bak");
                                Tracker.Invoke(new Action(() => log("Checking Archive_" + i + ".dat")));
                                File.Copy(dirPath + "/archive_" + i + ".dat", dirPath + "/archive_" + i + ".dat.bak", true);
                            }
                            File.Delete(dirPath + "/archive_" + i + ".dat");
                        }
                    }
                    if (backupdata == true)
                        Tracker.Invoke(new Action(() => log("========Archive Passed Checks========")));
                    #endregion
                    #region //copy archive
                    Tracker.Invoke(new Action(() => log("Copying Archive")));
                    File.Copy(Application.StartupPath + "\\archive.dat", dirPath + "/archive.dat");
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_0" + i + ".dat"))
                        {
                            Tracker.Invoke(new Action(() => log("Copying Archive_0" + i + "")));
                            File.Copy(Application.StartupPath + "\\archive_0" + i + ".dat", dirPath + "/archive_0" + i + ".dat");
                        }
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_" + i + ".dat"))
                        {
                            Tracker.Invoke(new Action(() => log("Copying Archive_" + i + "")));
                            File.Copy(Application.StartupPath + "\\archive_" + i + ".dat", dirPath + "/archive_" + i + ".dat");
                        }
                    }
                    Tracker.Invoke(new Action(() => log("=======Archive Completed ======")));
                    #endregion

                    #region//Step 9 - Remove files from working directory
                    Tracker.Invoke(new Action(() => log("Deleting final files from working directory...")));
                    if (File.Exists("psid.bin"))
                        File.Delete("psid.bin");
                    if (Directory.Exists(Application.StartupPath + "\\exdata"))
                        Directory.Delete(Application.StartupPath + "\\exdata", true);
                    if (Directory.Exists(Application.StartupPath + "\\mms"))
                        Directory.Delete(Application.StartupPath + "\\mms", true);
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_0" + i + ".tmp"))
                            File.Delete(Application.StartupPath + "\\archive_0" + i + ".tmp");
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_" + i + ".tmp"))
                            File.Delete(Application.StartupPath + "\\archive_" + i + ".tmp");
                    }
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive2_0" + i + ".tmp"))
                            File.Delete(Application.StartupPath + "\\archive2_0" + i + ".tmp");
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive2_" + i + ".tmp"))
                            File.Delete(Application.StartupPath + "\\archive2_" + i + ".tmp");
                    }
                    if (Directory.Exists(Application.StartupPath + "\\CustomEnvoirment"))
                        Directory.Delete(Application.StartupPath + "\\CustomEnvoirment", true);
                    try
                    {
                        if (Directory.Exists(Application.StartupPath + @"\\game_pkg"))
                            Directory.Delete(Application.StartupPath + @"\\game_pkg", true);
                    }
                    catch { }

                    string path = Application.StartupPath;
                    try
                    {
                        enumerable = Directory.EnumerateFiles(path, "*.DEC", SearchOption.AllDirectories);
                        foreach (string str4 in enumerable)
                        {
                            FileInfo decdelete = new FileInfo(str4);
                            Tracker.Invoke(new Action(() => log("Deleting " + decdelete.Name)));
                            File.Delete(str4);
                        }
                    }
                    catch
                    {
                    }
                    try
                    {
                        enumerable = Directory.EnumerateFiles(path, "*.pkg", SearchOption.AllDirectories);
                        foreach (string str4 in enumerable)
                        {
                            FileInfo pkgdelete = new FileInfo(str4);
                            Tracker.Invoke(new Action(() => log("Deleting " + pkgdelete.Name)));
                            File.Delete(str4);
                        }
                    }
                    catch
                    {
                    }
                    try
                    {
                        enumerable = Directory.EnumerateFiles(path, "*.bak", SearchOption.AllDirectories);
                        foreach (string str4 in enumerable)
                        {
                            FileInfo pkgdelete = new FileInfo(str4);
                            Tracker.Invoke(new Action(() => log("Deleting " + pkgdelete.Name)));
                            File.Delete(str4);
                        }
                    }
                    catch
                    {
                    }
                    this.notifyIcon1.ShowBalloonTip(0x7d, "PeXploit", "PKG(s) Injected", ToolTipIcon.Info);
                    SystemSounds.Beep.Play();
                    MessageBox.Show("Complete.\r\nBackup saved to " + dirPath + "\n Restore Your Backup");
                    progressBar1.Invoke(new Action(() => progressBar1.Visible = false));
                }
                    #endregion

                #endregion << PeXploit PKG(s) >>

                #region << PKG_VIEW >>
                else if (radioButton3.Checked == true)//pkg_view extracted
                {
                    Tracker.Invoke(new Action(() => log("Copying important backup data to working directory...This May Take Some Time")));
                    Tracker.Invoke(new Action(() => log("Cleaning Up Files If Any Are Found")));
                    string exdata = Application.StartupPath + @"\\exdata\\dev_hdd0\\home\\" + usernum + "\\exdata"; //usernumber and exdata directory
                    #region //Step 3 - Settup Directories so we can add all the info needed well anything u want really

                    Tracker.Invoke(new Action(() => log("Setting up directories..")));
                    Tracker.Invoke(new Action(() => log("Creating Custom Environment..")));

                    string dir = Application.StartupPath + "\\CustomEnvoirment"; //start building the path could propebly do it like below

                    string xDPxdir = Application.StartupPath + "\\CustomEnvoirment\\dev_hdd0\\game\\XDPX00008"; //dont know why sometimes gives a corrupt data on the xmb ? but makes a nice icon in game utility

                    string mms = Application.StartupPath + "\\CustomEnvoirment"; //build for recovery rebuild but started to use it for more than just the recovery rebuild

                    string restore = Application.StartupPath + "\\db.err"; //if u know code ull see what this does later
                    #endregion
                    FileInfo fi = new FileInfo(txtBack.Text); //info from the backup folder
                    string dirPath = fi.Directory.FullName.Replace("\\", "/"); //Ensure a working directory
                    #region //Build The Directory
                    if (!Directory.Exists(dir))
                        Directory.CreateDirectory(dir);
                    dir += "\\dev_hdd0";
                    if (!Directory.Exists(dir))
                        Directory.CreateDirectory(dir);
                    dir += "\\game";
                    if (!Directory.Exists(dir))
                        Directory.CreateDirectory(dir);

                    if (!Directory.Exists(mms))
                        Directory.CreateDirectory(mms);
                    mms += "\\dev_hdd0";
                    if (!Directory.Exists(mms))
                        Directory.CreateDirectory(mms);
                    mms += "\\mms";
                    if (!Directory.Exists(mms))
                        Directory.CreateDirectory(mms);
                    #endregion
                    //Cleanup Could Have Been Done Another Way i Guess But I Wanted To Ensure That This Part is fullproof
                    //archive 15 ? 1arch = 4gb 14 = 60gb ?
                    //so if i add 30arhives means 120 gb x2 for archive and archive2 = 320gb standard ps3 hdd size
                    //soo if archive 99 = 4gb each == 396gb *2 for archive2 = 792GB +8GBreally why would u need more ???
                    #region //Check And Delete archive.dat if it exists
                    if (File.Exists(Application.StartupPath + "\\archive.dat"))
                        File.Delete(Application.StartupPath + "\\archive.dat");
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_0" + i + ".dat"))
                            File.Delete(Application.StartupPath + "\\archive_0" + i + ".dat");
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_" + i + ".dat"))
                            File.Delete(Application.StartupPath + "\\archive_" + i + ".dat");
                    }

                    #endregion//end for 30 archives
                    #region //start deleting backups if there are any

                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_0" + i + ".bak"))
                            File.Delete(Application.StartupPath + "\\archive_0" + i + ".bak");
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_" + i + ".bak"))
                            File.Delete(Application.StartupPath + "\\archive_" + i + ".bak");
                    }

                    #endregion//end backups archive_00
                    #region //archive.bak

                    if (File.Exists(Application.StartupPath + "\\archive.bak"))
                        File.Delete(Application.StartupPath + "\\archive.bak");

                    #endregion
                    #region //tmp file check
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_0" + i + ".tmp"))
                            File.Delete(Application.StartupPath + "\\archive_0" + i + ".tmp");
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_" + i + ".tmp"))
                            File.Delete(Application.StartupPath + "\\archive_" + i + ".tmp");
                    }
                    #endregion
                    #region//SFO Check
                    foreach (string pkglocation in pkglist)
                    {
                        Tracker.Invoke(new Action(() => log("Adding " + new DirectoryInfo(pkglocation).Name + " To PeXploit")));
                        PARAM_SFO para = new PARAM_SFO(pkglocation + "\\PARAM.SFO");
                        TitleID = para.TitleID;

                        //if (File.Exists(dir + "\\" + TitleID + "\\PARAM.SFO") == true)
                        //{
                        //    if (File.Exists(pkglocation + "\\PARAM.SFO") == true)
                        //    {
                        //        try
                        //        {
                        //            File.Copy(pkglocation + "\\PARAM.SFO", pkglocation + "\\PARAM.SFO.Bak");
                        //            File.Delete(pkglocation + "\\PARAM.SFO");
                        //        }
                        //        catch (Exception ex)
                        //        {

                        //        }
                        //    }
                        //}

                        DirectoryCopy(pkglocation, dir + "\\" + TitleID, true);
                    }
                    #endregion
                    #region //check for param.sfo c00
                    try
                    {
                        foreach (string pn in pkglist)
                        {
                            string dirktpkg = dir + "\\" + new DirectoryInfo(pn).Name;
                            if (File.Exists(dirktpkg + "\\C00\\PARAM.SFO"))
                            {
                                using (var fs = new FileStream(dirktpkg + "\\C00\\PARAM.SFO",
                                        FileMode.Open,
                                        FileAccess.ReadWrite))
                                {
                                    if (File.Exists(Application.StartupPath + "\\PARAM.SFO"))
                                        File.Delete(Application.StartupPath + "\\PARAM.SFO");
                                    File.Copy(dirktpkg + "\\C00\\PARAM.SFO", Application.StartupPath + "\\PARAM.SFO");
                                    Tracker.Invoke(new Action(() => log("Retrieving CONTENT ID ....")));
                                    PARAM_SFO para = new PARAM_SFO(Application.StartupPath + "\\PARAM.SFO");
                                    TitleID = para.ContentID;
                                    Tracker.Invoke(new Action(() => log("Converting " + para.TitleID + " To Full")));
                                    scan_files();
                                    File.Delete(Application.StartupPath + "\\PARAM.SFO");
                                    //string command = "edat-license.exe " + TitleID;
                                    //string retur = CMD(command);
                                    File.Delete(Application.StartupPath + "\\out.txt");
                                    if (!Directory.Exists(exdata))
                                        Directory.CreateDirectory(exdata);
                                    Tracker.Invoke(new Action(() => log("Conversion Complete And Adding To Enviroment")));
                                    try
                                    {
                                        DirectoryCopy(Application.StartupPath + "\\edats\\", exdata, true);
                                    }
                                    catch (Exception ex)
                                    {

                                    }
                                    Tracker.Invoke(new Action(() => log(".....")));

                                    DirectoryCopy(Application.StartupPath + "\\exdata", Application.StartupPath + "\\mms\\", true);
                                    if (File.Exists(Application.StartupPath + "\\" + TitleID))
                                        File.Delete(Application.StartupPath + "\\" + TitleID);
                                    //}
                                    File.Delete(Application.StartupPath + "\\out.txt");
                                    Tracker.Invoke(new Action(() => log("Done")));
                                }
                            }
                    #endregion
                            #region//Check non-c00
                            else if (File.Exists(dir + "\\" + new DirectoryInfo(pn).Name + "\\PARAM.SFO"))
                            {
                                using (var fs = new FileStream(dir + "\\PARAM.SFO",
                                        FileMode.Open,
                                        FileAccess.ReadWrite))
                                {
                                    //Copy The Param TO Main Directory TO Execute EDAT Creation
                                    File.Copy(dir + "\\PARAM.SFO", Application.StartupPath + "\\PARAM.SFO");
                                    //Invoke The Listbox
                                    Tracker.Invoke(new Action(() => log("Retrieving CONTENT ID ....")));

                                    //Read The SFO Thanks Jappi88
                                    PARAM_SFO para = new PARAM_SFO(Application.StartupPath + "\\PARAM.SFO");
                                    TitleID = para.ContentID;
                                    Tracker.Invoke(new Action(() => log("Converting " + para.TitleID + " To Full")));

                                    //Scan The Files TO Search For The Edat And Create am SFO Out Of That
                                    scan_files();

                                    //DELETE Non-Important Files
                                    if (File.Exists(Application.StartupPath + "\\PARAM.SFO"))
                                        File.Delete(Application.StartupPath + "\\PARAM.SFO");
                                    if (File.Exists(Application.StartupPath + "\\out.txt"))
                                        File.Delete(Application.StartupPath + "\\out.txt");
                                    //Check OR Create Directory
                                    if (!Directory.Exists(exdata))
                                        Directory.CreateDirectory(exdata);
                                    Tracker.Invoke(new Action(() => log("Conversion Completed And Adding To Enviroment")));

                                    //try And Catch Directory Copy
                                    try
                                    {
                                        DirectoryCopy(Application.StartupPath + "\\edats\\", exdata, true);
                                    }
                                    catch (Exception ex)
                                    {

                                    }
                                    Tracker.Invoke(new Action(() => log(".....")));
                                    DirectoryCopy(Application.StartupPath + "\\exdata", Application.StartupPath + "\\mms\\", true);
                                    //If Exists Delete The Old Method
                                    if (File.Exists(Application.StartupPath + "\\" + TitleID))
                                        File.Delete(Application.StartupPath + "\\" + TitleID);
                                    if (File.Exists(Application.StartupPath + "\\out.txt"))
                                        File.Delete(Application.StartupPath + "\\out.txt");
                                    Tracker.Invoke(new Action(() => log("Done")));
                                }

                            }
                        }
                    }
                    catch (Exception ex)
                    {

                    }
                            #endregion
                    Tracker.Invoke(new Action(() => log("Copying archive.dat ....")));
                    File.Copy(dirPath + "/archive.dat", Application.StartupPath + "\\archive.dat");
                    #region //copy archive.dat
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(dirPath + "/archive_0" + i + ".dat"))
                        {
                            Tracker.Invoke(new Action(() => log("Copying archive_0" + i + ".dat ....")));
                            File.Copy(dirPath + "/archive_0" + i + ".dat", Application.StartupPath + "\\archive_0" + i + ".dat");
                        }
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(dirPath + "/archive_" + i + ".dat"))
                        {
                            Tracker.Invoke(new Action(() => log("Copying archive_" + i + ".dat ....")));
                            File.Copy(dirPath + "/archive_" + i + ".dat", Application.StartupPath + "\\archive_" + i + ".dat");
                        }
                    }

                    #endregion
                    Tracker.Invoke(new Action(() => log("=======All Archives Coppied=========")));
                    Tracker.Invoke(new Action(() => log("Adding Files To Environment ....")));
                    #region Batch Install edats
                    scan_files();
                    IEnumerable<string> enumerable;
                    string edatsf = Application.StartupPath + @"\edats\";
                    try
                    {
                        enumerable = Directory.EnumerateFiles(edatsf, "*.edat", SearchOption.AllDirectories);
                        foreach (string str4 in enumerable)
                        {
                            FileInfo edatname = new FileInfo(str4);
                            if (!Directory.Exists(exdata))
                                Directory.CreateDirectory(exdata);
                            File.Move(str4, exdata + @"\\" + edatname.Name);
                        }
                    }
                    catch
                    {
                    }
                    #endregion
                    #region //custom edats
                    if (txtEdat.Text != "")
                    {
                        foreach (string line in edats)
                        {
                            Tracker.Invoke(new Action(() => log("Adding " + System.IO.Path.GetFileName(line))));
                            if (!Directory.Exists(exdata))
                                Directory.CreateDirectory(exdata);
                            File.Copy(line, exdata + "\\" + System.IO.Path.GetFileName(line), true);
                        }
                        Tracker.Invoke(new Action(() => log("========All Edat(s) Added=========")));
                    }
                    #endregion
                    File.Copy(restore, mms + "\\db.err");
                    if (Directory.Exists(Application.StartupPath + "\\exdata"))
                    {
                        DirectoryCopy(Application.StartupPath + "\\exdata", Application.StartupPath + "\\CustomEnvoirment\\", true);
                    }

                    #region //Check for any existing duplicates and delete them from the backup
                    Tracker.Invoke(new Action(() => log("Deleting any potential duplicate files in backup...")));
                    string com;
                    string ret;
                    foreach (string info in pkglist)
                    {
                        FileInfo PKGNAme = new FileInfo(info);
                        com = "ps3xport.exe ExtractPSID ./ psid.bin SetPSID psid.bin DeletePath ./ /dev_hdd0/game/" + PKGNAme.Name + "/";
                        ret = CMD(com);
                    }
                    File.Delete("out.txt");
                    Tracker.Invoke(new Action(() => log("======Dublicates have been cleared=======")));
                    #endregion
                    #region//Install Custom PKG Files
                    this.notifyIcon1.ShowBalloonTip(0x7d0, "PeXploit", "Installing Pkg(s)", ToolTipIcon.Info);
                    Tracker.Invoke(new Action(() => log("Installing PKG(s) files...")));
                    Tracker.Invoke(new Action(() => log("This May Take A While ...")));
                    com = "ps3xport.exe ExtractPSID ./ psid.bin SetPSID psid.bin Add ./ CustomEnvoirment";
                    ret = CMD(com);
                    while (File.Exists(Application.StartupPath + "\\archive_00.tmp"))
                    {
                        Tracker.Invoke(new Action(() => log("Busy.......")));
                        Thread.Sleep(1000);
                    }
                    Tracker.Invoke(new Action(() => log("================PKG(s) Installed============= ")));
                    File.Delete("out.txt");
                    #endregion
                    #region//Copy backup files back to actual backup

                    Tracker.Invoke(new Action(() => log("Moving backup files from working directory...")));
                    //archive
                    if (File.Exists(dirPath + "/archive.dat"))
                    {
                        if (backupdata == true)
                        {
                            if (File.Exists(dirPath + "/archive.dat.bak"))
                                File.Delete(dirPath + "/archive.dat.bak");
                            Tracker.Invoke(new Action(() => log("Checking archive.dat")));
                            File.Copy(dirPath + "/archive.dat", dirPath + "/archive.dat.bak", true);
                        }
                        File.Delete(dirPath + "/archive.dat");
                    }
                    //archive0
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(dirPath + "/archive_0" + i + ".dat"))
                        {
                            if (backupdata == true)
                            {
                                if (File.Exists(dirPath + "/archive_0" + i + ".dat.bak"))
                                    File.Delete(dirPath + "/archive_0" + i + ".dat.bak");
                                Tracker.Invoke(new Action(() => log("Checking Archive_0" + i + ".dat")));
                                File.Copy(dirPath + "/archive_0" + i + ".dat", dirPath + "/archive_0" + i + ".dat.bak", true);
                            }
                            File.Delete(dirPath + "/archive_0" + i + ".dat");
                        }
                    }
                    //archive00
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(dirPath + "/archive_" + i + ".dat"))
                        {
                            if (backupdata == true)
                            {
                                if (File.Exists(dirPath + "/archive_" + i + ".dat.bak"))
                                    File.Delete(dirPath + "/archive_" + i + ".dat.bak");
                                Tracker.Invoke(new Action(() => log("Checking Archive_" + i + ".dat")));
                                File.Copy(dirPath + "/archive_" + i + ".dat", dirPath + "/archive_" + i + ".dat.bak", true);
                            }
                            File.Delete(dirPath + "/archive_" + i + ".dat");
                        }
                    }
                    if (backupdata == true)
                        Tracker.Invoke(new Action(() => log("========Archive Passed Checks========")));
                    #endregion
                    #region //copy archive
                    Tracker.Invoke(new Action(() => log("Copying Archive")));
                    File.Copy(Application.StartupPath + "\\archive.dat", dirPath + "/archive.dat");
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_0" + i + ".dat"))
                        {
                            Tracker.Invoke(new Action(() => log("Copying Archive_0" + i + "")));
                            File.Copy(Application.StartupPath + "\\archive_0" + i + ".dat", dirPath + "/archive_0" + i + ".dat");
                        }
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_" + i + ".dat"))
                        {
                            Tracker.Invoke(new Action(() => log("Copying Archive_" + i + "")));
                            File.Copy(Application.StartupPath + "\\archive_" + i + ".dat", dirPath + "/archive_" + i + ".dat");
                        }
                    }
                    Tracker.Invoke(new Action(() => log("=======Archive Completed ======")));
                    #endregion
                    #region//Step 9 - Remove files from working directory
                    Tracker.Invoke(new Action(() => log("Deleting final files from working directory...")));
                    if (File.Exists("psid.bin"))
                        File.Delete("psid.bin");
                    if (Directory.Exists(Application.StartupPath + "\\exdata"))
                        Directory.Delete(Application.StartupPath + "\\exdata", true);
                    if (Directory.Exists(Application.StartupPath + "\\mms"))
                        Directory.Delete(Application.StartupPath + "\\mms", true);
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_0" + i + ".tmp"))
                            File.Delete(Application.StartupPath + "\\archive_0" + i + ".tmp");
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive_" + i + ".tmp"))
                            File.Delete(Application.StartupPath + "\\archive_" + i + ".tmp");
                    }
                    for (int i = 0; i <= 9; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive2_0" + i + ".tmp"))
                            File.Delete(Application.StartupPath + "\\archive2_0" + i + ".tmp");
                    }
                    for (int i = 10; i <= 99; i++)
                    {
                        if (File.Exists(Application.StartupPath + "\\archive2_" + i + ".tmp"))
                            File.Delete(Application.StartupPath + "\\archive2_" + i + ".tmp");
                    }
                    if (Directory.Exists(Application.StartupPath + "\\CustomEnvoirment"))
                        Directory.Delete(Application.StartupPath + "\\CustomEnvoirment", true);
                    try
                    {
                        if (Directory.Exists(Application.StartupPath + @"\\game_pkg"))
                            Directory.Delete(Application.StartupPath + @"\\game_pkg", true);
                    }
                    catch { }

                    string path = Application.StartupPath;
                    try
                    {
                        enumerable = Directory.EnumerateFiles(path, "*.DEC", SearchOption.AllDirectories);
                        foreach (string str4 in enumerable)
                        {
                            FileInfo decdelete = new FileInfo(str4);
                            Tracker.Invoke(new Action(() => log("Deleting " + decdelete.Name)));
                            File.Delete(str4);
                        }
                    }
                    catch
                    {
                    }
                    try
                    {
                        enumerable = Directory.EnumerateFiles(path, "*.pkg", SearchOption.AllDirectories);
                        foreach (string str4 in enumerable)
                        {
                            FileInfo pkgdelete = new FileInfo(str4);
                            Tracker.Invoke(new Action(() => log("Deleting " + pkgdelete.Name)));
                            File.Delete(str4);
                        }
                    }
                    catch
                    {
                    }
                    try
                    {
                        enumerable = Directory.EnumerateFiles(path, "*.bak", SearchOption.AllDirectories);
                        foreach (string str4 in enumerable)
                        {
                            FileInfo pkgdelete = new FileInfo(str4);
                            Tracker.Invoke(new Action(() => log("Deleting " + pkgdelete.Name)));
                            File.Delete(str4);
                        }
                    }
                    catch
                    {
                    }
                    this.notifyIcon1.ShowBalloonTip(0x7d, "PeXploit", "PKG(s) Injected", ToolTipIcon.Info);
                    SystemSounds.Beep.Play();
                    MessageBox.Show("Complete.\r\nBackup saved to " + dirPath + "\n Restore Your Backup");
                    progressBar1.Invoke(new Action(() => progressBar1.Visible = false));
                }

                    #endregion
                #endregion << PKG_VIEW >>

            }
            catch (Exception ex)
            {
                MessageBox.Show("An Internal Error Accoured " + ex.Message + " It Has Been Loged", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                System.IO.File.WriteAllText(Application.StartupPath + "\\errorlog.txt", ex.ToString());
            }
        }
Beispiel #4
0
        private string DecryptPKGFile(string PKGFileName, FileInfo ini)
        {
            try
            {
                int moltiplicator = 65536;
                byte[] EncryptedData = new byte[AesKey.Length * moltiplicator];
                byte[] DecryptedData = new byte[AesKey.Length * moltiplicator];

                byte[] PKGXorKey = new byte[AesKey.Length];
                byte[] EncryptedFileStartOffset = new byte[4];
                byte[] EncryptedFileLenght = new byte[8];

                Stream PKGReadStream = new FileStream(PKGFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                BinaryReader brPKG = new BinaryReader(PKGReadStream);

                PKGReadStream.Seek(0x00, SeekOrigin.Begin);
                byte[] pkgMagic = brPKG.ReadBytes(4);
                if (pkgMagic[0x00] != 0x7F || pkgMagic[0x01] != 0x50 || pkgMagic[0x02] != 0x4B || pkgMagic[0x03] != 0x47)
                {
                    ResultText("ERROR: Selected file isn't a Pkg file.");
                    SystemSounds.Beep.Play();
                    return string.Empty;
                }

                //Finalized byte
                PKGReadStream.Seek(0x04, SeekOrigin.Begin);
                byte pkgFinalized = brPKG.ReadByte();

                if (pkgFinalized != 0x80)
                {
                    string com = ini.Name;
                    string command = "pkg " + com;
                    CMD(command);
                    if (File.Exists(Application.StartupPath + @"\\PARAM.SFO") == true)
                    {
                        string dir = Application.StartupPath + @"\CustomEnvoirment";
                        if (!Directory.Exists(dir))
                            Directory.CreateDirectory(dir);
                        dir += "\\dev_hdd0";
                        if (!Directory.Exists(dir))
                            Directory.CreateDirectory(dir);
                        dir += "\\game";
                        if (!Directory.Exists(dir))
                            Directory.CreateDirectory(dir);
                        PARAM_SFO parrameters = new PARAM_SFO(Application.StartupPath + @"\\PARAM.SFO");
                        string pkgid = parrameters.TitleID;
                        pkgID.Add(pkgid);
                        string pkgdir = dir + "\\" + pkgid;
                        Directory.CreateDirectory(pkgdir);
                        if (Directory.Exists(Application.StartupPath + @"\\USRDIR") == true)
                            Directory.Move(Application.StartupPath + @"\\USRDIR", pkgdir + "\\USRDIR");
                        if (Directory.Exists(Application.StartupPath + @"\\TROPDIR") == true)
                            Directory.Move(Application.StartupPath + @"\\TROPDIR", pkgdir + "\\TROPDIR");
                        if (File.Exists(Application.StartupPath + @"\\PARAM.SFO") == true)
                            File.Move(Application.StartupPath + @"\\PARAM.SFO", pkgdir + "\\PARAM.SFO");
                        if (File.Exists(Application.StartupPath + @"\\ICON0.PNG") == true)
                            File.Move(Application.StartupPath + @"\\ICON0.PNG", pkgdir + "\\ICON0.PNG");
                        if (File.Exists(Application.StartupPath + @"\\PIC1.PNG") == true)
                            File.Move(Application.StartupPath + @"\\PIC1.PNG", pkgdir + "\\PIC1.PNG");
                        if (File.Exists(Application.StartupPath + @"\\PS3LOGO.DAT") == true)
                            if (File.Exists(Application.StartupPath + @"\\PARAM.HIP") == true)
                                File.Move(Application.StartupPath + @"\\PARAM.HIP", pkgdir + "\\PARAM.HIP");
                        if (File.Exists(Application.StartupPath + @"\\PS3LOGO.DAT") == true)
                            File.Move(Application.StartupPath + @"\\PS3LOGO.DAT", pkgdir + "\\PS3LOGO.DAT");
                    }

                    SystemSounds.Beep.Play();
                    return string.Empty;
                }

                //PKG Type PSP/PS3
                PKGReadStream.Seek(0x07, SeekOrigin.Begin);
                byte pkgType = brPKG.ReadByte();

                switch (pkgType)
                {
                    case 0x01:
                        //PS3
                        AesKey = PS3AesKey;
                        break;

                    case 0x02:
                        //PSP
                        AesKey = PSPAesKey;
                        break;

                    default:
                        ResultText("ERROR: Selected pkg isn't Valid.");
                        SystemSounds.Beep.Play();
                        return string.Empty;
                }

                //0x24 Store the start Address of the encrypted file to decrypt
                PKGReadStream.Seek(0x24, SeekOrigin.Begin);
                pkgType = brPKG.ReadByte();
                EncryptedFileStartOffset = brPKG.ReadBytes((int)EncryptedFileStartOffset.Length);
                Array.Reverse(EncryptedFileStartOffset);
                uiEncryptedFileStartOffset = BitConverter.ToUInt32(EncryptedFileStartOffset, 0);

                //0x1C Store the length of the whole pkg file

                //0x2C Store the length of the encrypted file to decrypt
                PKGReadStream.Seek(0x2C, SeekOrigin.Begin);
                pkgType = brPKG.ReadByte();
                EncryptedFileLenght = brPKG.ReadBytes((int)EncryptedFileLenght.Length);
                Array.Reverse(EncryptedFileLenght);
                uint uiEncryptedFileLenght = BitConverter.ToUInt32(EncryptedFileLenght, 0);

                //0x70 Store the PKG file Key.
                PKGReadStream.Seek(0x70, SeekOrigin.Begin);
                PKGFileKey = brPKG.ReadBytes(16);
                byte[] incPKGFileKey = new byte[16];
                Array.Copy(PKGFileKey, incPKGFileKey, PKGFileKey.Length);

                //the "file" key at 0x70 have to be encrypted with a "global AES key" to generate the "xor" key
                //PSP uses CipherMode.ECB, PaddingMode.None that doesn't need IV
                PKGXorKey = AESEngine.Encrypt(PKGFileKey, AesKey, AesKey, CipherMode.ECB, PaddingMode.None);

                // Pieces calculation
                double division = (double)uiEncryptedFileLenght / (double)AesKey.Length;
                UInt64 pieces = (UInt64)Math.Floor(division);
                UInt64 mod = (UInt64)uiEncryptedFileLenght / (UInt64)AesKey.Length;
                if (mod > 0)
                    pieces += 1;

                if (File.Exists(PKGFileName + ".Dec"))
                {
                    File.Delete(PKGFileName + ".Dec");
                }

                //Write File
                FileStream DecryptedFileWriteStream = new FileStream(PKGFileName + ".Dec", FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite);
                BinaryWriter bwDecryptedFile = new BinaryWriter(DecryptedFileWriteStream);

                //Put the read pointer on the encrypted starting point.
                PKGReadStream.Seek((int)uiEncryptedFileStartOffset, SeekOrigin.Begin);

                // Pieces calculation
                double filedivision = (double)uiEncryptedFileLenght / (double)(AesKey.Length * moltiplicator);
                UInt64 filepieces = (UInt64)Math.Floor(filedivision);
                UInt64 filemod = (UInt64)uiEncryptedFileLenght % (UInt64)(AesKey.Length * moltiplicator);
                if (filemod > 0)
                    filepieces += 1;

                Application.DoEvents();

                for (UInt64 i = 0; i < filepieces; i++)
                {
                    //If we have a mod and this is the last piece then...
                    if ((filemod > 0) && (i == (filepieces - 1)))
                    {
                        EncryptedData = new byte[filemod];
                        DecryptedData = new byte[filemod];
                    }

                    //Read 16 bytes of Encrypted data
                    EncryptedData = brPKG.ReadBytes(EncryptedData.Length);

                    //In order to retrieve a fast AES Encryption we pre-Increment the array
                    byte[] PKGFileKeyConsec = new byte[EncryptedData.Length];
                    byte[] PKGXorKeyConsec = new byte[EncryptedData.Length];

                    for (long pos = 0; pos < EncryptedData.Length; pos += AesKey.Length)
                    {
                        Array.Copy(incPKGFileKey, 0, PKGFileKeyConsec, pos, PKGFileKey.Length);

                        IncrementArray(ref incPKGFileKey, PKGFileKey.Length - 1);
                    }

                    //the incremented "file" key have to be encrypted with a "global AES key" to generate the "xor" key
                    //PSP uses CipherMode.ECB, PaddingMode.None that doesn't need IV
                    PKGXorKeyConsec = AESEngine.Encrypt(PKGFileKeyConsec, AesKey, AesKey, CipherMode.ECB, PaddingMode.None);

                    //XOR Decrypt and save every 16 bytes of data:
                    DecryptedData = XOREngine.XOR(EncryptedData, 0, PKGXorKeyConsec.Length, PKGXorKeyConsec);

                    Application.DoEvents();

                    bwDecryptedFile.Write(DecryptedData);
                }
                Application.DoEvents();

                DecryptedFileWriteStream.Close();
                bwDecryptedFile.Close();

                return PKGFileName + ".Dec";
            }
            catch (Exception ex)
            {
                ResultText("ERROR: An error occured during the decrypting process ");
                SystemSounds.Beep.Play();
                return string.Empty;
            }
        }
Beispiel #5
0
        private void Read_SFO_Load(object sender, EventArgs e)
        {
            try
            {
                if (Directory.Exists(pkgpath + @"\C00\"))
                {
                    PARAM_SFO para = new PARAM_SFO(pkgpath + @"\C00\PARAM.SFO");
                    backgroundWorker1.RunWorkerAsync();
                    textBox1.Text = para.TitleID;
                    textBox2.Text = para.Title;
                    textBox3.Text = para.DataType.ToString();
                    textBox4.Text = para.ContentID;
                        if (textBox4.Text !="")
                        {
                            lblEdat.Text = "Edat Enabled";
                        }
                    this.Text += " : " + para.Title.Replace("???", "-");
                }
                else
                {
                    PARAM_SFO para = new PARAM_SFO(pkgpath + @"\PARAM.SFO");
                    textBox1.Text = para.TitleID;
                    textBox2.Text = para.Title.Replace("???", "(TM)");
                    textBox3.Text = para.DataType.ToString();
                    textBox4.Text = para.ContentID;
                    this.Text += " : " + para.Title.Replace("???", "-");
                    if (textBox4.Text != "")
                    {
                        lblEdat.Text = "Edat Enabled";
                        backgroundWorker1.RunWorkerAsync();
                        return;

                    }
                    backgroundWorker1.RunWorkerAsync();
                    textBox4.Visible = false;
                    label4.Visible = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #6
0
        public void SaveFile(PARAM_SFO psfo, string filename)
        {
            // Sort the values before we save them to the sfo file
            //Array.Sort(psfo.Tables);

            using (FileStream stream = File.Create(filename))
            {
                using (StructWriter sw = new StructWriter(ByteOrder.LSB, stream))
                {
                    //build index table
                    INDEX_TABLE_ENTRY[]     indexes   = new INDEX_TABLE_ENTRY[psfo.Tables.Length];
                    PARAM_SFO.Table[]       mytables  = psfo.Tables;
                    PARAM_SFO.index_table[] myindexes = new index_table[psfo.Tables.Length];

                    string[] variablenames  = new string[psfo.Tables.Length];
                    string[] variablevalues = new string[psfo.Tables.Length];

                    int  curkeynameoffset = 0;
                    uint curvalueoffset   = 0;

                    for (int idx = 0; idx < psfo.Tables.Length; idx++)
                    {
                        PARAM_SFO.Table value = psfo.Tables[idx];


                        PARAM_SFO.FMT datatype = FMT.UINT32;
                        uint          datasize = 0;
                        switch (value.Indextable.param_data_fmt)
                        {
                        case FMT.ASCII:
                        {
                            datatype = FMT.ASCII;
                            datasize = (uint)Encoding.UTF8.GetBytes(value.Value.ToString()).Length + 1;
                            break;
                        }

                        case FMT.UINT32:
                        {
                            datatype = FMT.UINT32;
                            datasize = 4;
                            break;
                        }

                        case FMT.UTF_8:
                        {
                            datatype = FMT.UTF_8;
                            datasize = (uint)Encoding.UTF8.GetBytes(value.Value.ToString()).Length + 1;
                            break;
                        }

                        default:
                        {
                            throw new Exception("Unknown SFOType!");
                        }
                        }


                        if (value.Indextable.param_key_offset != (ushort)curkeynameoffset)
                        {
                            string breakpoint = "This is for debug testing";
                        }
                        //value.Indextable.param_key_offset = (ushort)curkeynameoffset;

                        if (value.Indextable.param_data_fmt != datatype)
                        {
                            string breakpoint = "This is for debug testing";
                        }
                        //value.Indextable.param_data_fmt = datatype;

                        if (value.Indextable.param_data_len != datasize)
                        {
                            string breakpoint = "This is for debug testing";
                        }
                        //value.Indextable.param_data_len = datasize;

                        //if (value.Indextable.param_data_max_len != GetPaddingSize(value.Name, datasize))
                        //{
                        //    string breakpoint = "This is for debug testing";
                        //}
                        //value.Indextable.param_data_max_len = GetPaddingSize(value.Name, datasize);

                        if (value.Indextable.param_data_offset != curvalueoffset)
                        {
                            string breakpoint = "This is for debug testing";
                        }
                        //value.Indextable.param_data_offset = curvalueoffset;

                        //we already have all the keynames

                        curvalueoffset += value.Indextable.param_data_max_len;



                        indexes[idx].KeyNameOffset = (ushort)curkeynameoffset;
                        indexes[idx].Unknown       = 4;
                        if (datatype == FMT.UTF_8)
                        {
                            indexes[idx].DataType = DATA_TYPE.BinaryData;
                        }
                        if (datatype == FMT.ASCII)
                        {
                            indexes[idx].DataType = DATA_TYPE.Utf8Text;
                        }
                        if (datatype == FMT.UINT32)
                        {
                            indexes[idx].DataType = DATA_TYPE.Si32Integer;
                        }
                        indexes[idx].ValueDataSize            = datasize;
                        indexes[idx].ValueDataSizePlusPadding = GetPaddingSize(value.Name, datasize);
                        indexes[idx].DataValueOffset          = curvalueoffset;


                        curkeynameoffset += value.Name.Length + 1;


                        variablenames[idx] = value.Name;

                        myindexes[idx]      = value.Indextable;
                        variablevalues[idx] = value.Value;
                    }


                    SFO_HEADER sfoheader = new SFO_HEADER();
                    sfoheader.magic           = 0;
                    sfoheader.signature       = new char[] { 'P', 'S', 'F' };
                    sfoheader.FileVersionHigh = 1;
                    sfoheader.FileVersionLow  = 1;
                    sfoheader.Unknown1        = 0;
                    sfoheader.Start_of_Variable_Name_Table = Header.KeyTableStart;     //PadOffset(Marshal.SizeOf(sfoheader) + (psfo.Tables.Length * Marshal.SizeOf(typeof(PARAM_SFO.index_table))));//
                    sfoheader.Start_of_Variable_Data_Table = Header.DataTableStart;    //PadOffset(sfoheader.Start_of_Variable_Name_Table + curkeynameoffset);//
                    sfoheader.NumberOfVariables            = Header.IndexTableEntries; //(uint)psfo.Tables.Length;//

                    sw.WriteStruct(sfoheader);


                    // Write variable information...
                    sw.WriteStructs(indexes);

                    WritePadBytes(sw, sw.BaseStream.Position, sfoheader.Start_of_Variable_Name_Table);

                    // Write variable names...
                    sw.WriteStrings(StringType.NullTerminated, variablenames);

                    WritePadBytes(sw, sw.BaseStream.Position, sfoheader.Start_of_Variable_Data_Table);

                    // Write variable data...
                    for (int idx = 0; idx < psfo.Tables.Length; idx++)
                    {
                        PARAM_SFO.Table value = psfo.Tables[idx];

                        switch (value.Indextable.param_data_fmt)
                        {
                        case FMT.UTF_8:
                        {
                            sw.Write(value.Value);
                            break;
                        }

                        case FMT.UINT32:
                        {
                            sw.Write(Convert.ToUInt32(value.Value));
                            break;
                        }

                        case FMT.ASCII:
                        {
                            sw.Write(value.Value);
                            break;
                        }
                        }

                        long pos = sw.BaseStream.Position;

                        WritePadBytes(sw, myindexes[idx].param_data_len, myindexes[idx].param_data_max_len);
                    }
                }
            }
        }