Ran code through "Reorganization"...

This commit is contained in:
givememystuffplease 2010-07-04 03:24:51 +00:00
parent fb4ca758f2
commit 9bcd0eba18
2 changed files with 300 additions and 296 deletions

View File

@ -567,7 +567,6 @@
this.saveaswadbox.TabIndex = 43; this.saveaswadbox.TabIndex = 43;
this.saveaswadbox.Text = "SaveAs"; this.saveaswadbox.Text = "SaveAs";
this.saveaswadbox.UseVisualStyleBackColor = true; this.saveaswadbox.UseVisualStyleBackColor = true;
this.saveaswadbox.Paint += new System.Windows.Forms.PaintEventHandler(this.saveaswadbox_Paint);
// //
// deletecontentsbox // deletecontentsbox
// //

View File

@ -10,7 +10,6 @@ using System.ComponentModel;
using System.Threading; using System.Threading;
using System.Text; using System.Text;
using wyDay.Controls; using wyDay.Controls;
using System.Diagnostics; using System.Diagnostics;
@ -18,55 +17,86 @@ namespace NUS_Downloader
{ {
public partial class Form1 : Form public partial class Form1 : Form
{ {
const string NUSURL = "http://nus.cdn.shop.wii.com/ccs/download/"; private const string WII_NUS_URL = "http://nus.cdn.shop.wii.com/ccs/download/";
const string DSiNUSURL = "http://nus.cdn.t.shop.nintendowifi.net/ccs/download/"; private const string DSI_NUS_URL = "http://nus.cdn.t.shop.nintendowifi.net/ccs/download/";
// TODO: Always remember to change version! // TODO: Always remember to change version!
string version = "v1.5a Beta"; private string version = "v1.5a Beta";
WebClient generalWC = new WebClient(); private WebClient generalWC = new WebClient();
static RijndaelManaged rijndaelCipher; private static RijndaelManaged rijndaelCipher;
static bool dsidecrypt = false; private static bool dsidecrypt = false;
// Cross-thread Windows Formsing // Cross-thread Windows Formsing
delegate void AddToolStripItemToStripCallback(int type, ToolStripMenuItem additionitem, XmlAttributeCollection attributes); //TODO private delegate void AddToolStripItemToStripCallback(
delegate void WriteStatusCallback(string Update); int type, ToolStripMenuItem additionitem, XmlAttributeCollection attributes);
//TODO
private delegate void WriteStatusCallback(string Update);
// Images do not compare unless globalized... // Images do not compare unless globalized...
Image green = Properties.Resources.bullet_green; private Image green = Properties.Resources.bullet_green;
Image orange = Properties.Resources.bullet_orange; private Image orange = Properties.Resources.bullet_orange;
Image redorb = Properties.Resources.bullet_red; private Image redorb = Properties.Resources.bullet_red;
Image redgreen = Properties.Resources.bullet_redgreen; private Image redgreen = Properties.Resources.bullet_redgreen;
Image redorange = Properties.Resources.bullet_redorange; private Image redorange = Properties.Resources.bullet_redorange;
// Certs storage // Certs storage
byte[] cert_CA = new byte[0x400]; private byte[] cert_CA = new byte[0x400];
byte[] cert_CACP = new byte[0x300]; private byte[] cert_CACP = new byte[0x300];
byte[] cert_CAXS = new byte[0x300]; private byte[] cert_CAXS = new byte[0x300];
byte[] cert_CA_sha1 = new byte[20] {0x5B, 0x7D, 0x3E, 0xE2, 0x87, 0x06, 0xAD, 0x8D, 0xA2, 0xCB, 0xD5, 0xA6, 0xB7, 0x5C, 0x15, 0xD0, 0xF9, 0xB6, 0xF3, 0x18}; private byte[] cert_CA_sha1 = new byte[20]
byte[] cert_CACP_sha1 = new byte[20] {0x68, 0x24, 0xD6, 0xDA, 0x4C, 0x25, 0x18, 0x4F, 0x0D, 0x6D, 0xAF, 0x6E, 0xDB, 0x9C, 0x0F, 0xC5, 0x75, 0x22, 0xA4, 0x1C}; {
byte[] cert_CAXS_sha1 = new byte[20] {0x09, 0x78, 0x70, 0x45, 0x03, 0x71, 0x21, 0x47, 0x78, 0x24, 0xBC, 0x6A, 0x3E, 0x5E, 0x07, 0x61, 0x56, 0x57, 0x3F, 0x8A}; 0x5B, 0x7D, 0x3E, 0xE2, 0x87, 0x06, 0xAD, 0x8D, 0xA2, 0xCB, 0xD5, 0xA6, 0xB7,
0x5C, 0x15, 0xD0, 0xF9, 0xB6, 0xF3, 0x18
};
byte[] cert_total_sha1 = new byte[20] {0xAC, 0xE0, 0xF1, 0x5D, 0x2A, 0x85, 0x1C, 0x38, 0x3F, 0xE4, 0x65, 0x7A, 0xFC, 0x38, 0x40, 0xD6, 0xFF, 0xE3, 0x0A, 0xD0}; private byte[] cert_CACP_sha1 = new byte[20]
{
0x68, 0x24, 0xD6, 0xDA, 0x4C, 0x25, 0x18, 0x4F, 0x0D, 0x6D, 0xAF, 0x6E,
0xDB, 0x9C, 0x0F, 0xC5, 0x75, 0x22, 0xA4, 0x1C
};
string WAD_Saveas_Filename; private byte[] cert_CAXS_sha1 = new byte[20]
{
0x09, 0x78, 0x70, 0x45, 0x03, 0x71, 0x21, 0x47, 0x78, 0x24, 0xBC, 0x6A,
0x3E, 0x5E, 0x07, 0x61, 0x56, 0x57, 0x3F, 0x8A
};
private byte[] cert_total_sha1 = new byte[20]
{
0xAC, 0xE0, 0xF1, 0x5D, 0x2A, 0x85, 0x1C, 0x38, 0x3F, 0xE4, 0x65, 0x7A,
0xFC, 0x38, 0x40, 0xD6, 0xFF, 0xE3, 0x0A, 0xD0
};
private string WAD_Saveas_Filename;
// TODO: OOP scripting // TODO: OOP scripting
string script_filename; private string script_filename;
bool script_mode = false; private bool script_mode = false;
string[] nusentries; private string[] nusentries;
// Proxy stuff... // Proxy stuff...
string proxy_url; private string proxy_url;
string proxy_usr; private string proxy_usr;
string proxy_pwd; private string proxy_pwd;
// Database thread // Database thread
private BackgroundWorker fds; private BackgroundWorker fds;
// Common Key hash // Common Key hash
byte[] wii_commonkey_sha1 = new byte[20] { 0xEB, 0xEA, 0xE6, 0xD2, 0x76, 0x2D, 0x4D, 0x3E, 0xA1, 0x60, 0xA6, 0xD8, 0x32, 0x7F, 0xAC, 0x9A, 0x25, 0xF8, 0x06, 0x2B }; private byte[] wii_commonkey_sha1 = new byte[20]
byte[] wii_commonkey_sha1_asstring = new byte[20] { 0x56, 0xdd, 0x4e, 0xb3, 0x59, 0x75, 0xc2, 0xfd, 0x5a, 0xe8, 0xba, 0x8c, 0x7d, 0x89, 0x9a, 0xc5, 0xe6, 0x17, 0x54, 0x19 }; {
0xEB, 0xEA, 0xE6, 0xD2, 0x76, 0x2D, 0x4D, 0x3E, 0xA1, 0x60, 0xA6, 0xD8,
0x32, 0x7F, 0xAC, 0x9A, 0x25, 0xF8, 0x06, 0x2B
};
private byte[] wii_commonkey_sha1_asstring = new byte[20]
{
0x56, 0xdd, 0x4e, 0xb3, 0x59, 0x75, 0xc2, 0xfd, 0x5a, 0xe8,
0xba, 0x8c, 0x7d, 0x89, 0x9a, 0xc5, 0xe6, 0x17, 0x54, 0x19
};
/* /*
public struct WADHeader public struct WADHeader
{ {
@ -89,8 +119,10 @@ namespace NUS_Downloader
public byte[] SHAHash; public byte[] SHAHash;
} ; } ;
public enum ContentTypes : int { public enum ContentTypes : int
Shared = 0x8001, Normal = 0x0001 {
Shared = 0x8001,
Normal = 0x0001
} }
// This is the standard entry to the GUI // This is the standard entry to the GUI
@ -241,10 +273,13 @@ namespace NUS_Downloader
else else
{ {
WriteStatus("Common Key detected."); WriteStatus("Common Key detected.");
if ((Convert.ToBase64String(ComputeSHA(LoadCommonKey("key.bin")))) != (Convert.ToBase64String(wii_commonkey_sha1))) if ((Convert.ToBase64String(ComputeSHA(LoadCommonKey("key.bin")))) !=
{ // Hmm, seems to be a bad hash (Convert.ToBase64String(wii_commonkey_sha1)))
{
// Hmm, seems to be a bad hash
// Let's check if it matches the hex string version... // Let's check if it matches the hex string version...
if ((Convert.ToBase64String(ComputeSHA(LoadCommonKey("key.bin")))) != (Convert.ToBase64String(wii_commonkey_sha1_asstring))) if ((Convert.ToBase64String(ComputeSHA(LoadCommonKey("key.bin")))) !=
(Convert.ToBase64String(wii_commonkey_sha1_asstring)))
WriteStatus(" - (PS: Your common key isn't hashing right!)"); WriteStatus(" - (PS: Your common key isn't hashing right!)");
else else
{ {
@ -304,8 +339,10 @@ namespace NUS_Downloader
{ {
proxy_usr = proxy_file[1]; proxy_usr = proxy_file[1];
SetAllEnabled(false); SetAllEnabled(false);
ProxyVerifyBox.Visible = true; ProxyVerifyBox.Enabled = true; ProxyVerifyBox.Visible = true;
ProxyPwdBox.Enabled = true; SaveProxyBtn.Enabled = true; ProxyVerifyBox.Enabled = true;
ProxyPwdBox.Enabled = true;
SaveProxyBtn.Enabled = true;
ProxyVerifyBox.Select(); ProxyVerifyBox.Select();
} }
} }
@ -435,7 +472,9 @@ namespace NUS_Downloader
// Loop through each content and display name, hash, index // Loop through each content and display name, hash, index
for (int i = 0; i < nbr_cont; i++) for (int i = 0; i < nbr_cont; i++)
{ {
WriteStatus(" Content " + (i + 1) + ": " + tmdcontents[i] + " (" + Convert.ToString(int.Parse(tmdsizes[i], System.Globalization.NumberStyles.HexNumber)) + " bytes)"); WriteStatus(" Content " + (i + 1) + ": " + tmdcontents[i] + " (" +
Convert.ToString(int.Parse(tmdsizes[i], System.Globalization.NumberStyles.HexNumber)) +
" bytes)");
byte[] hash = new byte[20]; byte[] hash = new byte[20];
for (int x = 0; x < 20; x++) for (int x = 0; x < 20; x++)
{ {
@ -458,7 +497,8 @@ namespace NUS_Downloader
string sysversion = ""; string sysversion = "";
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
sysversion += MakeProperLength(ConvertToHex(Convert.ToString(tmd[0x184 + i]))); sysversion += MakeProperLength(ConvertToHex(Convert.ToString(tmd[0x184 + i])));
sysversion = Convert.ToString(int.Parse(sysversion.Substring(14, 2), System.Globalization.NumberStyles.HexNumber)); sysversion =
Convert.ToString(int.Parse(sysversion.Substring(14, 2), System.Globalization.NumberStyles.HexNumber));
return sysversion; return sysversion;
} }
@ -844,7 +884,8 @@ namespace NUS_Downloader
// Current directory... // Current directory...
string currentdir = Directory.GetCurrentDirectory(); string currentdir = Directory.GetCurrentDirectory();
if (!(currentdir.EndsWith(Path.DirectorySeparatorChar.ToString())) || !(currentdir.EndsWith(Path.AltDirectorySeparatorChar.ToString()))) if (!(currentdir.EndsWith(Path.DirectorySeparatorChar.ToString())) ||
!(currentdir.EndsWith(Path.AltDirectorySeparatorChar.ToString())))
currentdir += Path.DirectorySeparatorChar.ToString(); currentdir += Path.DirectorySeparatorChar.ToString();
// Prevent crossthread issues // Prevent crossthread issues
@ -899,7 +940,6 @@ namespace NUS_Downloader
{ {
// Windows 7 Taskbar progress can be used. // Windows 7 Taskbar progress can be used.
dlprogress.ShowInTaskbar = true; dlprogress.ShowInTaskbar = true;
} }
// Download TMD before the rest... // Download TMD before the rest...
@ -912,7 +952,6 @@ namespace NUS_Downloader
} }
catch (Exception ex) catch (Exception ex)
{ {
WriteStatus("Download Failed: " + tmdfull); WriteStatus("Download Failed: " + tmdfull);
WriteStatus(" - Reason: " + ex.Message.ToString().Replace("The remote server returned an error: ", "")); WriteStatus(" - Reason: " + ex.Message.ToString().Replace("The remote server returned an error: ", ""));
SetEnableforDownload(true); SetEnableforDownload(true);
@ -935,7 +974,8 @@ namespace NUS_Downloader
if (ignoreticket.Checked == false) if (ignoreticket.Checked == false)
{ {
WriteStatus("Download Failed: cetk"); WriteStatus("Download Failed: cetk");
WriteStatus(" - Reason: " + ex.Message.ToString().Replace("The remote server returned an error: ", "")); WriteStatus(" - Reason: " +
ex.Message.ToString().Replace("The remote server returned an error: ", ""));
WriteStatus("You may be able to retrieve the contents by Ignoring the Ticket (Check below)"); WriteStatus("You may be able to retrieve the contents by Ignoring the Ticket (Check below)");
SetEnableforDownload(true); SetEnableforDownload(true);
downloadstartbtn.Text = "Start NUS Download!"; downloadstartbtn.Text = "Start NUS Download!";
@ -1079,13 +1119,15 @@ namespace NUS_Downloader
} }
else else
{ {
DownloadNUSFile(titleid, tmdcontents[i], titledirectory, int.Parse(tmdsizes[i], System.Globalization.NumberStyles.HexNumber), wiimode); DownloadNUSFile(titleid, tmdcontents[i], titledirectory,
int.Parse(tmdsizes[i], System.Globalization.NumberStyles.HexNumber), wiimode);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
WriteStatus("Download Failed: " + tmdcontents[i]); WriteStatus("Download Failed: " + tmdcontents[i]);
WriteStatus(" - Reason: " + ex.Message.ToString().Replace("The remote server returned an error: ", "")); WriteStatus(" - Reason: " +
ex.Message.ToString().Replace("The remote server returned an error: ", ""));
SetEnableforDownload(true); SetEnableforDownload(true);
downloadstartbtn.Text = "Start NUS Download!"; downloadstartbtn.Text = "Start NUS Download!";
dlprogress.Value = 0; dlprogress.Value = 0;
@ -1094,14 +1136,16 @@ namespace NUS_Downloader
} }
// Progress reporting advances... // Progress reporting advances...
downloadstartbtn.Text = "Content: (" + (i + 1) + Path.AltDirectorySeparatorChar.ToString() + contentstrnum + ")"; downloadstartbtn.Text = "Content: (" + (i + 1) + Path.AltDirectorySeparatorChar.ToString() +
contentstrnum + ")";
currentcontentlocation += int.Parse(tmdsizes[i], System.Globalization.NumberStyles.HexNumber); currentcontentlocation += int.Parse(tmdsizes[i], System.Globalization.NumberStyles.HexNumber);
// Decrypt stuff... // Decrypt stuff...
if (decryptbox.Checked == true) if (decryptbox.Checked == true)
{ {
// Create content file holder // Create content file holder
byte[] contbuf = FileLocationToByteArray(titledirectory + Path.DirectorySeparatorChar.ToString() + tmdcontents[i]); byte[] contbuf =
FileLocationToByteArray(titledirectory + Path.DirectorySeparatorChar.ToString() + tmdcontents[i]);
// IV (00+IDX+more000) // IV (00+IDX+more000)
byte[] iv = new byte[16]; byte[] iv = new byte[16];
@ -1120,7 +1164,10 @@ namespace NUS_Downloader
decfs.Close(); decfs.Close();
WriteStatus(" - Decrypted: " + zeros + i.ToString("X2") + ".app"); */ WriteStatus(" - Decrypted: " + zeros + i.ToString("X2") + ".app"); */
FileStream decfs = new FileStream(titledirectory + Path.DirectorySeparatorChar.ToString() + tmdcontents[i] + ".app", FileMode.Create); FileStream decfs =
new FileStream(
titledirectory + Path.DirectorySeparatorChar.ToString() + tmdcontents[i] + ".app",
FileMode.Create);
decfs.Write(Decrypt(contbuf), 0, int.Parse(tmdsizes[i], System.Globalization.NumberStyles.HexNumber)); decfs.Write(Decrypt(contbuf), 0, int.Parse(tmdsizes[i], System.Globalization.NumberStyles.HexNumber));
decfs.Close(); decfs.Close();
WriteStatus(" - Decrypted: " + tmdcontents[i] + ".app"); WriteStatus(" - Decrypted: " + tmdcontents[i] + ".app");
@ -1164,7 +1211,6 @@ namespace NUS_Downloader
if (script_mode) if (script_mode)
statusbox.Text = ""; statusbox.Text = "";
} }
/// <summary> /// <summary>
@ -1182,7 +1228,9 @@ namespace NUS_Downloader
if (titleversion.Text == "") if (titleversion.Text == "")
titledirectory = Path.Combine(currentdir, titleidbox.Text + Path.DirectorySeparatorChar.ToString()); titledirectory = Path.Combine(currentdir, titleidbox.Text + Path.DirectorySeparatorChar.ToString());
else else
titledirectory = Path.Combine(currentdir, titleidbox.Text + "v" + titleversion.Text + Path.DirectorySeparatorChar.ToString()); titledirectory = Path.Combine(currentdir,
titleidbox.Text + "v" + titleversion.Text +
Path.DirectorySeparatorChar.ToString());
// Keep local directory if present and checked out... // Keep local directory if present and checked out...
if ((localuse.Checked) && (Directory.Exists(titledirectory))) if ((localuse.Checked) && (Directory.Exists(titledirectory)))
@ -1212,7 +1260,9 @@ namespace NUS_Downloader
if (titleversion.Text == "") if (titleversion.Text == "")
titledirectory = Path.Combine(currentdir, titleidbox.Text + Path.DirectorySeparatorChar.ToString()); titledirectory = Path.Combine(currentdir, titleidbox.Text + Path.DirectorySeparatorChar.ToString());
else else
titledirectory = Path.Combine(currentdir, titleidbox.Text + "v" + titleversion.Text + Path.DirectorySeparatorChar.ToString()); titledirectory = Path.Combine(currentdir,
titleidbox.Text + "v" + titleversion.Text +
Path.DirectorySeparatorChar.ToString());
if (Directory.Exists(titledirectory)) if (Directory.Exists(titledirectory))
Directory.Delete(titledirectory, true); Directory.Delete(titledirectory, true);
@ -1228,14 +1278,15 @@ namespace NUS_Downloader
/// <param name="placementdir">The placementdir.</param> /// <param name="placementdir">The placementdir.</param>
/// <param name="sizeinbytes">The sizeinbytes.</param> /// <param name="sizeinbytes">The sizeinbytes.</param>
/// <param name="iswiititle">if set to <c>true</c> [iswiititle].</param> /// <param name="iswiititle">if set to <c>true</c> [iswiititle].</param>
private void DownloadNUSFile(string titleid, string filename, string placementdir, int sizeinbytes, bool iswiititle) private void DownloadNUSFile(string titleid, string filename, string placementdir, int sizeinbytes,
bool iswiititle)
{ {
// Create NUS URL... // Create NUS URL...
string nusfileurl; string nusfileurl;
if (iswiititle) if (iswiititle)
nusfileurl = NUSURL + titleid + Path.AltDirectorySeparatorChar.ToString() + filename; nusfileurl = WII_NUS_URL + titleid + Path.AltDirectorySeparatorChar.ToString() + filename;
else else
nusfileurl = DSiNUSURL + titleid + Path.AltDirectorySeparatorChar.ToString() + filename; nusfileurl = DSI_NUS_URL + titleid + Path.AltDirectorySeparatorChar.ToString() + filename;
WriteStatus("Grabbing " + filename + "..."); WriteStatus("Grabbing " + filename + "...");
@ -1247,7 +1298,7 @@ namespace NUS_Downloader
generalWC.DownloadFile(nusfileurl, placementdir + filename); generalWC.DownloadFile(nusfileurl, placementdir + filename);
} }
void StatusChange(string status) private void StatusChange(string status)
{ {
WriteStatus(status); WriteStatus(status);
} }
@ -1264,7 +1315,8 @@ namespace NUS_Downloader
// Obtain Current Directory // Obtain Current Directory
string currentdir = Directory.GetCurrentDirectory(); string currentdir = Directory.GetCurrentDirectory();
if (!(currentdir.EndsWith(Path.DirectorySeparatorChar.ToString())) || !(currentdir.EndsWith(Path.AltDirectorySeparatorChar.ToString()))) if (!(currentdir.EndsWith(Path.DirectorySeparatorChar.ToString())) ||
!(currentdir.EndsWith(Path.AltDirectorySeparatorChar.ToString())))
currentdir += Path.DirectorySeparatorChar.ToString(); currentdir += Path.DirectorySeparatorChar.ToString();
// Create instance of WAD Packing class // Create instance of WAD Packing class
@ -1312,7 +1364,8 @@ namespace NUS_Downloader
} }
else else
{ {
string wad_filename = totaldirectory + Path.DirectorySeparatorChar.ToString() + RemoveIllegalCharacters(wadnamebox.Text); string wad_filename = totaldirectory + Path.DirectorySeparatorChar.ToString() +
RemoveIllegalCharacters(wadnamebox.Text);
packer.Directory = totaldirectory; packer.Directory = totaldirectory;
packer.FileName = System.IO.Path.GetFileName(wad_filename); packer.FileName = System.IO.Path.GetFileName(wad_filename);
} }
@ -1347,6 +1400,7 @@ namespace NUS_Downloader
} }
} }
/*
/// <summary> /// <summary>
/// Returns next 0x40 padded length. /// Returns next 0x40 padded length.
/// </summary> /// </summary>
@ -1386,7 +1440,7 @@ namespace NUS_Downloader
Array.Reverse(b); Array.Reverse(b);
return b; return b;
} }*/
private void consoleCBox_SelectedIndexChanged(object sender, EventArgs e) private void consoleCBox_SelectedIndexChanged(object sender, EventArgs e)
{ {
@ -1474,7 +1528,6 @@ namespace NUS_Downloader
wadnamebox.Enabled = false; wadnamebox.Enabled = false;
wadnamebox.Text = ""; wadnamebox.Text = "";
} }
} }
private void titleidbox_TextChanged(object sender, EventArgs e) private void titleidbox_TextChanged(object sender, EventArgs e)
@ -1578,7 +1631,7 @@ namespace NUS_Downloader
/// </summary> /// </summary>
/// <param name="data">A byte[].</param> /// <param name="data">A byte[].</param>
/// <returns></returns> /// <returns></returns>
static public byte[] ComputeSHA(byte[] data) public static byte[] ComputeSHA(byte[] data)
{ {
SHA1 sha = new SHA1CryptoServiceProvider(); SHA1 sha = new SHA1CryptoServiceProvider();
// This is one implementation of the abstract class SHA1. // This is one implementation of the abstract class SHA1.
@ -1594,7 +1647,8 @@ namespace NUS_Downloader
{ {
// Directory stuff // Directory stuff
string currentdir = Directory.GetCurrentDirectory(); string currentdir = Directory.GetCurrentDirectory();
if (!(currentdir.EndsWith(Path.DirectorySeparatorChar.ToString())) || !(currentdir.EndsWith(Path.AltDirectorySeparatorChar.ToString()))) if (!(currentdir.EndsWith(Path.DirectorySeparatorChar.ToString())) ||
!(currentdir.EndsWith(Path.AltDirectorySeparatorChar.ToString())))
currentdir += Path.DirectorySeparatorChar.ToString(); currentdir += Path.DirectorySeparatorChar.ToString();
if (File.Exists(currentdir + keyfile) == true) if (File.Exists(currentdir + keyfile) == true)
@ -1699,6 +1753,7 @@ namespace NUS_Downloader
// Okay, so now report the progress... // Okay, so now report the progress...
rnt = rnt + 1; rnt = rnt + 1;
float currentProgress = ((float) rnt/(float) totalLength)*(float) 100; float currentProgress = ((float) rnt/(float) totalLength)*(float) 100;
if (Convert.ToInt16(Math.Round(currentProgress))%10 == 0)
worker.ReportProgress(Convert.ToInt16(Math.Round(currentProgress))); worker.ReportProgress(Convert.ToInt16(Math.Round(currentProgress)));
// Lol. // Lol.
@ -1716,7 +1771,8 @@ namespace NUS_Downloader
break; break;
case "titleIDs": case "titleIDs":
updateScript = ChildrenOfTheNode[z].InnerText; updateScript = ChildrenOfTheNode[z].InnerText;
XMLToolStripItem.AccessibleDescription = updateScript; // TODO: Find somewhere better to put this. AND FAST. XMLToolStripItem.AccessibleDescription = updateScript;
// TODO: Find somewhere better to put this. AND FAST.
break; break;
case "version": case "version":
string[] versions = ChildrenOfTheNode[z].InnerText.Split(','); string[] versions = ChildrenOfTheNode[z].InnerText.Split(',');
@ -1727,13 +1783,15 @@ namespace NUS_Downloader
{ {
if (ChildrenOfTheNode[z].InnerText != "") if (ChildrenOfTheNode[z].InnerText != "")
{ {
ToolStripMenuItem regitem = (ToolStripMenuItem)XMLToolStripItem.DropDownItems[b]; ToolStripMenuItem regitem =
(ToolStripMenuItem) XMLToolStripItem.DropDownItems[b];
regitem.DropDownItems.Add("Latest Version"); regitem.DropDownItems.Add("Latest Version");
for (int y = 0; y < versions.Length; y++) for (int y = 0; y < versions.Length; y++)
{ {
regitem.DropDownItems.Add("v" + versions[y]); regitem.DropDownItems.Add("v" + versions[y]);
} }
regitem.DropDownItemClicked += new ToolStripItemClickedEventHandler(deepitem_clicked); regitem.DropDownItemClicked +=
new ToolStripItemClickedEventHandler(deepitem_clicked);
} }
} }
} }
@ -1755,7 +1813,8 @@ namespace NUS_Downloader
{ {
for (int y = 0; y < regions.Length; y++) for (int y = 0; y < regions.Length; y++)
{ {
XMLToolStripItem.DropDownItems.Add(RegionFromIndex(Convert.ToInt32(regions[y]), xDoc)); XMLToolStripItem.DropDownItems.Add(RegionFromIndex(Convert.ToInt32(regions[y]),
xDoc));
} }
} }
break; break;
@ -1791,9 +1850,9 @@ namespace NUS_Downloader
/// <param name="type">The type.</param> /// <param name="type">The type.</param>
/// <param name="additionitem">The additionitem.</param> /// <param name="additionitem">The additionitem.</param>
/// <param name="attributes">The attributes.</param> /// <param name="attributes">The attributes.</param>
void AddToolStripItemToStrip(int type, ToolStripMenuItem additionitem, XmlAttributeCollection attributes) private void AddToolStripItemToStrip(int type, ToolStripMenuItem additionitem, XmlAttributeCollection attributes)
{ {
Debug.WriteLine("Adding item..."); Debug.WriteLine(String.Format("Adding item (Type: {0})...", type));
// Check if thread-safe // Check if thread-safe
if (this.InvokeRequired) if (this.InvokeRequired)
{ {
@ -1891,7 +1950,7 @@ namespace NUS_Downloader
} }
} }
void deepitem_clicked(object sender, ToolStripItemClickedEventArgs e) private void deepitem_clicked(object sender, ToolStripItemClickedEventArgs e)
{ {
titleidbox.Text = e.ClickedItem.OwnerItem.OwnerItem.Text.Substring(0, 16); titleidbox.Text = e.ClickedItem.OwnerItem.OwnerItem.Text.Substring(0, 16);
titleidbox.Text = titleidbox.Text.Replace("XX", e.ClickedItem.OwnerItem.Text.Substring(0, 2)); titleidbox.Text = titleidbox.Text.Replace("XX", e.ClickedItem.OwnerItem.Text.Substring(0, 2));
@ -1912,11 +1971,14 @@ namespace NUS_Downloader
} }
// Prepare StatusBox... // Prepare StatusBox...
string titlename = e.ClickedItem.OwnerItem.OwnerItem.Text.Substring(19, (e.ClickedItem.OwnerItem.OwnerItem.Text.Length - 19)); string titlename = e.ClickedItem.OwnerItem.OwnerItem.Text.Substring(19,
(e.ClickedItem.OwnerItem.OwnerItem.Text.
Length - 19));
statusbox.Text = " --- " + titlename + " ---"; statusbox.Text = " --- " + titlename + " ---";
// Check if a ticket is present... // Check if a ticket is present...
if ((e.ClickedItem.OwnerItem.OwnerItem.Image) == (orange) || (e.ClickedItem.OwnerItem.OwnerItem.Image) == (redorange)) if ((e.ClickedItem.OwnerItem.OwnerItem.Image) == (orange) ||
(e.ClickedItem.OwnerItem.OwnerItem.Image) == (redorange))
{ {
ignoreticket.Checked = true; ignoreticket.Checked = true;
WriteStatus("Note: This title has no ticket and cannot be packed/decrypted!"); WriteStatus("Note: This title has no ticket and cannot be packed/decrypted!");
@ -1935,7 +1997,8 @@ namespace NUS_Downloader
} }
// Check for danger item // Check for danger item
if ((e.ClickedItem.OwnerItem.OwnerItem.Image) == (redgreen) || (e.ClickedItem.OwnerItem.OwnerItem.Image) == (redorange)) if ((e.ClickedItem.OwnerItem.OwnerItem.Image) == (redgreen) ||
(e.ClickedItem.OwnerItem.OwnerItem.Image) == (redorange))
{ {
WriteStatus("\r\n" + e.ClickedItem.OwnerItem.OwnerItem.ToolTipText); WriteStatus("\r\n" + e.ClickedItem.OwnerItem.OwnerItem.ToolTipText);
} }
@ -1970,7 +2033,7 @@ namespace NUS_Downloader
wadnamebox.Text = wadnamebox.Text.Replace("[v]", "v" + titleversion.Text); wadnamebox.Text = wadnamebox.Text.Replace("[v]", "v" + titleversion.Text);
} }
void wwitem_regionclicked(object sender, ToolStripItemClickedEventArgs e) private void wwitem_regionclicked(object sender, ToolStripItemClickedEventArgs e)
{ {
titleidbox.Text = e.ClickedItem.OwnerItem.Text.Substring(0, 16); titleidbox.Text = e.ClickedItem.OwnerItem.Text.Substring(0, 16);
titleversion.Text = ""; titleversion.Text = "";
@ -2006,14 +2069,15 @@ namespace NUS_Downloader
} }
} }
void upditem_itemclicked(object sender, ToolStripItemClickedEventArgs e) private void upditem_itemclicked(object sender, ToolStripItemClickedEventArgs e)
{ {
WriteStatus("Preparing to run download script..."); WriteStatus("Preparing to run download script...");
Control.CheckForIllegalCrossThreadCalls = false; Control.CheckForIllegalCrossThreadCalls = false;
script_mode = true; script_mode = true;
statusbox.Text = ""; statusbox.Text = "";
WriteStatus("Starting script download. Please be patient!"); WriteStatus("Starting script download. Please be patient!");
string[] NUS_Entries = e.ClickedItem.AccessibleDescription.Split('\n'); // TODO: Find somewhere better to put this. AND FAST! string[] NUS_Entries = e.ClickedItem.AccessibleDescription.Split('\n');
// TODO: Find somewhere better to put this. AND FAST!
for (int i = 0; i < NUS_Entries.Length; i++) for (int i = 0; i < NUS_Entries.Length; i++)
{ {
WriteStatus(NUS_Entries[i]); WriteStatus(NUS_Entries[i]);
@ -2026,7 +2090,7 @@ namespace NUS_Downloader
} }
void sysitem_versionclicked(object sender, ToolStripItemClickedEventArgs e) private void sysitem_versionclicked(object sender, ToolStripItemClickedEventArgs e)
{ {
titleidbox.Text = e.ClickedItem.OwnerItem.Text.Substring(0, 16); titleidbox.Text = e.ClickedItem.OwnerItem.Text.Substring(0, 16);
@ -2091,7 +2155,7 @@ namespace NUS_Downloader
/// <param name="index">The index.</param> /// <param name="index">The index.</param>
/// <param name="databasexml">XmlDocument with database inside</param> /// <param name="databasexml">XmlDocument with database inside</param>
/// <returns>Region desc</returns> /// <returns>Region desc</returns>
string RegionFromIndex(int index, XmlDocument databasexml) private string RegionFromIndex(int index, XmlDocument databasexml)
{ {
/* Typical Region XML /* Typical Region XML
* <REGIONS> * <REGIONS>
@ -2157,7 +2221,7 @@ namespace NUS_Downloader
/// </summary> /// </summary>
/// <param name="databasestr">removes the illegal chars</param> /// <param name="databasestr">removes the illegal chars</param>
/// <returns>legal string</returns> /// <returns>legal string</returns>
private string RemoveIllegalCharacters(string databasestr) private static string RemoveIllegalCharacters(string databasestr)
{ {
// Database strings must contain filename-legal characters. // Database strings must contain filename-legal characters.
foreach (char illegalchar in System.IO.Path.GetInvalidFileNameChars()) foreach (char illegalchar in System.IO.Path.GetInvalidFileNameChars())
@ -2168,67 +2232,13 @@ namespace NUS_Downloader
return databasestr; return databasestr;
} }
/// <summary>
/// Zeroes the signature in TMD/TIK.
/// </summary>
/// <param name="tmdortik">TMD/TIK</param>
/// <returns>Zeroed TMD/TIK</returns>
private byte[] ZeroSignature(byte[] tmdortik)
{
// Write all 0x00 to signature...
// Sig starts at 0x04 in both TMD/TIK
for (int i = 0; i < 256; i++)
{
tmdortik[i + 4] = 0x00;
}
WriteStatus(" - Signature Emptied...");
return tmdortik;
}
/// <summary>
/// Trucha Signs a TMD/TIK
/// </summary>
/// <param name="tmdortik">The tmdortik.</param>
/// <returns>Fake-signed byte[]</returns>
private byte[] TruchaSign(byte[] tmdortik)
{
// Loop through 2 bytes worth of numbers until hash starts with 0x00...
// Padding starts at 0x104 in both TMD/TIK, seems like a good place to me...
byte[] payload = new byte[2];
byte[] hashobject = new byte[tmdortik.Length - 0x104];
for (int i = 0; i < 65535; i++)
{
payload = incrementAtIndex(payload, 1);
tmdortik[0x104] = payload[0];
tmdortik[0x105] = payload[1];
for (int x = 0; x < (tmdortik.Length - 0x104); x++)
{
hashobject[x] = tmdortik[0x104 + x];
}
if (ComputeSHA(hashobject)[0] == 0x00)
{
WriteStatus(" - Successfully Trucha Signed.");
return tmdortik;
}
}
WriteStatus(" - Sign FAIL!");
return tmdortik;
}
/// <summary> /// <summary>
/// Increments at an index. /// Increments at an index.
/// </summary> /// </summary>
/// <param name="array">The array.</param> /// <param name="array">The array.</param>
/// <param name="index">The index.</param> /// <param name="index">The index.</param>
/// <returns></returns> /// <returns></returns>
static public byte[] incrementAtIndex(byte[] array, int index) public static byte[] incrementAtIndex(byte[] array, int index)
{ {
if (array[index] == byte.MaxValue) if (array[index] == byte.MaxValue)
{ {
@ -2286,7 +2296,6 @@ namespace NUS_Downloader
{ {
// Do nothing, some objects will not cast. // Do nothing, some objects will not cast.
} }
} }
} }
@ -2360,7 +2369,6 @@ namespace NUS_Downloader
} }
} }
wadnamebox.Text = RemoveIllegalCharacters(wadnamebox.Text); wadnamebox.Text = RemoveIllegalCharacters(wadnamebox.Text);
} }
/// <summary> /// <summary>
@ -2374,10 +2382,15 @@ namespace NUS_Downloader
byte[] Ticket = new byte[0x2A4]; byte[] Ticket = new byte[0x2A4];
// RSA Signature Heading... // RSA Signature Heading...
Ticket[1] = 0x01; Ticket[3] = 0x01; Ticket[1] = 0x01;
Ticket[3] = 0x01;
// Signature Issuer... (Root-CA00000001-XS00000003) // Signature Issuer... (Root-CA00000001-XS00000003)
byte[] SignatureIssuer = new byte[0x1A] { 0x52, 0x6F, 0x6F, 0x74, 0x2D, 0x43, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x2D, 0x58, 0x53, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x33 }; byte[] SignatureIssuer = new byte[0x1A]
{
0x52, 0x6F, 0x6F, 0x74, 0x2D, 0x43, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
0x30, 0x31, 0x2D, 0x58, 0x53, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x33
};
for (int a = 0; a < 0x40; a++) for (int a = 0; a < 0x40; a++)
{ {
Ticket[0x140 + a] = SignatureIssuer[a]; Ticket[0x140 + a] = SignatureIssuer[a];
@ -2402,8 +2415,10 @@ namespace NUS_Downloader
} }
// Misc FF... // Misc FF...
Ticket[0x1E4] = 0xFF; Ticket[0x1E5] = 0xFF; Ticket[0x1E4] = 0xFF;
Ticket[0x1E6] = 0xFF; Ticket[0x1E7] = 0xFF; Ticket[0x1E5] = 0xFF;
Ticket[0x1E6] = 0xFF;
Ticket[0x1E7] = 0xFF;
// Unknown 0x01... // Unknown 0x01...
Ticket[0x221] = 0x01; Ticket[0x221] = 0x01;
@ -2427,12 +2442,6 @@ namespace NUS_Downloader
return System.Text.RegularExpressions.Regex.IsMatch(test, @"\A\b[0-9a-fA-F]+\b\Z"); return System.Text.RegularExpressions.Regex.IsMatch(test, @"\A\b[0-9a-fA-F]+\b\Z");
} }
/// <summary> /// <summary>
/// Pads to multiple of.... /// Pads to multiple of....
/// </summary> /// </summary>
@ -2447,11 +2456,6 @@ namespace NUS_Downloader
return src; return src;
} }
/// <summary> /// <summary>
/// Determines whether OS is win7. /// Determines whether OS is win7.
/// </summary> /// </summary>
@ -2470,7 +2474,6 @@ namespace NUS_Downloader
for (int i = arrayLen - 1; i >= 0; i--) for (int i = arrayLen - 1; i >= 0; i--)
{ {
resultArray[i] = (byte) ((theInt >> (8*i)) & 0xFF); resultArray[i] = (byte) ((theInt >> (8*i)) & 0xFF);
} }
Array.Reverse(resultArray); Array.Reverse(resultArray);
@ -2486,7 +2489,6 @@ namespace NUS_Downloader
} }
/// <summary> /// <summary>
/// Does byte[] contain byte[]? /// Does byte[] contain byte[]?
/// </summary> /// </summary>
@ -2552,7 +2554,9 @@ namespace NUS_Downloader
databasedl.UseDefaultCredentials = true; databasedl.UseDefaultCredentials = true;
} }
string wiibrewsource = databasedl.DownloadString("http://www.wiibrew.org/wiki/NUS_Downloader/database?cachesmash=" + System.DateTime.Now.ToString()); string wiibrewsource =
databasedl.DownloadString("http://www.wiibrew.org/wiki/NUS_Downloader/database?cachesmash=" +
System.DateTime.Now.ToString());
//statusbox.Refresh(); //statusbox.Refresh();
// Strip out HTML // Strip out HTML
@ -2561,7 +2565,8 @@ namespace NUS_Downloader
// Shrink to fix only the database // Shrink to fix only the database
string startofdatabase = "&lt;database v"; string startofdatabase = "&lt;database v";
string endofdatabase = "&lt;/database&gt;"; string endofdatabase = "&lt;/database&gt;";
wiibrewsource = wiibrewsource.Substring(wiibrewsource.IndexOf(startofdatabase), wiibrewsource.Length - wiibrewsource.IndexOf(startofdatabase)); wiibrewsource = wiibrewsource.Substring(wiibrewsource.IndexOf(startofdatabase),
wiibrewsource.Length - wiibrewsource.IndexOf(startofdatabase));
wiibrewsource = wiibrewsource.Substring(0, wiibrewsource.IndexOf(endofdatabase) + endofdatabase.Length); wiibrewsource = wiibrewsource.Substring(0, wiibrewsource.IndexOf(endofdatabase) + endofdatabase.Length);
// Fix ", <, >, and spaces // Fix ", <, >, and spaces
@ -2576,7 +2581,6 @@ namespace NUS_Downloader
private void RetrieveNewDatabase_Completed(object sender, RunWorkerCompletedEventArgs e) private void RetrieveNewDatabase_Completed(object sender, RunWorkerCompletedEventArgs e)
{ {
string database = e.Result.ToString(); string database = e.Result.ToString();
string currentversion = GetDatabaseVersion("database.xml"); string currentversion = GetDatabaseVersion("database.xml");
string onlineversion = GetDatabaseVersion(database); string onlineversion = GetDatabaseVersion(database);
@ -2623,7 +2627,6 @@ namespace NUS_Downloader
{ {
WriteStatus("Database successfully updated!"); WriteStatus("Database successfully updated!");
} }
} }
private void updateDatabaseToolStripMenuItem_Click(object sender, EventArgs e) private void updateDatabaseToolStripMenuItem_Click(object sender, EventArgs e)
@ -2654,7 +2657,9 @@ namespace NUS_Downloader
/// <returns></returns> /// <returns></returns>
public string SendSOAPRequest(string soap_xml) public string SendSOAPRequest(string soap_xml)
{ {
System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("http://nus.shop.wii.com:80/nus/services/NetUpdateSOAP"); System.Net.HttpWebRequest req =
(System.Net.HttpWebRequest)
System.Net.HttpWebRequest.Create("http://nus.shop.wii.com:80/nus/services/NetUpdateSOAP");
req.Method = "POST"; req.Method = "POST";
req.UserAgent = "wii libnup/1.0"; req.UserAgent = "wii libnup/1.0";
req.Headers.Add("SOAPAction", '"' + "urn:nus.wsapi.broadon.com/" + '"'); req.Headers.Add("SOAPAction", '"' + "urn:nus.wsapi.broadon.com/" + '"');
@ -2716,7 +2721,6 @@ namespace NUS_Downloader
return ex.Message.ToString(); return ex.Message.ToString();
} }
} }
private void emulateUpdate_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) private void emulateUpdate_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
@ -2746,11 +2750,14 @@ namespace NUS_Downloader
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
"<soapenv:Body>\n<GetSystemUpdateRequest xmlns=\"urn:nus.wsapi.broadon.com\">\n" + "<soapenv:Body>\n<GetSystemUpdateRequest xmlns=\"urn:nus.wsapi.broadon.com\">\n" +
"<Version>1.0</Version>\n<MessageId>" + messageID + "</MessageId>\n<DeviceId>" + deviceID + "</DeviceId>\n" + "<Version>1.0</Version>\n<MessageId>" + messageID + "</MessageId>\n<DeviceId>" + deviceID +
"<RegionId>" + RegionID + "</RegionId>\n<CountryCode>" + CountryCode + "</CountryCode>\n<TitleVersion>\n<TitleId>0000000100000001</TitleId>\n" + "</DeviceId>\n" +
"<RegionId>" + RegionID + "</RegionId>\n<CountryCode>" + CountryCode +
"</CountryCode>\n<TitleVersion>\n<TitleId>0000000100000001</TitleId>\n" +
"<Version>2</Version>\n</TitleVersion>\n<TitleVersion>\n<TitleId>0000000100000002</TitleId>\n" + "<Version>2</Version>\n</TitleVersion>\n<TitleVersion>\n<TitleId>0000000100000002</TitleId>\n" +
"<Version>33</Version>\n</TitleVersion>\n<TitleVersion>\n<TitleId>0000000100000009</TitleId>\n" + "<Version>33</Version>\n</TitleVersion>\n<TitleVersion>\n<TitleId>0000000100000009</TitleId>\n" +
"<Version>516</Version>\n</TitleVersion>\n<Attribute>" + attr + "</Attribute>\n<AuditData></AuditData>\n" + "<Version>516</Version>\n</TitleVersion>\n<Attribute>" + attr +
"</Attribute>\n<AuditData></AuditData>\n" +
"</GetSystemUpdateRequest>\n</soapenv:Body>\n</soapenv:Envelope>"; "</GetSystemUpdateRequest>\n</soapenv:Body>\n</soapenv:Envelope>";
WriteStatus(" - Sending SOAP Request to NUS..."); WriteStatus(" - Sending SOAP Request to NUS...");
@ -2795,23 +2802,24 @@ namespace NUS_Downloader
if ((File.Exists("database.xml") == true) && ((!(String.IsNullOrEmpty(NameFromDatabase(TitleID)))))) if ((File.Exists("database.xml") == true) && ((!(String.IsNullOrEmpty(NameFromDatabase(TitleID))))))
statusbox.Text += String.Format(" [{0}]", NameFromDatabase(TitleID)); statusbox.Text += String.Format(" [{0}]", NameFromDatabase(TitleID));
script_text += String.Format("{0} {1}\n", TitleID, DisplayBytes(NewIntegertoByteArray(Convert.ToInt32(Version), 2), "")); script_text += String.Format("{0} {1}\n", TitleID,
DisplayBytes(NewIntegertoByteArray(Convert.ToInt32(Version), 2), ""));
} }
WriteStatus(" - Outputting results to NUS script..."); WriteStatus(" - Outputting results to NUS script...");
// Current directory... // Current directory...
string currentdir = Directory.GetCurrentDirectory(); string currentdir = Directory.GetCurrentDirectory();
if (!(currentdir.EndsWith(Path.DirectorySeparatorChar.ToString())) || !(currentdir.EndsWith(Path.AltDirectorySeparatorChar.ToString())))
currentdir += Path.DirectorySeparatorChar.ToString();
if (!(Directory.Exists(currentdir + "scripts"))) if (!(Directory.Exists(Path.Combine(currentdir, "scripts"))))
{ {
Directory.CreateDirectory(currentdir + "scripts"); Directory.CreateDirectory(Path.Combine(currentdir, "scripts"));
WriteStatus(" - Created 'scripts\' directory."); WriteStatus(" - Created 'scripts\' directory.");
} }
string time = RemoveIllegalCharacters(DateTime.Now.ToShortTimeString()); string time = RemoveIllegalCharacters(DateTime.Now.ToShortTimeString());
File.WriteAllText(String.Format(currentdir + "scripts\\{0}_Update_{1}_{2}_{3} {4}.nus", RegionID, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Year, time), script_text); File.WriteAllText(
String.Format(Path.Combine(currentdir, "scripts\\{0}_Update_{1}_{2}_{3} {4}.nus"), RegionID,
DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Year, time), script_text);
WriteStatus(" - Script written!"); WriteStatus(" - Script written!");
WriteStatus(" - Run this script if you feel like downloading the update!"); WriteStatus(" - Run this script if you feel like downloading the update!");
} }
@ -2860,7 +2868,8 @@ namespace NUS_Downloader
} }
// Search for cert_CA // Search for cert_CA
if ((!(tmdortik.Length < 0x400)) && ((Convert.ToBase64String(ComputeSHA(cert_CA)) != Convert.ToBase64String(cert_CA_sha1)))) if ((!(tmdortik.Length < 0x400)) &&
((Convert.ToBase64String(ComputeSHA(cert_CA)) != Convert.ToBase64String(cert_CA_sha1))))
{ {
for (int a = 0; a < (tmdortik.Length - 0x400); a++) for (int a = 0; a < (tmdortik.Length - 0x400); a++)
{ {
@ -2945,7 +2954,9 @@ namespace NUS_Downloader
case "titleID": case "titleID":
if (ChildrenOfTheNode[z].InnerText == titleid) if (ChildrenOfTheNode[z].InnerText == titleid)
found_it = true; found_it = true;
else if ((ChildrenOfTheNode[z].InnerText.Substring(0, 14) + "XX") == (titleid.Substring(0, 14) + "XX") && (titleid.Substring(0, 14) != "00000001000000")) else if ((ChildrenOfTheNode[z].InnerText.Substring(0, 14) + "XX") ==
(titleid.Substring(0, 14) + "XX") &&
(titleid.Substring(0, 14) != "00000001000000"))
found_it = true; found_it = true;
else else
found_it = false; found_it = false;
@ -2979,32 +2990,24 @@ namespace NUS_Downloader
deletecontentsbox.Enabled = packbox.Enabled; deletecontentsbox.Enabled = packbox.Enabled;
} }
private void saveaswadbox_Paint(object sender, PaintEventArgs e)
{
//e.Graphics.
/*Rectangle rect = new Rectangle(0, 0, 16, 16);
if (saveaswadbox.Checked)
e.Graphics.DrawImageUnscaledAndClipped(green, rect);
else
e.Graphics.DrawImageUnscaled(orange, -7, -5); */
}
private void SaveProxyBtn_Click(object sender, EventArgs e) private void SaveProxyBtn_Click(object sender, EventArgs e)
{ {
// Current directory... // Current directory...
string currentdir = Directory.GetCurrentDirectory(); string currentdir = Directory.GetCurrentDirectory();
if (!(currentdir.EndsWith(Path.DirectorySeparatorChar.ToString())) || !(currentdir.EndsWith(Path.AltDirectorySeparatorChar.ToString())))
currentdir += Path.DirectorySeparatorChar.ToString();
if ((String.IsNullOrEmpty(ProxyURL.Text)) && (String.IsNullOrEmpty(ProxyUser.Text)) && ((File.Exists(currentdir + "proxy.txt")))) if ((String.IsNullOrEmpty(ProxyURL.Text)) && (String.IsNullOrEmpty(ProxyUser.Text)) &&
((File.Exists(Path.Combine(currentdir, "proxy.txt")))))
{ {
File.Delete(currentdir + "proxy.txt"); File.Delete(Path.Combine(currentdir, "proxy.txt"));
proxyBox.Visible = false; proxyBox.Visible = false;
proxy_usr = ""; proxy_url = ""; proxy_pwd = ""; proxy_usr = "";
proxy_url = "";
proxy_pwd = "";
WriteStatus("Proxy settings deleted!"); WriteStatus("Proxy settings deleted!");
return; return;
} }
else if ((String.IsNullOrEmpty(ProxyURL.Text)) && (String.IsNullOrEmpty(ProxyUser.Text)) && ((!(File.Exists(currentdir + "proxy.txt"))))) else if ((String.IsNullOrEmpty(ProxyURL.Text)) && (String.IsNullOrEmpty(ProxyUser.Text)) &&
((!(File.Exists(Path.Combine(currentdir, "proxy.txt"))))))
{ {
proxyBox.Visible = false; proxyBox.Visible = false;
WriteStatus("No proxy settings saved!"); WriteStatus("No proxy settings saved!");
@ -3027,15 +3030,17 @@ namespace NUS_Downloader
if (!(String.IsNullOrEmpty(proxy_file))) if (!(String.IsNullOrEmpty(proxy_file)))
{ {
File.WriteAllText(currentdir + "proxy.txt", proxy_file); File.WriteAllText(Path.Combine(currentdir, "proxy.txt"), proxy_file);
WriteStatus("Proxy settings saved!"); WriteStatus("Proxy settings saved!");
} }
proxyBox.Visible = false; proxyBox.Visible = false;
SetAllEnabled(false); SetAllEnabled(false);
ProxyVerifyBox.Visible = true; ProxyVerifyBox.Enabled = true; ProxyVerifyBox.Visible = true;
ProxyPwdBox.Enabled = true; SaveProxyBtn.Enabled = true; ProxyVerifyBox.Enabled = true;
ProxyPwdBox.Enabled = true;
SaveProxyBtn.Enabled = true;
ProxyVerifyBox.Select(); ProxyVerifyBox.Select();
} }
@ -3043,13 +3048,11 @@ namespace NUS_Downloader
{ {
// Current directory... // Current directory...
string currentdir = Directory.GetCurrentDirectory(); string currentdir = Directory.GetCurrentDirectory();
if (!(currentdir.EndsWith(Path.DirectorySeparatorChar.ToString())) || !(currentdir.EndsWith(Path.AltDirectorySeparatorChar.ToString())))
currentdir += Path.DirectorySeparatorChar.ToString();
// Check for Proxy Settings file... // Check for Proxy Settings file...
if (File.Exists(currentdir + "proxy.txt") == true) if (File.Exists(Path.Combine(currentdir, "proxy.txt")) == true)
{ {
string[] proxy_file = File.ReadAllLines(currentdir + "proxy.txt"); string[] proxy_file = File.ReadAllLines(Path.Combine(currentdir, "proxy.txt"));
ProxyURL.Text = proxy_file[0]; ProxyURL.Text = proxy_file[0];
if (proxy_file.Length > 1) if (proxy_file.Length > 1)
@ -3085,15 +3088,13 @@ namespace NUS_Downloader
{ {
// Current directory... // Current directory...
string currentdir = Directory.GetCurrentDirectory(); string currentdir = Directory.GetCurrentDirectory();
if (!(currentdir.EndsWith(Path.DirectorySeparatorChar.ToString())) || !(currentdir.EndsWith(Path.AltDirectorySeparatorChar.ToString())))
currentdir += Path.DirectorySeparatorChar.ToString();
// Open a NUS script. // Open a NUS script.
OpenFileDialog ofd = new OpenFileDialog(); OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = false; ofd.Multiselect = false;
ofd.Filter = "NUS Scripts|*.nus|All Files|*.*"; ofd.Filter = "NUS Scripts|*.nus|All Files|*.*";
if (Directory.Exists(currentdir + "scripts")) if (Directory.Exists(Path.Combine(currentdir, "scripts")))
ofd.InitialDirectory = currentdir + "scripts"; ofd.InitialDirectory = Path.Combine(currentdir, "scripts");
ofd.Title = "Load a NUS/Wiimpersonator script."; ofd.Title = "Load a NUS/Wiimpersonator script.";
if (ofd.ShowDialog() != DialogResult.Cancel) if (ofd.ShowDialog() != DialogResult.Cancel)
@ -3136,8 +3137,14 @@ namespace NUS_Downloader
if (string.IsNullOrEmpty(title_info[0])) if (string.IsNullOrEmpty(title_info[0]))
break; break;
titleidbox.Text = title_info[0]; titleidbox.Text = title_info[0];
titleversion.Text = Convert.ToString(256*(byte.Parse(title_info[1].Substring(0, 2), System.Globalization.NumberStyles.HexNumber))); titleversion.Text =
titleversion.Text = Convert.ToString(Convert.ToInt32(titleversion.Text) + byte.Parse(title_info[1].Substring(2, 2), System.Globalization.NumberStyles.HexNumber)); Convert.ToString(256*
(byte.Parse(title_info[1].Substring(0, 2),
System.Globalization.NumberStyles.HexNumber)));
titleversion.Text =
Convert.ToString(Convert.ToInt32(titleversion.Text) +
byte.Parse(title_info[1].Substring(2, 2),
System.Globalization.NumberStyles.HexNumber));
button3_Click("Scripter", EventArgs.Empty); button3_Click("Scripter", EventArgs.Empty);
@ -3191,14 +3198,14 @@ namespace NUS_Downloader
// Find our start point // Find our start point
string startofcommonkey = "Common key ("; string startofcommonkey = "Common key (";
keyspostsource = keyspostsource.Substring(keyspostsource.IndexOf(startofcommonkey) + startofcommonkey.Length, 32); keyspostsource = keyspostsource.Substring(
keyspostsource.IndexOf(startofcommonkey) + startofcommonkey.Length, 32);
WriteStatus("Got the common key as: " + keyspostsource); WriteStatus("Got the common key as: " + keyspostsource);
byte[] commonkey = HexStringToByteArray(keyspostsource); byte[] commonkey = HexStringToByteArray(keyspostsource);
if (WriteCommonKey("key.bin", commonkey)) if (WriteCommonKey("key.bin", commonkey))
{ {
BootChecks(); BootChecks();
} }
} }
public static string ByteArrayToHexString(byte[] Bytes) public static string ByteArrayToHexString(byte[] Bytes)
@ -3218,9 +3225,12 @@ namespace NUS_Downloader
public static byte[] HexStringToByteArray(string Hex) public static byte[] HexStringToByteArray(string Hex)
{ {
byte[] Bytes = new byte[Hex.Length/2]; byte[] Bytes = new byte[Hex.Length/2];
int[] HexValue = new int[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, int[] HexValue = new int[]
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x0B, 0x0C, 0x0D,
0x0E, 0x0F }; 0x0E, 0x0F
};
for (int x = 0, i = 0; i < Hex.Length; i += 2, x += 1) for (int x = 0, i = 0; i < Hex.Length; i += 2, x += 1)
{ {
@ -3230,10 +3240,5 @@ namespace NUS_Downloader
return Bytes; return Bytes;
} }
} }
} }