private void ReopenFileView() { if (!pkg.CheckEkpfs(ekpfs)) { return; } if (va != null) { return; } try { va = pkgFile.CreateViewAccessor((long)pkg.Header.pfs_image_offset, (long)pkg.Header.pfs_image_size); var outerPfs = new PfsReader(va, pkg.Header.pfs_flags, ekpfs); var inner = new PfsReader(new PFSCReader(outerPfs.GetFile("pfs_image.dat").GetView())); var view = new FileView(inner); view.Dock = DockStyle.Fill; filesTab.Controls.Clear(); filesTab.Controls.Add(view); } catch (Exception) { va?.Dispose(); va = null; } }
public PkgView(string path) { InitializeComponent(); if (path == null) { return; } pkgFile = MemoryMappedFile.CreateFromFile(path); using (var s = pkgFile.CreateViewStream()) ObjectPreview(new PkgReader(s).ReadHeader(), pkgHeaderTreeView); using (var s = pkgFile.CreateViewStream()) pkg = new PkgReader(s).ReadPkg(); try { using (var s = pkgFile.CreateViewStream((long)pkg.Header.pfs_image_offset, (long)pkg.Header.pfs_image_size)) ObjectPreview(PfsHeader.ReadFromStream(s), pfsHeaderTreeView); } catch (Exception e) { pkgHeaderTabControl.TabPages.Remove(outerPfsHeaderTabPage); MessageBox.Show("Error loading outer PFS: " + e.Message + Environment.NewLine + "Please report this issue at https://github.com/maxton/LibOrbisPkg/issues"); } if (pkg.Metas.Metas.Where(entry => entry.id == EntryId.ICON0_PNG).FirstOrDefault() is MetaEntry icon0) { using (var s = pkgFile.CreateViewStream(icon0.DataOffset, icon0.DataSize)) { pictureBox1.Image = Image.FromStream(s); } } contentIdTextBox.Text = pkg.Header.content_id; titleTextBox.Text = pkg.ParamSfo.ParamSfo["TITLE"]?.ToString(); sizeLabel.Text = FileView.HumanReadableFileSize((long)pkg.Header.package_size); var category = pkg.ParamSfo.ParamSfo["CATEGORY"].ToString(); typeLabel.Text = SFOView.SfoTypes.Where(x => x.Category == category).FirstOrDefault() is SFOView.SfoType t ? t.Description : "Unknown"; versionLabel.Text = pkg.ParamSfo.ParamSfo["VERSION"]?.ToString(); if (pkg.ParamSfo.ParamSfo["APP_VER"] is Utf8Value v) { appVerLabel.Text = v.Value; } else { appVerLabelLabel.Visible = false; appVerLabel.Visible = false; } var sfoEditor = new SFOView(pkg.ParamSfo.ParamSfo, true); sfoEditor.Dock = DockStyle.Fill; tabPage1.Controls.Add(sfoEditor); if (pkg.CheckPasscode("00000000000000000000000000000000")) { passcode = "00000000000000000000000000000000"; ekpfs = Crypto.ComputeKeys(pkg.Header.content_id, passcode, 1); } else { ekpfs = pkg.GetEkpfs(); } ReopenFileView(); foreach (var e in pkg.Metas.Metas) { var lvi = new ListViewItem(new[] { e.id.ToString(), string.Format("0x{0:X}", e.DataSize), string.Format("0x{0:X}", e.DataOffset), e.Encrypted ? "Yes" : "No", e.KeyIndex.ToString(), }); lvi.Tag = e; entriesListView.Items.Add(lvi); } }
public PkgView(string path) { InitializeComponent(); if (path == null) { return; } pkgFile = MemoryMappedFile.CreateFromFile(path, FileMode.Open, "pkgFile" + idx++, 0, MemoryMappedFileAccess.Read); using (var s = pkgFile.CreateViewStream(0, 0, MemoryMappedFileAccess.Read)) ObjectPreview(new PkgReader(s).ReadHeader(), pkgHeaderTreeView); using (var s = pkgFile.CreateViewStream(0, 0, MemoryMappedFileAccess.Read)) pkg = new PkgReader(s).ReadPkg(); try { using (var s = pkgFile.CreateViewStream((long)pkg.Header.pfs_image_offset, (long)pkg.Header.pfs_image_size, MemoryMappedFileAccess.Read)) ObjectPreview(PfsHeader.ReadFromStream(s), pfsHeaderTreeView); } catch (Exception e) { pkgHeaderTabControl.TabPages.Remove(outerPfsHeaderTabPage); MessageBox.Show("Error loading outer PFS: " + e.Message + Environment.NewLine + "Please report this issue at https://github.com/maxton/LibOrbisPkg/issues"); } if (pkg.Metas.Metas.Where(entry => entry.id == EntryId.ICON0_PNG).FirstOrDefault() is MetaEntry icon0) { using (var s = pkgFile.CreateViewStream(icon0.DataOffset, icon0.DataSize, MemoryMappedFileAccess.Read)) { pictureBox1.Image = Image.FromStream(s); } } contentIdTextBox.Text = pkg.Header.content_id; titleTextBox.Text = pkg.ParamSfo.ParamSfo["TITLE"]?.ToString(); sizeLabel.Text = FileView.HumanReadableFileSize((long)pkg.Header.package_size); var category = pkg.ParamSfo.ParamSfo["CATEGORY"].ToString(); typeLabel.Text = SFOView.SfoTypes.Where(x => x.Category == category).FirstOrDefault() is SFOView.SfoType t ? t.Description : "Unknown"; versionLabel.Text = pkg.ParamSfo.ParamSfo["VERSION"]?.ToString(); if (pkg.ParamSfo.ParamSfo["APP_VER"] is Utf8Value v) { appVerLabel.Text = v.Value; } else { appVerLabelLabel.Visible = false; appVerLabel.Visible = false; } var sfoEditor = new SFOView(pkg.ParamSfo.ParamSfo, true); sfoEditor.Dock = DockStyle.Fill; tabPage1.Controls.Add(sfoEditor); if (pkg.CheckPasscode("00000000000000000000000000000000")) { passcode = "00000000000000000000000000000000"; ekpfs = Crypto.ComputeKeys(pkg.Header.content_id, passcode, 1); } else if (KeyDB.Instance.Passcodes.TryGetValue(pkg.Header.content_id, out var keydbPasscode) && pkg.CheckPasscode(keydbPasscode)) { passcode = keydbPasscode; ekpfs = Crypto.ComputeKeys(pkg.Header.content_id, passcode, 1); } else if (pkg.GetEkpfs() is byte[] ek && ek != null) { ekpfs = ek; }