Working on trucha bug restoration, not done, but closer

This commit is contained in:
givememystuffplease 2009-08-02 18:12:05 +00:00
parent a08307ee35
commit 1fff53a1e4
2 changed files with 101 additions and 29 deletions

View File

@ -174,7 +174,6 @@
this.dlprogress.Size = new System.Drawing.Size(250, 15); this.dlprogress.Size = new System.Drawing.Size(250, 15);
this.dlprogress.Style = System.Windows.Forms.ProgressBarStyle.Continuous; this.dlprogress.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
this.dlprogress.TabIndex = 7; this.dlprogress.TabIndex = 7;
this.dlprogress.Click += new System.EventHandler(this.dlprogress_Click);
// //
// localuse // localuse
// //
@ -419,14 +418,12 @@
// truchabox // truchabox
// //
this.truchabox.AutoSize = true; this.truchabox.AutoSize = true;
this.truchabox.Enabled = false;
this.truchabox.Location = new System.Drawing.Point(184, 468); this.truchabox.Location = new System.Drawing.Point(184, 468);
this.truchabox.Name = "truchabox"; this.truchabox.Name = "truchabox";
this.truchabox.Size = new System.Drawing.Size(60, 17); this.truchabox.Size = new System.Drawing.Size(60, 17);
this.truchabox.TabIndex = 21; this.truchabox.TabIndex = 21;
this.truchabox.Text = "Trucha"; this.truchabox.Text = "Trucha";
this.truchabox.UseVisualStyleBackColor = true; this.truchabox.UseVisualStyleBackColor = true;
this.truchabox.Visible = false;
// //
// tmdgpbox // tmdgpbox
// //
@ -734,7 +731,7 @@
this.contentModBox.Controls.Add(this.button11); this.contentModBox.Controls.Add(this.button11);
this.contentModBox.Controls.Add(this.button9); this.contentModBox.Controls.Add(this.button9);
this.contentModBox.Controls.Add(this.button10); this.contentModBox.Controls.Add(this.button10);
this.contentModBox.Location = new System.Drawing.Point(287, 435); this.contentModBox.Location = new System.Drawing.Point(268, 153);
this.contentModBox.Name = "contentModBox"; this.contentModBox.Name = "contentModBox";
this.contentModBox.Size = new System.Drawing.Size(249, 327); this.contentModBox.Size = new System.Drawing.Size(249, 327);
this.contentModBox.TabIndex = 41; this.contentModBox.TabIndex = 41;
@ -883,8 +880,8 @@
this.ClientSize = new System.Drawing.Size(539, 492); this.ClientSize = new System.Drawing.Size(539, 492);
this.Controls.Add(this.button3); this.Controls.Add(this.button3);
this.Controls.Add(this.shamelessvariablelabel); this.Controls.Add(this.shamelessvariablelabel);
this.Controls.Add(this.contentModBox);
this.Controls.Add(this.button1); this.Controls.Add(this.button1);
this.Controls.Add(this.contentModBox);
this.Controls.Add(this.button17); this.Controls.Add(this.button17);
this.Controls.Add(this.ticketgpbox); this.Controls.Add(this.ticketgpbox);
this.Controls.Add(this.tmdgpbox); this.Controls.Add(this.tmdgpbox);

View File

@ -2583,6 +2583,11 @@ namespace NUS_Downloader
} }
private void button14_Click(object sender, EventArgs e) private void button14_Click(object sender, EventArgs e)
{
UpdateTMDContents();
}
private void UpdateTMDContents()
{ {
// Write changes to TMD of contents... // Write changes to TMD of contents...
WriteStatus("Updating TMD with content information..."); WriteStatus("Updating TMD with content information...");
@ -2606,7 +2611,7 @@ namespace NUS_Downloader
} }
for (int c = 0; c < 8; c++) for (int c = 0; c < 8; c++)
{ {
iv[c+8] = 0x00; iv[c + 8] = 0x00;
} }
initCrypt(iv, commonkey); initCrypt(iv, commonkey);
@ -2843,7 +2848,6 @@ namespace NUS_Downloader
FileStream testtmd = new FileStream(fileinfo[0] + fileinfo[1], FileMode.Open); FileStream testtmd = new FileStream(fileinfo[0] + fileinfo[1], FileMode.Open);
testtmd.Write(tmd, 0, tmd.Length); testtmd.Write(tmd, 0, tmd.Length);
testtmd.Close(); testtmd.Close();
} }
/* Pad Byte[] to specific alignment... /* Pad Byte[] to specific alignment...
@ -2998,7 +3002,7 @@ namespace NUS_Downloader
WriteStatus(String.Format(" - Bug restored at 0x{0}", int.Parse(oldresults[s].ToString(), System.Globalization.NumberStyles.HexNumber))); WriteStatus(String.Format(" - Bug restored at 0x{0}", int.Parse(oldresults[s].ToString(), System.Globalization.NumberStyles.HexNumber)));
} }
} }
// TODO THIS DOESN't WORK I THINK REWRITE THE FILE>>>
if (newresults[0] != 0) if (newresults[0] != 0)
{ {
WriteStatus(String.Format(" - {0} New-school ES Signing Fix(es) Found...", newresults[0])); WriteStatus(String.Format(" - {0} New-school ES Signing Fix(es) Found...", newresults[0]));
@ -3011,10 +3015,10 @@ namespace NUS_Downloader
} }
else else
{ {
/* Content is part of original TMD and must be decrypted...
string filename = contentsEdit.Items[contentsEdit.SelectedIndex].ToString().Substring(contentsEdit.Items[contentsEdit.SelectedIndex].ToString().IndexOf("] [") + 3, 8); string filename = contentsEdit.Items[contentsEdit.SelectedIndex].ToString().Substring(contentsEdit.Items[contentsEdit.SelectedIndex].ToString().IndexOf("] [") + 3, 8);
byte[] ticket = FileLocationToByteArray(fileinfo[0] + "cetk"); byte[] ticket = FileLocationToByteArray(fileinfo[0] + "cetk");
byte[] tmd = FileLocationToByteArray(fileinfo[0] + fileinfo[1]);
byte[] etitlekey = new byte[16]; byte[] etitlekey = new byte[16];
for (int a = 0; a < 16; a++) for (int a = 0; a < 16; a++)
{ {
@ -3036,9 +3040,87 @@ namespace NUS_Downloader
} }
initCrypt(iv, commonkey); initCrypt(iv, commonkey);
byte[] dtitlekey = Decrypt(etitlekey); TODO ADD THIS SUPPORT */ byte[] dtitlekey = Decrypt(etitlekey);
MessageBox.Show("Currently you can only add the bug to decrypted contents. Sorry!"); // Decrypt this content (determine index)
string[] tmdcontents = GetContentNames(tmd, ContentCount(tmd));
byte[] tmdindices = GetContentIndices(tmd, ContentCount(tmd));
byte[] tmdhashes = GetContentHashes(tmd, ContentCount(tmd));
string[] tmdsizes = GetContentSizes(tmd, ContentCount(tmd));
iv = new byte[16];
for (int e = 0; e < 16; e++)
{
iv[e] = 0x00;
}
byte[] hash = new byte[20];
for (int d = 0; d < tmdcontents.Length; d++)
{
if (tmdcontents[d] == filename)
{
iv[0] = 0x00; // TODO: Add double index byte support
iv[1] = tmdindices[d];
for (int x = 0; x < 20; x++)
{
hash[x] = tmdhashes[(d*20) + x];
}
}
}
initCrypt(iv, commonkey);
byte[] decContent = Decrypt(FileLocationToByteArray(fileinfo[0] + filename));
Array.Resize(ref decContent, int.Parse(tmdsizes[thiscontentidx], System.Globalization.NumberStyles.HexNumber));
if ((Convert.ToBase64String(ComputeSHA(decContent))) == Convert.ToBase64String(hash))
{
WriteStatus(" - Hash Check: Content is Unchanged...");
contents[c].SHAHash = hash;
//WriteStatus("HASH: " + DisplayBytes(hash, ""));
}
else
{
WriteStatus(" - Hash Check: Content changed (did you add an encrypted file from another title?)...");
contents[c].SHAHash = ComputeSHA(decContent);
}
// TODO PATCH HERE
// Re-encrypt
byte[] newiv = new byte[16];
for (int g = 0; g < newiv.Length; g++)
{
newiv[g] = 0x00;
}
byte[] smallix = NewIntegertoByteArray(c, 2);
ivindex[0] = smallix[0];
ivindex[1] = smallix[1];
//WriteStatus(" - Old Index: " + thiscontentidx + "; New Index: " + c);
// Pad back to 0x16 alignment
//AlignByteArray(decContent, 0x16
decContent = PadToMultipleOf(decContent, 16);
initCrypt(newiv, dtitlekey);
byte[] encContent = Encrypt(decContent);
File.Delete(fileinfo[0] + filename.Substring(0, 8));
FileStream encryptwrite = new FileStream(fileinfo[0] + filename.Substring(0, 8), FileMode.OpenOrCreate);
encryptwrite.Write(encContent, 0, encContent.Length);
encryptwrite.Close();
WriteStatus(" - Encrypted Content Again!");
// Patch content
// Probably leave decrypted
// Run an update through the TMD to update the contents
//MessageBox.Show("Currently you can only add the bug to decrypted contents. Sorry!");
} }
@ -3092,12 +3174,5 @@ namespace NUS_Downloader
} }
} }
} }
private void dlprogress_Click(object sender, EventArgs e)
{
// Enable BETA stuff?
truchabox.Enabled = !(truchabox.Enabled);
truchabox.Visible = !(truchabox.Visible);
}
} }
} }