예제 #1
0
        private void NextButtonClick(object sender, RoutedEventArgs e)
        {
            NavigationWindow root = FindNavigationWindow();

            // Reset SDService so that it's ready for later
            SDService.ResetHandlers();
            SDService.Stop();

            root.Navigate(new DerivingPage((page) =>
            {
                // setup key derivation task and execute it asynchronously on the next page
                HACGUIKeyset.Keyset.DeriveKeys();

                PageExtension next = null;

                // move to next page (after the task is complete)
                page.Dispatcher.BeginInvoke(new Action(() => // move to UI thread
                {
                    next = new PickNANDPage();
                    page.FindNavigationWindow().Navigate(next);
                })).Wait();   // must wait, otherwise a race condition may occur

                return(next); // return the page we are navigating to
            }));
        }
예제 #2
0
        private void btn_next_Click(object sender, RoutedEventArgs e)
        {
            NavigationWindow root = FindRoot();

            // Reset SDService so that it's ready for later
            SDService.ResetHandlers();
            SDService.Stop();

            root.Navigate(new DerivingPage((page) =>
            {
                // setup key derivation task and execute it asynchronously on the next page

                Array.Copy(SBK, HACGUIKeyset.Keyset.SecureBootKey, 0x10);
                Array.Copy(TSECKeys[0], HACGUIKeyset.Keyset.TsecKey, 0x10);

                FileStream boot0 = HACGUIKeyset.TempBOOT0FileInfo.OpenRead();
                boot0.Seek(0x180000, SeekOrigin.Begin); // Seek to keyblob area

                for (int i = 0; i < 32; i++)
                {
                    boot0.Read(HACGUIKeyset.Keyset.EncryptedKeyblobs[i], 0, 0xB0);
                    boot0.Seek(0x150, SeekOrigin.Current); // skip empty region
                }

                boot0.Seek(0x100000, SeekOrigin.Begin);
                List <HashSearchEntry> searches = new List <HashSearchEntry>
                {
                    new HashSearchEntry(NintendoKeys.MasterKeySourceHash, 0x10),
                    new HashSearchEntry(NintendoKeys.KeyblobMacKeySourceHash, 0x10)
                };
                Dictionary <byte[], byte[]> hashes = boot0.FindKeyViaHash(searches, new SHA256Managed(), 0x10, 0x40000);
                Array.Copy(hashes[NintendoKeys.MasterKeySourceHash], HACGUIKeyset.Keyset.MasterKeySource, 0x10);
                Array.Copy(hashes[NintendoKeys.KeyblobMacKeySourceHash], HACGUIKeyset.Keyset.KeyblobMacKeySource, 0x10);

                HACGUIKeyset.Keyset.DeriveKeys();

                // Copy package1 into seperate file
                boot0.Seek(0x100000, SeekOrigin.Begin);
                FileStream pkg1stream = HACGUIKeyset.TempPkg1FileInfo.Create();
                boot0.CopyToNew(pkg1stream, 0x40000);
                boot0.Close();
                pkg1stream.Seek(0, SeekOrigin.Begin); // reset position

                HACGUIKeyset.RootTempPkg1FolderInfo.Create();
                Package1 pkg1 = new Package1(HACGUIKeyset.Keyset, pkg1stream);

                // Extracting package1 contents
                FileStream NXBootloaderStream  = HACGUIKeyset.TempNXBootloaderFileInfo.Create();
                FileStream SecureMonitorStream = HACGUIKeyset.TempSecureMonitorFileInfo.Create();
                FileStream WarmbootStream      = HACGUIKeyset.TempWarmbootFileInfo.Create();
                pkg1.Pk11.OpenNxBootloader().CopyToNew(NXBootloaderStream);
                pkg1.Pk11.OpenSecureMonitor().CopyToNew(SecureMonitorStream);
                pkg1.Pk11.OpenWarmboot().CopyToNew(WarmbootStream);


                searches = new List <HashSearchEntry>
                {
                    new HashSearchEntry(NintendoKeys.Pkg2KeySourceHash, 0x10),
                    new HashSearchEntry(NintendoKeys.TitleKekSourceHash, 0x10),
                    new HashSearchEntry(NintendoKeys.AesKekGenerationSourceHash, 0x10)
                };

                SecureMonitorStream.Seek(0, SeekOrigin.Begin);
                hashes = SecureMonitorStream.FindKeyViaHash(searches, new SHA256Managed(), 0x10);
                Array.Copy(hashes[NintendoKeys.Pkg2KeySourceHash], HACGUIKeyset.Keyset.Package2KeySource, 0x10);
                Array.Copy(hashes[NintendoKeys.TitleKekSourceHash], HACGUIKeyset.Keyset.TitlekekSource, 0x10);
                Array.Copy(hashes[NintendoKeys.AesKekGenerationSourceHash], HACGUIKeyset.Keyset.AesKekGenerationSource, 0x10);

                HACGUIKeyset.Keyset.DeriveKeys(); // derive the additional keys obtained from package1

                // close shit
                NXBootloaderStream.Close();
                SecureMonitorStream.Close();
                WarmbootStream.Close();
                pkg1stream.Close();

                PageExtension next = null;

                // move to next page (after the task is complete)
                page.Dispatcher.BeginInvoke(new Action(() => // move to UI thread
                {
                    next = new PickNANDPage();
                    page.FindRoot().Navigate(next);
                })).Wait();   // must wait, otherwise a race condition may occur

                return(next); // return the page we are navigating to
            }));
        }