private void UpdateBackupList() { BackupList.Items.Clear(); try { string CmaDir = CMADir.Text; string Aid = AIDSelector.Text; string BackupuPath = Path.Combine(CmaDir, "PGAME", Aid); foreach (string Dir in Directory.GetDirectories(BackupuPath)) { try { string SfoPath = Path.Combine(BackupuPath, Dir, "sce_sys", "param.sfo"); FileStream SfoStream = File.OpenRead(SfoPath); PARAM_SFO sfo = new PARAM_SFO(SfoStream); string Title = sfo.Title; SfoStream.Close(); string BackupName = (Path.GetFileName(Dir) + " - " + Title); BackupList.Items.Add(BackupName); } catch (Exception) { BackupList.Items.Add(Path.GetFileName(Dir)); } } } catch (Exception) { } }
public string GetTitleFromPbp(string pbp) { byte[] SfoData = GetSfo(pbp); using (MemoryStream ms = new MemoryStream(SfoData, 0x00, SfoData.Length)) { PARAM_SFO sfo = new PARAM_SFO(ms); return(sfo.Title); } }
private void button1_Click(object sender, EventArgs e) { if (Directory.Exists(@"C:/temp")) { Console.Write("Temp directory deleted"); Directory.Delete(@"C:/temp", true); } openFileDialog1.Title = "Open Game..."; openFileDialog1.Filter = "VPK Files |*.vpk|Zip Files |*.zip"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { gameNameLabel.Text = openFileDialog1.FileName; bool isvpk = false; if (openFileDialog1.FileName.Contains(".vpk")) { isvpk = true; File.Move(openFileDialog1.FileName, Path.ChangeExtension(openFileDialog1.FileName, ".zip")); openFileDialog1.FileName = Path.ChangeExtension(openFileDialog1.FileName, ".zip"); } var archive = ArchiveFactory.Open(openFileDialog1.FileName); fileSizeLabel.Text = "File Size: " + archive.TotalSize + " bytes"; statusLabel.Text = "Reading File..."; foreach (var file_ in archive.Entries) { if (file_.Key.Contains("sce_sys") || file_.Key == "eboot.bin") { file_.WriteToDirectory(@"C:\temp\install", ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite); } else { file_.WriteToDirectory(@"C:\temp\data", ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite); } } archive.Dispose(); pictureBox1.ImageLocation = @"C:\temp\install\sce_sys\pic0.png"; statusLabel.Text = "Reading SFO..."; param = new PARAM_SFO(@"C:\temp\install\sce_sys\param.sfo"); gameNameLabel.Text = param.Title; statusLabel.Text = "Game Loaded"; button2.Enabled = true; if (isvpk) { File.Move(openFileDialog1.FileName, Path.ChangeExtension(openFileDialog1.FileName, ".vpk")); } } }
public static string GetTitleID(string ISOFile) { FileStream ISO = File.OpenRead(ISOFile); CDReader cdr = new CDReader(ISO, false); Stream ParamSfo = cdr.OpenFile(@"PSP_GAME\PARAM.SFO", FileMode.Open, FileAccess.Read); PARAM_SFO sfo = new PARAM_SFO(ParamSfo); string TitleID = sfo.GetValue("DISC_ID"); ISO.Close(); return(TitleID); }
private void button1_Click(object sender, EventArgs e) { if (backgroundWorker1.IsBusy) { backgroundWorker1.CancelAsync(); } OpenFileDialog theDialog = new OpenFileDialog(); theDialog.Title = "Select PARAM.SFO File"; theDialog.Filter = "PARAM.SFO|*.sfo"; theDialog.InitialDirectory = System.Environment.SpecialFolder.MyComputer.ToString(); if (theDialog.ShowDialog() == DialogResult.OK) { sfopath = theDialog.FileName; sfopath = sfopath.Replace("\\PARAM.SFO", ""); if (File.Exists(sfopath + @"\C00\PARAM.SFO")) { PARAM_SFO para = new PARAM_SFO(sfopath + @"\C00\PARAM.SFO"); if (backgroundWorker1.IsBusy == false) { backgroundWorker1.RunWorkerAsync(); } textBox1.Text = para.TitleID; textBox4.Text = para.Title; textBox3.Text = para.DataType.ToString(); textBox2.Text = para.ContentID; string[] lines = System.IO.File.ReadAllLines(Application.StartupPath + @"\PS3DB"); foreach (string line in lines) { if (line.Contains(textBox1.Text)) { lblEdat.Text = "Edat Enabled"; } } this.Text = "SFO Reader : " + para.Title.Replace("???", "-"); } else { { PARAM_SFO para = new PARAM_SFO(sfopath + @"\PARAM.SFO"); string[] lines = System.IO.File.ReadAllLines(Application.StartupPath + @"\PS3DB"); textBox1.Text = para.TitleID; textBox4.Text = para.Title.Replace("???", "(TM)"); textBox3.Text = para.DataType.ToString(); textBox2.Text = para.ContentID; this.Text = "SFO Reader : " + para.Title.Replace("???", "-"); foreach (string line in lines) { if (line.Contains(textBox1.Text) == true) { if (backgroundWorker1.IsBusy == false) { backgroundWorker1.RunWorkerAsync(); } lblEdat.Text = "Edat Enabled"; return; } } if (backgroundWorker1.IsBusy == false) { backgroundWorker1.RunWorkerAsync(); } textBox4.Visible = false; label4.Visible = false; } } } }
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) { //secondary check for ps4 if (pkgMagic[0x00] != 0x7F || pkgMagic[0x01] != 0x43 || pkgMagic[0x02] != 0x4E || pkgMagic[0x03] != 0x54) { //this is either a ps3 or psp or psvita pkg MessageBox.Show("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) { File.Copy(ini.FullName, Application.StartupPath + "\\" + ini.Name, true); string arguments = ini.Name; string com = Application.StartupPath + "@\\pkg.exe "; CMD(com, arguments); if (File.Exists("PARAM.SFO") == true) { string dir = Application.StartupPath + @"\Extracted"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } PARAM_SFO parrameters = new PARAM_SFO("PARAM.SFO"); string pkgid = parrameters.TitleID; pkgID.Add(pkgid); if (!Directory.Exists(dir + "\\Extracted\\" + pkgid)) { string pkgdir = dir + "\\" + pkgid; Directory.CreateDirectory(pkgdir); if (Directory.Exists("USRDIR") == true) { Directory.Move("USRDIR", pkgdir + "\\USRDIR"); } if (Directory.Exists("TROPDIR") == true) { Directory.Move("TROPDIR", pkgdir + "\\TROPDIR"); } if (File.Exists("PARAM.SFO") == true) { File.Move("PARAM.SFO", pkgdir + "\\PARAM.SFO"); } if (File.Exists("ICON0.PNG") == true) { File.Move("ICON0.PNG", pkgdir + "\\ICON0.PNG"); } if (File.Exists("PIC1.PNG") == true) { File.Move("PIC1.PNG", pkgdir + "\\PIC1.PNG"); } if (File.Exists("PS3LOGO.DAT") == true) { if (File.Exists("PARAM.HIP") == true) { File.Move("PARAM.HIP", pkgdir + "\\PARAM.HIP"); } } if (File.Exists("PS3LOGO.DAT") == true) { File.Move("PS3LOGO.DAT", pkgdir + "\\PS3LOGO.DAT"); } if (File.Exists("out.txt")) { File.Copy("out.txt", pkgdir + "[" + pkgid + "]extractedlist.txt"); File.Delete("out.txt"); } } else { if (Directory.Exists("USRDIR") == true) { Directory.Delete("USRDIR", true); } if (Directory.Exists("TROPDIR") == true) { Directory.Delete("TROPDIR", true); } if (File.Exists("PARAM.SFO") == true) { File.Delete("PARAM.SFO"); } if (File.Exists("ICON0.PNG") == true) { File.Delete("ICON0.PNG"); } if (File.Exists("PIC1.PNG") == true) { File.Delete("PIC1.PNG"); } if (File.Exists("PS3LOGO.DAT") == true) { if (File.Exists("PARAM.HIP") == true) { File.Delete("PARAM.HIP"); } } if (File.Exists("PS3LOGO.DAT") == true) { File.Delete("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: MessageBox.Show("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); 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(0x28, SeekOrigin.Begin); 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 (int 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) { MessageBox.Show("ERROR: An error occured during the decrypting process "); SystemSounds.Beep.Play(); return(string.Empty); } }