From 1c51d8bada43f4ac49315ef245bd30ca32d996b5 Mon Sep 17 00:00:00 2001 From: givememystuffplease Date: Sun, 4 Jul 2010 04:51:27 +0000 Subject: [PATCH] - Added retrieval of korean key (kkey.bin) from hackmii. - Background threaded key retrieval methods. --- NUS Downloader/Form1.Designer.cs | 66 +++++++++++++------- NUS Downloader/Form1.cs | 102 ++++++++++++++++++++----------- 2 files changed, 109 insertions(+), 59 deletions(-) diff --git a/NUS Downloader/Form1.Designer.cs b/NUS Downloader/Form1.Designer.cs index 484d978..dc6b2b0 100644 --- a/NUS Downloader/Form1.Designer.cs +++ b/NUS Downloader/Form1.Designer.cs @@ -83,6 +83,8 @@ this.loadNUSScriptToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator7 = new System.Windows.Forms.ToolStripSeparator(); this.getCommonKeyMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.commonKeykeybinToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.koreanKeykkeybinToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); this.updateDatabaseToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveaswadbox = new System.Windows.Forms.CheckBox(); @@ -98,8 +100,8 @@ this.SaveProxyPwdBtn = new System.Windows.Forms.Button(); this.label14 = new System.Windows.Forms.Label(); this.ProxyPwdBox = new System.Windows.Forms.TextBox(); - this.dlprogress = new wyDay.Controls.Windows7ProgressBar(); this.consoleCBox = new System.Windows.Forms.ComboBox(); + this.dlprogress = new wyDay.Controls.Windows7ProgressBar(); this.databaseStrip.SuspendLayout(); this.extrasStrip.SuspendLayout(); this.proxyBox.SuspendLayout(); @@ -453,20 +455,20 @@ this.toolStripSeparator2, this.updateDatabaseToolStripMenuItem}); this.extrasStrip.Name = "extrasStrip"; - this.extrasStrip.Size = new System.Drawing.Size(242, 166); + this.extrasStrip.Size = new System.Drawing.Size(220, 188); // // loadInfoFromTMDToolStripMenuItem // this.loadInfoFromTMDToolStripMenuItem.Image = global::NUS_Downloader.Properties.Resources.page_white_magnify; this.loadInfoFromTMDToolStripMenuItem.Name = "loadInfoFromTMDToolStripMenuItem"; - this.loadInfoFromTMDToolStripMenuItem.Size = new System.Drawing.Size(241, 22); + this.loadInfoFromTMDToolStripMenuItem.Size = new System.Drawing.Size(219, 22); this.loadInfoFromTMDToolStripMenuItem.Text = "Load Info from TMD"; this.loadInfoFromTMDToolStripMenuItem.Click += new System.EventHandler(this.loadInfoFromTMDToolStripMenuItem_Click); // // toolStripSeparator3 // this.toolStripSeparator3.Name = "toolStripSeparator3"; - this.toolStripSeparator3.Size = new System.Drawing.Size(238, 6); + this.toolStripSeparator3.Size = new System.Drawing.Size(216, 6); // // emulateUpdate // @@ -477,7 +479,7 @@ this.koreaToolStripMenuItem}); this.emulateUpdate.Image = global::NUS_Downloader.Properties.Resources.server_connect; this.emulateUpdate.Name = "emulateUpdate"; - this.emulateUpdate.Size = new System.Drawing.Size(241, 22); + this.emulateUpdate.Size = new System.Drawing.Size(219, 22); this.emulateUpdate.Text = "Emulate Wii System Update"; this.emulateUpdate.DropDownItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.emulateUpdate_DropDownItemClicked); // @@ -508,52 +510,68 @@ // toolStripSeparator4 // this.toolStripSeparator4.Name = "toolStripSeparator4"; - this.toolStripSeparator4.Size = new System.Drawing.Size(238, 6); + this.toolStripSeparator4.Size = new System.Drawing.Size(216, 6); // // proxySettingsToolStripMenuItem // this.proxySettingsToolStripMenuItem.Image = global::NUS_Downloader.Properties.Resources.server_link; this.proxySettingsToolStripMenuItem.Name = "proxySettingsToolStripMenuItem"; - this.proxySettingsToolStripMenuItem.Size = new System.Drawing.Size(241, 22); + this.proxySettingsToolStripMenuItem.Size = new System.Drawing.Size(219, 22); this.proxySettingsToolStripMenuItem.Text = "Proxy Settings"; this.proxySettingsToolStripMenuItem.Click += new System.EventHandler(this.proxySettingsToolStripMenuItem_Click); // // toolStripSeparator6 // this.toolStripSeparator6.Name = "toolStripSeparator6"; - this.toolStripSeparator6.Size = new System.Drawing.Size(238, 6); + this.toolStripSeparator6.Size = new System.Drawing.Size(216, 6); // // loadNUSScriptToolStripMenuItem // this.loadNUSScriptToolStripMenuItem.Image = global::NUS_Downloader.Properties.Resources.script_go; this.loadNUSScriptToolStripMenuItem.Name = "loadNUSScriptToolStripMenuItem"; - this.loadNUSScriptToolStripMenuItem.Size = new System.Drawing.Size(241, 22); + this.loadNUSScriptToolStripMenuItem.Size = new System.Drawing.Size(219, 22); this.loadNUSScriptToolStripMenuItem.Text = "Load NUS Script"; this.loadNUSScriptToolStripMenuItem.Click += new System.EventHandler(this.loadNUSScriptToolStripMenuItem_Click); // // toolStripSeparator7 // this.toolStripSeparator7.Name = "toolStripSeparator7"; - this.toolStripSeparator7.Size = new System.Drawing.Size(238, 6); + this.toolStripSeparator7.Size = new System.Drawing.Size(216, 6); // // getCommonKeyMenuItem // + this.getCommonKeyMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.commonKeykeybinToolStripMenuItem, + this.koreanKeykkeybinToolStripMenuItem}); this.getCommonKeyMenuItem.Image = global::NUS_Downloader.Properties.Resources.key; this.getCommonKeyMenuItem.Name = "getCommonKeyMenuItem"; - this.getCommonKeyMenuItem.Size = new System.Drawing.Size(241, 22); - this.getCommonKeyMenuItem.Text = "Retrieve Common Key (key.bin)"; - this.getCommonKeyMenuItem.Click += new System.EventHandler(this.getCommonKeyMenuItem_Click); + this.getCommonKeyMenuItem.Size = new System.Drawing.Size(219, 22); + this.getCommonKeyMenuItem.Text = "Retrieve Key"; + // + // commonKeykeybinToolStripMenuItem + // + this.commonKeykeybinToolStripMenuItem.Name = "commonKeykeybinToolStripMenuItem"; + this.commonKeykeybinToolStripMenuItem.Size = new System.Drawing.Size(196, 22); + this.commonKeykeybinToolStripMenuItem.Text = "Common Key (key.bin)"; + this.commonKeykeybinToolStripMenuItem.Click += new System.EventHandler(this.commonKeykeybinToolStripMenuItem_Click); + // + // koreanKeykkeybinToolStripMenuItem + // + this.koreanKeykkeybinToolStripMenuItem.Name = "koreanKeykkeybinToolStripMenuItem"; + this.koreanKeykkeybinToolStripMenuItem.Size = new System.Drawing.Size(196, 22); + this.koreanKeykkeybinToolStripMenuItem.Text = "Korean Key (kkey.bin)"; + this.koreanKeykkeybinToolStripMenuItem.Click += new System.EventHandler(this.koreanKeykkeybinToolStripMenuItem_Click); // // toolStripSeparator2 // this.toolStripSeparator2.Name = "toolStripSeparator2"; - this.toolStripSeparator2.Size = new System.Drawing.Size(238, 6); + this.toolStripSeparator2.Size = new System.Drawing.Size(216, 6); // // updateDatabaseToolStripMenuItem // this.updateDatabaseToolStripMenuItem.Image = global::NUS_Downloader.Properties.Resources.database_save; this.updateDatabaseToolStripMenuItem.Name = "updateDatabaseToolStripMenuItem"; - this.updateDatabaseToolStripMenuItem.Size = new System.Drawing.Size(241, 22); + this.updateDatabaseToolStripMenuItem.Size = new System.Drawing.Size(219, 22); this.updateDatabaseToolStripMenuItem.Text = "Update Database"; this.updateDatabaseToolStripMenuItem.Click += new System.EventHandler(this.updateDatabaseToolStripMenuItem_Click); // @@ -696,14 +714,6 @@ this.ProxyPwdBox.UseSystemPasswordChar = true; this.ProxyPwdBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.ProxyPwdBox_KeyPress); // - // dlprogress - // - this.dlprogress.ContainerControl = this; - this.dlprogress.Location = new System.Drawing.Point(12, 95); - this.dlprogress.Name = "dlprogress"; - this.dlprogress.Size = new System.Drawing.Size(250, 15); - this.dlprogress.TabIndex = 47; - // // consoleCBox // this.consoleCBox.FlatStyle = System.Windows.Forms.FlatStyle.Flat; @@ -717,6 +727,14 @@ this.consoleCBox.TabIndex = 48; this.consoleCBox.SelectedIndexChanged += new System.EventHandler(this.consoleCBox_SelectedIndexChanged); // + // dlprogress + // + this.dlprogress.ContainerControl = this; + this.dlprogress.Location = new System.Drawing.Point(12, 95); + this.dlprogress.Name = "dlprogress"; + this.dlprogress.Size = new System.Drawing.Size(250, 15); + this.dlprogress.TabIndex = 47; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -834,6 +852,8 @@ private System.Windows.Forms.ToolStripMenuItem NTSCMassUpdate; private System.Windows.Forms.ToolStripMenuItem KoreaMassUpdate; private System.Windows.Forms.ComboBox consoleCBox; + private System.Windows.Forms.ToolStripMenuItem commonKeykeybinToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem koreanKeykkeybinToolStripMenuItem; } } diff --git a/NUS Downloader/Form1.cs b/NUS Downloader/Form1.cs index 664b60c..7e3a94a 100644 --- a/NUS Downloader/Form1.cs +++ b/NUS Downloader/Form1.cs @@ -29,8 +29,6 @@ namespace NUS_Downloader // Cross-thread Windows Formsing private delegate void AddToolStripItemToStripCallback( int type, ToolStripMenuItem additionitem, XmlAttributeCollection attributes); - - // TODO private delegate void WriteStatusCallback(string Update); // Images do not compare unless globalized... @@ -267,7 +265,7 @@ namespace NUS_Downloader if (File.Exists(Path.Combine(currentdir, "key.bin")) == false) { WriteStatus("Common Key (key.bin) missing! Decryption disabled!"); - WriteStatus(" - To enable it, why not try choosing \"Retrieve Common Key\" from the Extras menu?"); + WriteStatus(" - Try: Extras -> Retrieve Key -> Common Key"); decryptbox.Visible = false; } else @@ -325,6 +323,7 @@ namespace NUS_Downloader WriteStatus(" - Version: " + version); databaseButton.Enabled = false; databaseButton.Text = "DB Loading"; + updateDatabaseToolStripMenuItem.Text = "Update Database"; // Load it up... this.fds.RunWorkerAsync(); } @@ -1647,19 +1646,19 @@ namespace NUS_Downloader if (File.Exists(Path.Combine(currentdir, keyfile)) == true) { - WriteStatus("Overwriting old key.bin..."); + WriteStatus(String.Format("Overwriting old {0}...", keyfile)); } try { FileStream fs = File.OpenWrite(Path.Combine(currentdir, keyfile)); fs.Write(commonkey, 0, commonkey.Length); fs.Close(); - WriteStatus("key.bin written - Reloading..."); + WriteStatus(String.Format("{0} written - Reloading...", keyfile)); return true; } catch (IOException e) { - WriteStatus("Error: Couldn't write key.bin: " + e.Message); + WriteStatus(String.Format("Error: Couldn't write {0}: {1}", keyfile, e.Message)); } return false; } @@ -2625,10 +2624,6 @@ namespace NUS_Downloader dbFetcher.DoWork += new DoWorkEventHandler(RetrieveNewDatabase); dbFetcher.RunWorkerCompleted += new RunWorkerCompletedEventHandler(RetrieveNewDatabase_Completed); dbFetcher.RunWorkerAsync(); - /*while (dbFetcher.IsBusy) - { - statusbox.Text += "."; - }*/ } private void loadInfoFromTMDToolStripMenuItem_Click(object sender, EventArgs e) @@ -3146,32 +3141,6 @@ namespace NUS_Downloader WriteStatus("Script completed!"); } - private void getCommonKeyMenuItem_Click(object sender, EventArgs e) - { - WriteStatus("Preparing to retrieve common key..."); - - // Begin the epic grab for freedom - WebClient databasedl = new WebClient(); - statusbox.Refresh(); - - // Proxy - databasedl = ConfigureWithProxy(databasedl); - - string keyspostsource = databasedl.DownloadString("http://hackmii.com/2008/04/keys-keys-keys/"); - statusbox.Refresh(); - - // Find our start point - string startofcommonkey = "Common key ("; - keyspostsource = keyspostsource.Substring( - keyspostsource.IndexOf(startofcommonkey) + startofcommonkey.Length, 32); - WriteStatus("Got the common key as: " + keyspostsource); - byte[] commonkey = HexStringToByteArray(keyspostsource); - if (WriteCommonKey("key.bin", commonkey)) - { - BootChecks(); - } - } - public static string ByteArrayToHexString(byte[] Bytes) { StringBuilder Result = new StringBuilder(); @@ -3204,5 +3173,66 @@ namespace NUS_Downloader return Bytes; } + + private void commonKeykeybinToolStripMenuItem_Click(object sender, EventArgs e) + { + BackgroundWorker keyFetcher = new BackgroundWorker(); + keyFetcher.DoWork += new DoWorkEventHandler(RetrieveCommonKey); + keyFetcher.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CommonKey_Retrieved); + keyFetcher.RunWorkerAsync("key.bin"); + } + + private void koreanKeykkeybinToolStripMenuItem_Click(object sender, EventArgs e) + { + BackgroundWorker keyFetcher = new BackgroundWorker(); + keyFetcher.DoWork += new DoWorkEventHandler(RetrieveCommonKey); + keyFetcher.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CommonKey_Retrieved); + keyFetcher.RunWorkerAsync("kkey.bin"); + } + + void CommonKey_Retrieved(object sender, RunWorkerCompletedEventArgs e) + { + BootChecks(); + } + + void RetrieveCommonKey(object sender, DoWorkEventArgs e) + { + WriteStatus(String.Format("Retrieving Key ({0})...", e.Argument.ToString())); + + // Begin the epic grab for freedom + WebClient keyclient = new WebClient(); + + // Proxy + keyclient = ConfigureWithProxy(keyclient); + + string htmlwithkey; + if (e.Argument.ToString() == "key.bin") + { + htmlwithkey = keyclient.DownloadString("http://hackmii.com/2008/04/keys-keys-keys/"); + + // Find our start point + string startofcommonkey = "Common key ("; + htmlwithkey = htmlwithkey.Substring( + htmlwithkey.IndexOf(startofcommonkey) + startofcommonkey.Length, 32); + WriteStatus(" - Got the Common Key as: "); + WriteStatus(" " + htmlwithkey); + byte[] commonkey = HexStringToByteArray(htmlwithkey); + WriteCommonKey("key.bin", commonkey); + } + else if (e.Argument.ToString() == "kkey.bin") + { + htmlwithkey = keyclient.DownloadString("http://hackmii.com/2008/09/korean-wii/"); + + // Find our start point + string startofcommonkey = "those.

"; + htmlwithkey = htmlwithkey.Substring( + htmlwithkey.IndexOf(startofcommonkey) + startofcommonkey.Length + 6, 47); + htmlwithkey = htmlwithkey.Replace(" ", ""); + WriteStatus(" - Got the Korean Key as: "); + WriteStatus(" " + htmlwithkey); + byte[] commonkey = HexStringToByteArray(htmlwithkey); + WriteCommonKey("kkey.bin", commonkey); + } + } } } \ No newline at end of file