private void MountClicked(object sender, RoutedEventArgs e) { if (ComboBox.SelectedItem == null) { return; } MountType mountType = (MountType)ComboBox.SelectedItem; NcaFormatType sectionType = NcaFormatType.Romfs; switch (mountType) { case MountType.Exefs: sectionType = NcaFormatType.Pfs0; break; case MountType.Romfs: sectionType = NcaFormatType.Romfs; break; } List <IFileSystem> filesystems = new List <IFileSystem>(); IEnumerable <Tuple <SwitchFsNca, int> > list = Indexed[sectionType]; TaskManagerPage.Current.Queue.Submit(new RunTask("Opening filesystems to mount...", new Task(() => { foreach (Tuple <SwitchFsNca, int> t in list) { SwitchFsNca nca = t.Item1; NcaFsHeader section = t.Item1.Nca.Header.GetFsHeader(t.Item2); int index = t.Item2; /*IStorage inStorage = nca.OpenStorage(index, IntegrityCheckLevel.ErrorOnInvalid); * IFile outFile = new LocalFile("./tmp.bin", OpenMode.Write | OpenMode.AllowAppend); * IStorage outStorage = outFile.AsStorage(); * inStorage.GetSize(out long size); * long buffLen = 0x10000; * for (int i = 0; i < (int)Math.Min(Math.Ceiling((double)size / buffLen), 5); i++) * { * long off = i * buffLen; * long left = size - off; * long toRead = Math.Min(buffLen, left); * * byte[] buff = new byte[toRead]; * * inStorage.Read(off, buff); * outStorage.Write(off, buff); * } * //inStorage.Dispose(); * outFile.Dispose();*/ filesystems.Add(nca.OpenFileSystem(index, IntegrityCheckLevel.ErrorOnInvalid)); } filesystems.Reverse(); LayeredFileSystem fs = new LayeredFileSystem(filesystems); string typeString = sectionType.ToString(); MountService.Mount(new MountableFileSystem(fs, $"Mounted {mountType.ToString().ToLower()}", typeString, OpenMode.Read)); }))); }
private void ExtractClicked(object sender, RoutedEventArgs e) { MountType mountType = (MountType)ComboBox.SelectedItem; NcaFormatType sectionType = NcaFormatType.Romfs; switch (mountType) { case MountType.Exefs: sectionType = NcaFormatType.Pfs0; break; case MountType.Romfs: sectionType = NcaFormatType.Romfs; break; } IEnumerable <Tuple <SwitchFsNca, int> > list = Indexed[sectionType]; string path = Path.Text; TaskManagerPage.Current.Queue.Submit(new RunTask("Opening filesystems to extract...", new Task(() => { List <IFileSystem> filesystems = new List <IFileSystem>(); foreach (Tuple <SwitchFsNca, int> t in list) { SwitchFsNca nca = t.Item1; NcaFsHeader section = t.Item1.Nca.Header.GetFsHeader(t.Item2); int index = t.Item2; filesystems.Add(nca.OpenFileSystem(index, IntegrityCheckLevel.ErrorOnInvalid)); } filesystems.Reverse(); LayeredFileSystem lfs = new LayeredFileSystem(filesystems); ExtractFileSystemTask task = new ExtractFileSystemTask($"Extracting {sectionType}...", lfs, path); Dispatcher.InvokeAsync(() => { ProgressView view = new ProgressView(new List <ProgressTask>() { task }); NavigationWindow window = new NavigationWindow { ShowsNavigationUI = false // get rid of the t r a s h }; window.Navigate(view); TaskManagerPage.Current.Queue.Submit(task); window.Owner = Window.GetWindow(this); window.ShowDialog(); }); }))); }
public static NcaFsHeader GetFsHeader(this NcaHeader obj, NcaFormatType type) { for (int i = 0; i < 4; i++) { NcaFsHeader header = obj.GetFsHeader(i); if (header.FormatType == type) { return(header); } } throw new InvalidOperationException($"NCA is missing section type {type}"); }
public NcaFsHeader(BinaryReader reader) { long start = reader.BaseStream.Position; Version = reader.ReadInt16(); FormatType = (NcaFormatType)reader.ReadByte(); HashType = (NcaHashType)reader.ReadByte(); EncryptionType = (NcaEncryptionType)reader.ReadByte(); reader.BaseStream.Position += 3; switch (HashType) { case NcaHashType.Sha256: Sha256Info = new Sha256Info(reader); break; case NcaHashType.Ivfc: IvfcInfo = new IvfcHeader(reader); break; } if (EncryptionType == NcaEncryptionType.AesCtrEx) { BktrInfo = new BktrPatchInfo(); reader.BaseStream.Position = start + 0x100; BktrInfo.RelocationHeader = new BktrHeader(reader); BktrInfo.EncryptionHeader = new BktrHeader(reader); } if (FormatType == NcaFormatType.Pfs0) { Type = SectionType.Pfs0; } else if (FormatType == NcaFormatType.Romfs) { if (EncryptionType == NcaEncryptionType.AesCtrEx) { Type = SectionType.Bktr; } else { Type = SectionType.Romfs; } } reader.BaseStream.Position = start + 0x140; Ctr = reader.ReadBytes(8).Reverse().ToArray(); reader.BaseStream.Position = start + 512; }
private void MountClicked(object sender, RoutedEventArgs e) { MountType mountType = (MountType)ComboBox.SelectedItem; NcaFormatType sectionType = NcaFormatType.Romfs; switch (mountType) { case MountType.Exefs: sectionType = NcaFormatType.Pfs0; break; case MountType.Romfs: sectionType = NcaFormatType.Romfs; break; } List <IFileSystem> filesystems = new List <IFileSystem>(); IEnumerable <Tuple <SwitchFsNca, int> > list = Indexed[sectionType]; TaskManagerPage.Current.Queue.Submit(new RunTask("Opening filesystems to mount...", new Task(() => { foreach (Tuple <SwitchFsNca, int> t in list) { SwitchFsNca nca = t.Item1; NcaFsHeader section = t.Item1.Nca.Header.GetFsHeader(t.Item2); int index = t.Item2; if (section.IsPatchSection()) { MainNca.BaseNca = nca.Nca; } filesystems.Add(nca.OpenFileSystem(index, IntegrityCheckLevel.ErrorOnInvalid)); } filesystems.Reverse(); LayeredFileSystem fs = new LayeredFileSystem(filesystems); string typeString = sectionType.ToString(); MountService.Mount(new MountableFileSystem(fs, $"Mounted {mountType.ToString().ToLower()}", typeString, OpenMode.Read)); }))); }
private Result OpenNcaStorage(out IStorage ncaStorage, Nca nca, out NcaFormatType fsType, FileSystemProxyType fsProxyType, bool isGameCard, bool canMountSystemDataPrivate) { ncaStorage = default; fsType = default; NcaContentType contentType = nca.Header.ContentType; switch (fsProxyType) { case FileSystemProxyType.Code: case FileSystemProxyType.Rom: case FileSystemProxyType.Logo: case FileSystemProxyType.RegisteredUpdate: if (contentType != NcaContentType.Program) { return(ResultFs.PreconditionViolation.Log()); } break; case FileSystemProxyType.Control: if (contentType != NcaContentType.Control) { return(ResultFs.PreconditionViolation.Log()); } break; case FileSystemProxyType.Manual: if (contentType != NcaContentType.Manual) { return(ResultFs.PreconditionViolation.Log()); } break; case FileSystemProxyType.Meta: if (contentType != NcaContentType.Meta) { return(ResultFs.PreconditionViolation.Log()); } break; case FileSystemProxyType.Data: if (contentType != NcaContentType.Data && contentType != NcaContentType.PublicData) { return(ResultFs.PreconditionViolation.Log()); } if (contentType == NcaContentType.Data && !canMountSystemDataPrivate) { return(ResultFs.PermissionDenied.Log()); } break; default: return(ResultFs.InvalidArgument.Log()); } if (nca.Header.DistributionType == DistributionType.GameCard && !isGameCard) { return(ResultFs.PermissionDenied.Log()); } Result rc = SetNcaExternalKey(nca); if (rc.IsFailure()) { return(rc); } rc = GetNcaSectionIndex(out int sectionIndex, fsProxyType); if (rc.IsFailure()) { return(rc); } rc = FsCreators.StorageOnNcaCreator.Create(out ncaStorage, out NcaFsHeader fsHeader, nca, sectionIndex, fsProxyType == FileSystemProxyType.Code); if (rc.IsFailure()) { return(rc); } fsType = fsHeader.FormatType; return(Result.Success); }