public static void CreateNsp(Context ctx, SwitchFs switchFs) { ulong id = ctx.Options.TitleId; if (id == 0) { ctx.Logger.LogMessage("Title ID must be specified to save title"); return; } if (!switchFs.Titles.TryGetValue(id, out Title title)) { ctx.Logger.LogMessage($"Could not find title {id:X16}"); return; } var builder = new Pfs0Builder(); foreach (Nca nca in title.Ncas) { builder.AddFile(nca.Filename, nca.GetStorage().AsStream()); } var ticket = new Ticket { SignatureType = TicketSigType.Rsa2048Sha256, Signature = new byte[0x200], Issuer = "Root-CA00000003-XS00000020", FormatVersion = 2, RightsId = title.MainNca.Header.RightsId, TitleKeyBlock = title.MainNca.TitleKey, CryptoType = title.MainNca.Header.CryptoType2, SectHeaderOffset = 0x2C0 }; byte[] ticketBytes = ticket.GetBytes(); builder.AddFile($"{ticket.RightsId.ToHexString()}.tik", new MemoryStream(ticketBytes)); Assembly thisAssembly = Assembly.GetExecutingAssembly(); Stream cert = thisAssembly.GetManifestResourceStream("hactoolnet.CA00000003_XS00000020"); builder.AddFile($"{ticket.RightsId.ToHexString()}.cert", cert); using (var outStream = new FileStream(ctx.Options.NspOut, FileMode.Create, FileAccess.ReadWrite)) { builder.Build(outStream, ctx.Logger); } }
private void RepackClicked(object sender, RoutedEventArgs e) { FileInfo info = new FileInfo(Path.Text); info.Directory.Create(); // ensure that the folder exists Pfs0Builder builder = new Pfs0Builder(); NspPackTask logger = new NspPackTask(builder, info); ProgressView view = new ProgressView(new List <ProgressTask> { logger }); if (TicketCheckbox.IsChecked == true) { DirectoryInfo ticketDir = HACGUIKeyset.GetTicketsDirectory(Preferences.Current.DefaultConsoleName); // TODO: load console name from continuous location List <string> foundTickets = new List <string>(); foreach (Nca nca in SelectedNcas) { if (nca.HasRightsId) { string rightsId = BitConverter.ToString(nca.Header.RightsId).Replace("-", "").ToLower(); string ticketFileName = rightsId + ".tik"; FileInfo sourceTikFileInfo = ticketDir.GetFile(ticketFileName); if (sourceTikFileInfo.Exists && !foundTickets.Contains(rightsId)) { foundTickets.Add(rightsId); LocalFile tikFile = new LocalFile(sourceTikFileInfo.FullName, OpenMode.Read); builder.AddFile(ticketFileName, new FileStorage(tikFile).AsStream()); } } } } foreach (Nca nca in SelectedNcas) { builder.AddFile(nca.Filename, nca.GetStorage().AsStream()); } NavigationWindow window = new NavigationWindow { ShowsNavigationUI = false // get rid of the t r a s h }; window.Navigate(view); TaskManagerPage.Current.Queue.Submit(logger); window.Owner = Window.GetWindow(this); window.ShowDialog(); }