public static Process PSVIMG_EXTRACT(string AID, string PSVIMG, string OUTPUT) { PSVIMG = PSVIMG.Replace("/", "\\"); OUTPUT = OUTPUT.Replace("/", "\\"); string CmaKey = CmaKeys.GenerateKeyStr(AID); Process psvimgtools = new Process(); psvimgtools.StartInfo.FileName = Path.Combine(Application.StartupPath, "tools", "psvimg-extract.exe"); psvimgtools.StartInfo.Arguments = "-K " + CmaKey + " \"" + PSVIMG + "\" \"" + OUTPUT + "\""; psvimgtools.StartInfo.CreateNoWindow = true; psvimgtools.StartInfo.UseShellExecute = false; psvimgtools.StartInfo.RedirectStandardInput = true; // NO IDEA WHY BUT IT DOESNT WORK WITHOUT THIS psvimgtools.StartInfo.RedirectStandardOutput = true; psvimgtools.StartInfo.RedirectStandardError = true; psvimgtools.Start(); return(psvimgtools); }
public static string GenerateKeyStr(string Aid) { try { Int64 longlong = Convert.ToInt64(Aid, 16); byte[] AidBytes = BitConverter.GetBytes(longlong); Array.Reverse(AidBytes); byte[] DerivedKey = CmaKeys.GenerateKey(AidBytes); return(BitConverter.ToString(DerivedKey).Replace("-", "")); } catch (Exception) { return("INVALID_AID"); } }
private void Ccs_FormClosing(object sender, FormClosingEventArgs e) { CHOVYCmaSelector ccs = (CHOVYCmaSelector)sender; string CmaDir = ccs.GetCmaDir(); string CmaAid = ccs.GetCmaAid(); string Backup = ccs.GetSelectedBackup(); WriteSetting("CmaDir", CmaDir); if (Backup == "") { return; } string BackupPath = Path.Combine(CmaDir, "PGAME", CmaAid, Backup, "game", "game.psvimg"); if (!File.Exists(BackupPath)) { MessageBox.Show("Could not find \n" + BackupPath + "\n Perhaps backup failed?", "License Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ccs.Hide(); this.Show(); this.Focus(); return; } byte[] AID = BitConverter.GetBytes(Convert.ToInt64(CmaAid, 16)); Array.Reverse(AID); byte[] Key = CmaKeys.GenerateKey(AID); PSVIMGStream GamePsvimg = new PSVIMGStream(File.OpenRead(BackupPath), Key); BackupPath = Path.Combine(CmaDir, "PGAME", CmaAid, Backup, "license", "license.psvimg"); if (!File.Exists(BackupPath)) { MessageBox.Show("Could not find \n" + BackupPath + "\n Perhaps backup failed?", "License Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ccs.Hide(); this.Show(); this.Focus(); return; } PSVIMGStream LicensePsvimg = new PSVIMGStream(File.OpenRead(BackupPath), Key); string Rif = Path.Combine(Application.StartupPath, "GAME.RIF"); PSVIMGFileStream EbootPbp = new PSVIMGFileStream(GamePsvimg, "/EBOOT.PBP"); byte[] VersionKey = pbp.GetVersionKey(EbootPbp); string VerKey = BitConverter.ToString(VersionKey).Replace("-", ""); WriteSetting("VersionKey", VerKey); string ContentID = pbp.GetContentId(EbootPbp); PSVIMGFileStream LicenseRif = new PSVIMGFileStream(LicensePsvimg, "/" + ContentID + ".rif"); LicenseRif.WriteToFile(Rif); LicenseRif.Close(); LicensePsvimg.Close(); EbootPbp.Close(); GamePsvimg.Close(); WriteSetting("RifPath", Rif); Versionkey.Text = VerKey; RifPath.Text = Rif; ccs.Hide(); this.Show(); this.Focus(); MessageBox.Show("KEYS HAVE BEEN EXTRACTED FROM CMA, YOU MAY NOW LIBERATE YOURSELF", "SUCCESS", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void FREEDOM_Click(object sender, EventArgs e) { Action enable = () => { this.FREEDOM.Enabled = true; }; if (RifPath.Text == "" || !File.Exists(RifPath.Text)) { MessageBox.Show("INVALID RIF PATH!\nPlease try \"Find from CMA\"", "RIF ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (Versionkey.Text.Length != 32) { MessageBox.Show("INVALID VERSION KEY!\nPlease try \"Find from CMA\"", "VERKEY ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (ISOPath.Text == "" || !File.Exists(ISOPath.Text)) { MessageBox.Show("INVALID ISO PATH!", "ISO ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.FREEDOM.Enabled = false; string CmaDir = ReadSetting("CmaDir"); if (CmaDir == "") { FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.Description = "Select CMA Backups Directory"; fbd.ShowDialog(); CmaDir = fbd.SelectedPath; } string TitleID = GetTitleID(ISOPath.Text); string TmpDir = Path.Combine(Application.StartupPath, "_tmp"); string GameWorkDir = Path.Combine(TmpDir, TitleID); string EbootFile = Path.Combine(GameWorkDir, "EBOOT.PBP"); string EbootSignature = Path.Combine(GameWorkDir, "__sce_ebootpbp"); Directory.CreateDirectory(TmpDir); Directory.CreateDirectory(GameWorkDir); //Read RIF data byte[] ContentId = new byte[0x24]; byte[] RifAid = new byte[0x08]; FileStream rif = File.OpenRead(RifPath.Text); rif.Seek(0x10, SeekOrigin.Begin); rif.Read(ContentId, 0x00, 0x24); rif.Seek(0x08, SeekOrigin.Begin); rif.Read(RifAid, 0x00, 0x08); rif.Close(); string ContentID = Encoding.UTF8.GetString(ContentId); string Aid = BitConverter.ToString(RifAid).Replace("-", "").ToLower(); string BackupWorkDir = Path.Combine(CmaDir, "PGAME", Aid, TitleID); TotalProgress.Maximum = 100; Status.Text = "Overthrowing The PSPEMU Monarchy 0%"; string BootupImage = ""; if (isMini(ISOPath.Text)) { BootupImage = Path.Combine(Application.StartupPath, "_tmp", "minis.png"); Resources.MINIS.Save(BootupImage); } else { BootupImage = Path.Combine(Application.StartupPath, "_tmp", "chovy.png"); Resources.ChovyLogo.Save(BootupImage); } Process signnp = pbp.GenPbpFromIso(ISOPath.Text, EbootFile, ContentID, Versionkey.Text, CompressPBP.Checked, BootupImage); while (!signnp.HasExited) { string Progress = signnp.StandardOutput.ReadLine(); if (Progress.StartsWith("Writing ISO blocks: ")) { Progress = Progress.Remove(0, 19); int ProgressInt = int.Parse(Progress.Substring(0, 3)); TotalProgress.Value = ProgressInt; Status.Text = "Overthrowing The PSPEMU Monarchy " + ProgressInt.ToString() + "%"; } Application.DoEvents(); } TotalProgress.Value = 0; Status.Text = "Signing the Declaration of Independance 0%"; UInt64 IntAid = BitConverter.ToUInt64(RifAid, 0x00); Thread thrd = new Thread(() => { int ChovyGenRes = pbp.gen__sce_ebootpbp(EbootFile, IntAid, EbootSignature); if (!File.Exists(EbootSignature) || ChovyGenRes != 0) { MessageBox.Show("CHOVY-GEN Failed! Please check CHOVY.DLL exists\nand that the Microsoft Visual C++ 2015 Redistributable Update 3 RC is installed"); enable(); return; } }); thrd.Start(); while (thrd.IsAlive) { Application.DoEvents(); } /* * BUILD PSVIMG FILE */ // Pacakge GAME byte[] CmaKey = CmaKeys.GenerateKey(RifAid); string[] entrys = Directory.GetFileSystemEntries(GameWorkDir, "*", SearchOption.AllDirectories); long noEntrys = entrys.LongLength; string parentPath = "ux0:pspemu/temp/game/PSP/GAME/" + TitleID; int noBlocks = 0; foreach (string fileName in Directory.GetFiles(GameWorkDir, "*", SearchOption.AllDirectories)) { noBlocks += Convert.ToInt32(new FileInfo(fileName).Length / PSVIMGConstants.PSVIMG_BLOCK_SIZE); } TotalProgress.Maximum = noBlocks; string BackupDir = Path.Combine(BackupWorkDir, "game"); Directory.CreateDirectory(BackupDir); string psvimgFilepath = Path.Combine(BackupDir, "game.psvimg"); FileStream gamePsvimg = File.OpenWrite(psvimgFilepath); gamePsvimg.SetLength(0); PSVIMGBuilder builder = new PSVIMGBuilder(gamePsvimg, CmaKey); foreach (string entry in entrys) { string relativePath = entry.Remove(0, GameWorkDir.Length); relativePath = relativePath.Replace('\\', '/'); bool isDir = File.GetAttributes(entry).HasFlag(FileAttributes.Directory); if (isDir) { builder.AddDir(entry, parentPath, relativePath); } else { builder.AddFileAsync(entry, parentPath, relativePath); while (!builder.HasFinished) { try { int tBlocks = builder.BlocksWritten; TotalProgress.Value = tBlocks; decimal progress = Math.Floor(((decimal)tBlocks / (decimal)noBlocks) * 100); Status.Text = "Signing the Declaration of Independance " + progress.ToString() + "%"; } catch (Exception) { } Application.DoEvents(); } } } long ContentSize = builder.Finish(); gamePsvimg = File.OpenRead(psvimgFilepath); FileStream gamePsvmd = File.OpenWrite(Path.Combine(BackupDir, "game.psvmd")); PSVMDBuilder.CreatePsvmd(gamePsvmd, gamePsvimg, ContentSize, "game", CmaKey); gamePsvmd.Close(); gamePsvimg.Close(); // Package LICENSE BackupDir = Path.Combine(BackupWorkDir, "license"); psvimgFilepath = Path.Combine(BackupDir, "license.psvimg"); Directory.CreateDirectory(BackupDir); FileStream licensePsvimg = File.OpenWrite(psvimgFilepath); licensePsvimg.SetLength(0); builder = new PSVIMGBuilder(licensePsvimg, CmaKey); builder.AddFile(RifPath.Text, "ux0:pspemu/temp/game/PSP/LICENSE", "/" + ContentID + ".rif"); ContentSize = builder.Finish(); licensePsvimg = File.OpenRead(psvimgFilepath); FileStream licensePsvmd = File.OpenWrite(Path.Combine(BackupDir, "license.psvmd")); PSVMDBuilder.CreatePsvmd(licensePsvmd, licensePsvimg, ContentSize, "license", CmaKey); licensePsvmd.Close(); licensePsvimg.Close(); // Write PARAM.SFO & ICON0.PNG string SceSysWorkDir = Path.Combine(BackupWorkDir, "sce_sys"); Directory.CreateDirectory(SceSysWorkDir); byte[] ParamSfo = GetSfo(ISOPath.Text); byte[] Icon0 = GetIcon(ISOPath.Text); File.WriteAllBytes(Path.Combine(SceSysWorkDir, "param.sfo"), ParamSfo); File.WriteAllBytes(Path.Combine(SceSysWorkDir, "icon0.png"), Icon0); Status.Text = "YOU HAVE MADE A SOCIAL CONTRACT WITH FREEDOM!"; TotalProgress.Value = 0; try { Directory.Delete(TmpDir, true); } catch (Exception) { }; if (!MutedAudio) { Stream str = Resources.Murica; SoundPlayer snd = new SoundPlayer(str); snd.Play(); } enable(); MessageBox.Show("YOU HAVE MADE A SOCIAL CONTRACT WITH FREEDOM!", "FREEDOM!", MessageBoxButtons.OK, MessageBoxIcon.Information); }