diff --git a/CHOVY-GEN/CHOVY-GEN.vcxproj b/CHOVY-GEN/CHOVY-GEN.vcxproj
index fc93b29..06aa028 100644
--- a/CHOVY-GEN/CHOVY-GEN.vcxproj
+++ b/CHOVY-GEN/CHOVY-GEN.vcxproj
@@ -9,14 +9,6 @@
Release
Win32
-
- Debug
- x64
-
-
- Release
- x64
-
@@ -45,19 +37,6 @@
true
Unicode
-
- DynamicLibrary
- true
- v142
- Unicode
-
-
- DynamicLibrary
- false
- v142
- true
- Unicode
-
@@ -69,30 +48,18 @@
-
-
-
-
-
-
true
$(SolutionDir)CHOVY-SIGN\bin\$(Configuration)
$(ProjectName)
-
- true
-
false
- CHOVY
+ $(ProjectName)
$(SolutionDir)CHOVY-SIGN\bin\$(Configuration)
-
- false
-
@@ -109,18 +76,6 @@
ws2_32.lib;libsslMT.lib;Crypt32.lib;libcryptoMT.lib;%(AdditionalDependencies)
-
-
-
-
- Level3
- Disabled
- _DEBUG;_WINDOWS;_USRDLL;CHOVYGEN_EXPORTS;%(PreprocessorDefinitions)
-
-
- Windows
-
-
Level3
@@ -141,22 +96,6 @@
ws2_32.lib;libsslMT.lib;Crypt32.lib;libcryptoMT.lib;%(AdditionalDependencies)
-
-
- Level3
-
-
- MaxSpeed
- true
- true
- NDEBUG;_WINDOWS;_USRDLL;CHOVYGEN_EXPORTS;%(PreprocessorDefinitions)
-
-
- Windows
- true
- true
-
-
diff --git a/CHOVY-KIRK/CHOVY-KIRK.vcxproj b/CHOVY-KIRK/CHOVY-KIRK.vcxproj
index 05df53e..0307908 100644
--- a/CHOVY-KIRK/CHOVY-KIRK.vcxproj
+++ b/CHOVY-KIRK/CHOVY-KIRK.vcxproj
@@ -5,10 +5,6 @@
CHOVY
Win32
-
- CHOVY
- x64
-
Debug
Win32
@@ -17,14 +13,6 @@
Release
Win32
-
- Debug
- x64
-
-
- Release
- x64
-
15.0
@@ -48,25 +36,9 @@
true
Unicode
-
- DynamicLibrary
- true
- v142
- Unicode
-
-
- DynamicLibrary
- false
- v142
- true
- Unicode
-
v142
-
- v142
-
@@ -78,27 +50,15 @@
-
-
-
-
-
-
true
$(SolutionDir)CHOVY-SIGN\bin\$(Configuration)
-
- true
-
false
$(SolutionDir)CHOVY-SIGN\bin\$(Configuration)
-
- false
-
$(SolutionDir)CHOVY-SIGN\bin\$(Configuration)
@@ -114,18 +74,6 @@
Windows
-
-
-
-
- Level3
- Disabled
- _DEBUG;_WINDOWS;_USRDLL;KIRK_EXPORTS;%(PreprocessorDefinitions)
-
-
- Windows
-
-
Level3
@@ -143,22 +91,6 @@
true
-
-
- Level3
-
-
- MaxSpeed
- true
- true
- NDEBUG;_WINDOWS;_USRDLL;KIRK_EXPORTS;%(PreprocessorDefinitions)
-
-
- Windows
- true
- true
-
-
diff --git a/CHOVY-SIGN/CHOVY-SIGN.csproj b/CHOVY-SIGN/CHOVY-SIGN.csproj
index 891ad05..ef6c315 100644
--- a/CHOVY-SIGN/CHOVY-SIGN.csproj
+++ b/CHOVY-SIGN/CHOVY-SIGN.csproj
@@ -31,7 +31,7 @@
MinimumRecommendedRules.ruleset
- bin\x86\Release\
+ bin\Release\
TRACE
true
true
@@ -56,9 +56,6 @@
..\packages\System.Buffers.4.5.1\lib\netstandard1.1\System.Buffers.dll
-
- ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll
-
@@ -398,7 +395,7 @@
-
+
diff --git a/CHOVY-SIGN/CHOVYCmaSelector.cs b/CHOVY-SIGN/CHOVYCmaSelector.cs
index 36affe6..cfaeb82 100644
--- a/CHOVY-SIGN/CHOVYCmaSelector.cs
+++ b/CHOVY-SIGN/CHOVYCmaSelector.cs
@@ -77,7 +77,7 @@ namespace CHOVY_SIGN
string SfoPath = Path.Combine(BackupPath, Dir, "sce_sys", "param.sfo");
FileStream SfoStream = File.OpenRead(SfoPath);
Dictionary SfoKeys = Sfo.ReadSfo(SfoStream);
- string Title = (string)SfoKeys["Title"];
+ string Title = (string)SfoKeys["TITLE"];
SfoStream.Close();
string BackupName = (Path.GetFileName(Dir) + " - " + Title);
BackupList.Items.Add(BackupName);
diff --git a/CHOVY-SIGN/CHOVYPspBuilder.cs b/CHOVY-SIGN/CHOVYPspBuilder.cs
index 4cff496..58696b0 100644
--- a/CHOVY-SIGN/CHOVYPspBuilder.cs
+++ b/CHOVY-SIGN/CHOVYPspBuilder.cs
@@ -145,7 +145,6 @@ namespace CHOVY_SIGN
this.FREEDOM.ForeColor = enabled ? red : black;
this.FREEDOM.BackColor = enabled ? black : red;
}
-
private void FREEDOM_Click(object sender, EventArgs e)
{
Action enable = () => {
@@ -227,23 +226,55 @@ namespace CHOVY_SIGN
- // Try New System
- FileStream EbootStream = File.OpenWrite(EbootFile);
- FileStream IsoStream = File.OpenRead(ISOPath.Text);
- Bitmap BootupImage;
- if (isMini(ISOPath.Text))
- BootupImage = Resources.MINIS;
- else
- BootupImage = Resources.ChovyLogo;
- byte[] ParamSfo = ReadFileFromISO(ISOPath.Text, @"PSP_GAME\PARAM.SFO");
- byte[] Icon0 = ReadFileFromISO(ISOPath.Text, @"PSP_GAME\ICON0.PNG");
- byte[] Icon1 = ReadFileFromISO(ISOPath.Text, @"PSP_GAME\ICON1.PMF");
- byte[] Pic0 = ReadFileFromISO(ISOPath.Text, @"PSP_GAME\PIC0.PNG");
- byte[] Pic1 = ReadFileFromISO(ISOPath.Text, @"PSP_GAME\PIC1.PNG");
- byte[] Snd0 = ReadFileFromISO(ISOPath.Text, @"PSP_GAME\SND0.AT3");
+
+ Thread BuildPbpThread = new Thread(() =>
+ {
+ // Try New System
+ try
+ {
+ FileStream EbootStream = File.OpenWrite(EbootFile);
+ FileStream IsoStream = File.OpenRead(ISOPath.Text);
+ Bitmap BootupImage;
+ if (isMini(ISOPath.Text))
+ BootupImage = Resources.MINIS;
+ else
+ BootupImage = Resources.ChovyLogo;
- Pbp.BuildPbp(EbootStream, IsoStream, CompressPBP.Checked, FromHex(Versionkey.Text), BootupImage, ContentID, ParamSfo, Icon0, Icon1, Pic0, Pic1, Snd0);
+ byte[] Sfo = ReadFileFromISO(ISOPath.Text, @"PSP_GAME\PARAM.SFO");
+ byte[] Icon0Png = ReadFileFromISO(ISOPath.Text, @"PSP_GAME\ICON0.PNG");
+ byte[] Icon1 = ReadFileFromISO(ISOPath.Text, @"PSP_GAME\ICON1.PMF");
+ byte[] Pic0 = ReadFileFromISO(ISOPath.Text, @"PSP_GAME\PIC0.PNG");
+ byte[] Pic1 = ReadFileFromISO(ISOPath.Text, @"PSP_GAME\PIC1.PNG");
+ byte[] Snd0 = ReadFileFromISO(ISOPath.Text, @"PSP_GAME\SND0.AT3");
+
+ Pbp.BuildPbp(EbootStream, IsoStream, CompressPBP.Checked, FromHex(Versionkey.Text), BootupImage, ContentID, Sfo, Icon0Png, Icon1, Pic0, Pic1, Snd0);
+ IsoStream.Close();
+ EbootStream.Close();
+ }
+ catch (Exception exp)
+ {
+ MessageBox.Show(exp.Message, "Error.", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+
+ });
+ BuildPbpThread.Start();
+ while(BuildPbpThread.IsAlive)
+ {
+ if(!Pbp.HasFinished)
+ {
+ TotalProgress.Maximum = Pbp.NumberOfSectors;
+ TotalProgress.Value = Pbp.SectorsDone;
+ if (Pbp.SectorsDone != 0 && Pbp.NumberOfSectors != 0)
+ {
+ decimal progress = Math.Floor(((decimal)Pbp.SectorsDone / (decimal)Pbp.NumberOfSectors) * 100);
+ Status.Text = "Overthrowing The PSPEMU Monarchy " + progress.ToString() + "%";
+ }
+ else
+ Status.Text = "Overthrowing The PSPEMU Monarchy 0%";
+ Application.DoEvents();
+ }
+ }
/*Process signnp = pbp.GenPbpFromIso(ISOPath.Text, EbootFile, ContentID, Versionkey.Text, CompressPBP.Checked, BootupImage);
while (!signnp.HasExited)
@@ -262,19 +293,19 @@ namespace CHOVY_SIGN
Status.Text = "Signing the Declaration of Independance 0%";
UInt64 IntAid = BitConverter.ToUInt64(RifAid,0x00);
- Thread thrd = new Thread(() =>
+ Thread ChovyGenThread = 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");
+ MessageBox.Show("CHOVY-GEN Failed! Please check CHOVY-KIRK.DLL exists");
enable();
return;
}
});
- thrd.Start();
- while(thrd.IsAlive)
+ ChovyGenThread.Start();
+ while(ChovyGenThread.IsAlive)
{
Application.DoEvents();
}
@@ -384,6 +415,8 @@ namespace CHOVY_SIGN
string SceSysWorkDir = Path.Combine(BackupWorkDir, "sce_sys");
Directory.CreateDirectory(SceSysWorkDir);
+ byte[] ParamSfo = ReadFileFromISO(ISOPath.Text, @"PSP_GAME\PARAM.SFO");
+ byte[] Icon0 = ReadFileFromISO(ISOPath.Text, @"PSP_GAME\ICON0.PNG");
File.WriteAllBytes(Path.Combine(SceSysWorkDir, "param.sfo"), ParamSfo);
File.WriteAllBytes(Path.Combine(SceSysWorkDir, "icon0.png"), Icon0);
diff --git a/CHOVY-SIGN/DataUtils.cs b/CHOVY-SIGN/DataUtils.cs
index 2b7ee84..d842533 100644
--- a/CHOVY-SIGN/DataUtils.cs
+++ b/CHOVY-SIGN/DataUtils.cs
@@ -177,6 +177,24 @@ namespace BasicDataTypes
WriteString(Str,Text);
Str.Seek(oldPos, SeekOrigin.Begin);
}
+ public static void WriteBytes(Stream Str, byte[] Bytes, Int64 Size)
+ {
+ Int64 Written = 0;
+ while (Written < Size)
+ {
+ if ((Size - Written) > 2000000000)
+ {
+ Str.Write(Bytes, 0x00, 2000000000);
+ Written += 2000000000;
+ }
+ else
+ {
+ Str.Write(Bytes, 0x00, Convert.ToInt32(Size - Written));
+ Written += (Size - Written);
+ break;
+ }
+ }
+ }
public static void WriteString(Stream Str, String Text, int len = -1)
{
if (len < 0)
diff --git a/CHOVY-SIGN/ParamSfo.cs b/CHOVY-SIGN/ParamSfo.cs
index d10a5e0..80544f2 100644
--- a/CHOVY-SIGN/ParamSfo.cs
+++ b/CHOVY-SIGN/ParamSfo.cs
@@ -49,10 +49,10 @@ namespace ParamSfo
if(KeyName == replaceOption)
{
- int padLen = Convert.ToInt32(TotalSize - replaceValue.Length);
+ // int padLen = Convert.ToInt32(TotalSize - replaceValue.Length);
DataUtils.WriteStringAt(Sfo, replaceValue, ValueLocation);
- int newSz = replaceValue.Length + 1;
+ /*int newSz = replaceValue.Length + 1;
if(newSz > TotalSize)
{
throw new Exception("New Value is larger than Total Size.");
@@ -63,6 +63,7 @@ namespace ParamSfo
byte[] zeros = new byte[padLen];
Sfo.Write(zeros, 0x00, zeros.Length);
+ */
return SfoValues;
}
diff --git a/CHOVY-SIGN/pbp.cs b/CHOVY-SIGN/pbp.cs
index 7c95f84..bf3466d 100644
--- a/CHOVY-SIGN/pbp.cs
+++ b/CHOVY-SIGN/pbp.cs
@@ -1,5 +1,4 @@
using BasicDataTypes;
-using DiscUtils.Streams;
using ParamSfo;
using System;
using System.Diagnostics;
@@ -7,7 +6,6 @@ using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
-using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Windows.Forms;
@@ -125,6 +123,9 @@ namespace CHOVY_SIGN
return signnp;
}
+ public static int NumberOfSectors = 0;
+ public static int SectorsDone = 0;
+ public static bool HasFinished = false;
private static UInt32 readUInt32(Stream src)
{
@@ -436,6 +437,9 @@ namespace CHOVY_SIGN
sceDrmBBCipherFinal(&bck);
+ Array.ConstrainedCopy(ToEncrypt, 0x00, NpumdimgHeader, 0x40, ToEncrypt.Length);
+
+
// Generate header hash.
byte[] header_hash = new byte[0x10];
@@ -483,71 +487,67 @@ namespace CHOVY_SIGN
}
// Verify the generated ECDSA signature.
- byte[] TestSignature = new byte[0x64];
- Array.ConstrainedCopy(npumdimg_public_key, 0, TestSignature, 0, npumdimg_public_key.Length);
- Array.ConstrainedCopy(NpuimgHash, 0, TestSignature, npumdimg_public_key.Length, NpuimgHash.Length);
- Array.ConstrainedCopy(NpumdimgSignature, 0, TestSignature, npumdimg_public_key.Length + NpuimgHash.Length, NpumdimgSignature.Length);
- if (sceUtilsBufferCopyWithRange(null, 0, TestSignature, 0x64, KIRK_CMD_ECDSA_VERIFY) != 0)
- {
- throw new Exception("ECDSA signature for NPUMDIMG header is invalid!");
- }
+ VerifySignature(false, NpuimgHash, NpumdimgSignature);
// Finally put ECDSA signature into header.
Array.ConstrainedCopy(NpumdimgSignature, 0, NpumdimgHeader, 0xD8, NpumdimgSignature.Length);
- return NpumdimgSignature;
+ return NpumdimgHeader;
}
- unsafe public static void SignIso(Stream BaseStr, Stream Iso, string ContentId, byte[] VersionKey, bool Compress)
+ unsafe public static void SignIso(int HeaderOffset, Stream BaseStr, Stream Iso, string ContentId, byte[] VersionKey, bool Compress)
{
MAC_KEY MKey;
CIPHER_KEY CKey;
Int64 IsoSize = Iso.Length;
- Int64 TableOffset = Convert.ToInt64(BaseStr.Position);
+ Int64 TableOffset = Convert.ToInt64(HeaderOffset);
int BlockBasis = 0x10;
int BlockSize = BlockBasis * 2048;
+
Int64 IsoBlocks = (IsoSize + BlockSize - 1) / BlockSize;
+ NumberOfSectors = Convert.ToInt32(IsoBlocks);
+
Int64 TableSize = IsoBlocks * 0x20;
Int64 NpOffset = TableOffset - 0x100;
-
+ int NpSize = 0x100;
// Generate Random Header Key
byte[] HeaderKey = new byte[0x10];
sceUtilsBufferCopyWithRange(HeaderKey, HeaderKey.Length, null, 0, KIRK_CMD_PRNG);
byte[] TableBuffer = new byte[TableSize];
- BaseStr.Write(TableBuffer, 0x00, TableBuffer.Length);
+ DataUtils.WriteBytes(BaseStr, TableBuffer, TableSize);
// Write ISO Blocks
byte[] IsoBuffer = new byte[BlockSize * 2];
byte[] LZRCBuffer = new byte[BlockSize * 2];
byte[] Tb = new byte[0x20];
- byte[] WBuf;
Int64 IsoOffset = 0x100 + TableSize;
- int WSize, LZRCSize, Ratio;
+ int LZRCSize, Ratio;
int TbOffset = 0;
+ int WSize = 0;
for (int i = 0; i < IsoBlocks; i++)
{
+ SectorsDone = i;
Array.Clear(IsoBuffer, 0, IsoBuffer.Length);
- Array.Clear(LZRCBuffer, 0, IsoBuffer.Length);
+ Array.Clear(LZRCBuffer, 0, LZRCBuffer.Length);
Array.Clear(Tb, 0, Tb.Length);
TbOffset = i * 0x20;
Array.ConstrainedCopy(TableBuffer, TbOffset, Tb, 0, Tb.Length);
- if ((Iso.Length + BlockSize) > IsoSize)
+ if ((Iso.Position + BlockSize) > IsoSize)
{
- int Remaining = Convert.ToInt32(IsoSize - Iso.Length);
- Iso.Read(IsoBuffer, 0x00, Remaining);
- WSize = Remaining;
+ Int64 Remaining = IsoSize - Iso.Position;
+ Iso.Read(IsoBuffer, 0x00, Convert.ToInt32(Remaining));
+ WSize = Convert.ToInt32(Remaining);
}
else
{
- Iso.Read(IsoBuffer, 0x01, BlockSize);
+ Iso.Read(IsoBuffer, 0x00, BlockSize);
WSize = BlockSize;
}
- WBuf = IsoBuffer;
if (Compress)
{
@@ -556,7 +556,6 @@ namespace CHOVY_SIGN
if (Ratio < RATIO_LIMIT)
{
- WBuf = LZRCBuffer;
WSize = (LZRCSize + 15) & ~15;
}
}
@@ -569,12 +568,18 @@ namespace CHOVY_SIGN
// Encrypt Block
sceDrmBBCipherInit(&CKey, 1, 2, HeaderKey, VersionKey, Convert.ToUInt32((IsoOffset >> 4)));
- sceDrmBBCipherUpdate(&CKey, WBuf, WSize);
+ if(!Compress)
+ sceDrmBBCipherUpdate(&CKey, IsoBuffer, WSize);
+ else
+ sceDrmBBCipherUpdate(&CKey, LZRCBuffer, WSize);
sceDrmBBCipherFinal(&CKey);
// Build MAC.
sceDrmBBMacInit(&MKey, 3);
- sceDrmBBMacUpdate(&MKey, WBuf, WSize);
+ if (!Compress)
+ sceDrmBBMacUpdate(&MKey, IsoBuffer, WSize);
+ else
+ sceDrmBBMacUpdate(&MKey, LZRCBuffer, WSize);
sceDrmBBMacFinal(&MKey, Tb, VersionKey);
bbmac_build_final2(3, Tb);
@@ -584,7 +589,10 @@ namespace CHOVY_SIGN
// Write ISO data.
WSize = (WSize + 15) & ~15;
- BaseStr.Write(WBuf, 0x00, WSize);
+ if (!Compress)
+ BaseStr.Write(IsoBuffer, 0x00, WSize);
+ else
+ BaseStr.Write(LZRCBuffer, 0x00, WSize);
// Update offset.
IsoOffset += WSize;
@@ -593,7 +601,7 @@ namespace CHOVY_SIGN
Array.ConstrainedCopy(EncTb, 0, TableBuffer, TbOffset, EncTb.Length);
}
-
+ HasFinished = true;
// Generate data key.
byte[] DataKey = new byte[0x10];
sceDrmBBMacInit(&MKey, 3);
@@ -603,11 +611,9 @@ namespace CHOVY_SIGN
byte[] NpumdimgHeader = BuildNpumdimgHeader(Convert.ToInt32(IsoSize), Convert.ToInt32(IsoBlocks), BlockBasis, ContentId, NP_FLAGS, VersionKey, HeaderKey, DataKey);
BaseStr.Seek(NpOffset, SeekOrigin.Begin);
- BaseStr.Write(NpumdimgHeader, 0x00, NpumdimgHeader.Length);
+ BaseStr.Write(NpumdimgHeader, 0x00, NpSize);
BaseStr.Seek(TableOffset, SeekOrigin.Begin);
- BaseStr.Write(TableBuffer, 0x00, TableBuffer.Length);
-
- return;
+ DataUtils.WriteBytes(BaseStr, TableBuffer, TableSize);
}
public static UInt32[] ByteArrayToUint32Array(byte[] ByteArray)
@@ -619,7 +625,7 @@ namespace CHOVY_SIGN
public static byte[] UInt32ArrayToByteArray(UInt32[] Uint32Array)
{
byte[] decode = new byte[Uint32Array.Length * 4];
- System.Buffer.BlockCopy(Uint32Array, 0, decode, 0, Uint32Array.Length);
+ System.Buffer.BlockCopy(Uint32Array, 0, decode, 0, Uint32Array.Length * 4);
return decode;
}
public static byte[] encrypt_table(byte[] table)
@@ -686,6 +692,13 @@ namespace CHOVY_SIGN
Str.Seek(OffsetToWrite, SeekOrigin.Begin);
Str.Write(pic0, 0x00, pic0.Length);
OffsetToWrite += pic0.Length;
+
+ //Write Pic1
+ Str.Seek(0x18, SeekOrigin.Begin); // Pic0 Offset
+ DataUtils.WriteInt32(Str, OffsetToWrite);
+ Str.Seek(OffsetToWrite, SeekOrigin.Begin);
+ Str.Write(pic1, 0x00, pic1.Length);
+ OffsetToWrite += pic1.Length;
//Write SND0
Str.Seek(0x1C, SeekOrigin.Begin); // SND0 Offset
@@ -714,7 +727,11 @@ namespace CHOVY_SIGN
OffsetToWrite += DataPsar.Length;
// Sign ISO Contents.
- SignIso(Str, Iso, content_id, VersionKey, Compress);
+ SignIso(OffsetToWrite, Str, Iso, content_id, VersionKey, Compress);
+
+ NumberOfSectors = 0;
+ SectorsDone = 0;
+ HasFinished = false;
}
public static int gen__sce_ebootpbp(string EbootFile, UInt64 AID, string OutSceebootpbpFile)
{