public PickSDPage() { InitializeComponent(); Loaded += (_, __) => { SDService.Validator = IsSDCard; SDService.OnSDPluggedIn += (drive) => { KeysetFile = SDService.SDRoot.GetDirectory("switch").GetFile("prod.keys"); if (CopyKeyset()) { Dispatcher.Invoke(() => NextButton.IsEnabled = true); // update on UI thread } }; SDService.OnSDRemoved += (drive) => { HACGUIKeyset.Keyset = new HACGUIKeyset(); HACGUIKeyset.Keyset.LoadCommon(); Dispatcher.Invoke(() => NextButton.IsEnabled = false); // update on UI thread }; SendLockpickButton.IsEnabled = InjectService.LibusbKInstalled; MountSDEnabled = InjectService.LibusbKInstalled; Dispatcher.Invoke(() => UpdateSDButton()); InjectService.DeviceInserted += () => { if (InjectService.LibusbKInstalled) { Dispatcher.Invoke(() => { SendLockpickButton.IsEnabled = true; MountSDEnabled = true; UpdateSDButton(); }); } }; InjectService.DeviceRemoved += () => { Dispatcher.Invoke(() => { SendLockpickButton.IsEnabled = false; MountSDEnabled = false; UpdateSDButton(); }); }; InjectService.ErrorOccurred += () => { MessageBox.Show("An error occurred while trying to send the memloader ini data..."); MountSDLock = false; Dispatcher.Invoke(() => UpdateSDButton()); }; InjectService.IniInjectFinished += () => { MountSDLock = false; Dispatcher.Invoke(() => UpdateSDButton()); }; RootWindow.Current.Submit(new Task(() => SDService.Start())); }; }
public void PublishDiscoveryAndRemovalTest() { DateTime dateTimeWhenToStopWaiting; bool found = false; AutoResetEvent are = new AutoResetEvent(false); SDService foundService = null; this.serviceDiscovery.ServiceFound += delegate(SDService service, bool ownService) { if (ownService) { foundService = service; found = true; are.Set(); } }; this.serviceDiscovery.ServiceLost += delegate(SDService service) { if (service.Equals(foundService)) { found = false; are.Set(); } }; this.serviceDiscovery.SearchForServices(SERVICE_TYPE); this.serviceDiscovery.PublishService(SERVICE_TYPE, SERVICE_PORT); dateTimeWhenToStopWaiting = DateTime.Now.Add(WAIT_TIME); while (!found && DateTime.Now < dateTimeWhenToStopWaiting) { long ticksToWait = dateTimeWhenToStopWaiting.Subtract(DateTime.Now).Ticks; are.WaitOne(new TimeSpan(ticksToWait)); } are.Reset(); if (!found) { this.serviceDiscovery.StopSearchingForServices(SERVICE_TYPE); this.serviceDiscovery.StopPublishingService(SERVICE_TYPE, SERVICE_PORT); Assert.Fail(); } this.serviceDiscovery.StopPublishing(); dateTimeWhenToStopWaiting = DateTime.Now.Add(WAIT_TIME); while (found && DateTime.Now < dateTimeWhenToStopWaiting) { long ticksToWait = dateTimeWhenToStopWaiting.Subtract(DateTime.Now).Ticks; are.WaitOne(new TimeSpan(ticksToWait)); } this.serviceDiscovery.StopSearchingForServices(SERVICE_TYPE); this.serviceDiscovery.StopPublishingService(SERVICE_TYPE, SERVICE_PORT); if (found) { Assert.Fail(); } }
public override void OnBack() { SDService.Stop(); }
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 })); }