Esempio n. 1
0
        private static string Print(this PartitionFileSystem pfs)
        {
            const int colLen      = 36;
            const int fileNameLen = 39;

            var sb = new StringBuilder();

            sb.AppendLine();

            sb.AppendLine("PFS0:");

            PrintItem(sb, colLen, "Magic:", pfs.Header.Magic);
            PrintItem(sb, colLen, "Number of files:", pfs.Header.NumFiles);

            for (int i = 0; i < pfs.Files.Length; i++)
            {
                PartitionFileEntry file = pfs.Files[i];

                string label   = i == 0 ? "Files:" : "";
                string offsets = $"{file.Offset:x12}-{file.Offset + file.Size:x12}{file.HashValidity.GetValidityString()}";
                string data    = $"pfs0:/{file.Name}".PadRight(fileNameLen) + offsets;

                PrintItem(sb, colLen, label, data);
            }

            return(sb.ToString());
        }
Esempio n. 2
0
        private static void PrintPartition(StringBuilder sb, int colLen, XciPartition partition, XciPartitionType type)
        {
            const int fileNameLen = 57;

            sb.AppendLine($"{type.ToString()} Partition:{partition.HashValidity.GetValidityString()}");
            PrintItem(sb, colLen, "    Magic:", partition.Header.Magic);
            PrintItem(sb, colLen, "    Offset:", $"{partition.Offset:x12}");
            PrintItem(sb, colLen, "    Number of files:", partition.Files.Length);

            string name = type.GetFileName();

            if (partition.Files.Length > 0 && partition.Files.Length < 100)
            {
                for (int i = 0; i < partition.Files.Length; i++)
                {
                    PartitionFileEntry file = partition.Files[i];

                    string label   = i == 0 ? "    Files:" : "";
                    string offsets = $"{file.Offset:x12}-{file.Offset + file.Size:x12}{file.HashValidity.GetValidityString()}";
                    string data    = $"{name}:/{file.Name}".PadRight(fileNameLen) + offsets;

                    PrintItem(sb, colLen, label, data);
                }
            }
        }
Esempio n. 3
0
            internal static PartitionFileEntry Read(Stream stream)
            {
                var pastPos             = stream.Position;
                PartitionFileEntry part = BinaryMapping.ReadObject <PartitionFileEntry>(stream);

                part.LocationOffset = pastPos;
                return(part);
            }
Esempio n. 4
0
 private static void ReadPartitionLba(IEnumerable <Partition <PartitionFileEntry> > partitions, Stream stream, int baseOffset)
 {
     stream.Position = baseOffset;
     foreach (var partition in partitions)
     {
         stream.Position = baseOffset + partition.Offset * LbaLength;
         partition.Lba   = Enumerable.Range(0, partition.Count)
                           .Select(x => PartitionFileEntry.Read(stream)).ToArray();
     }
 }
Esempio n. 5
0
        public PartitionFileSystemHeader(BinaryReader reader)
        {
            Magic           = reader.ReadAscii(4);
            NumFiles        = reader.ReadInt32();
            StringTableSize = reader.ReadInt32();
            Reserved        = reader.ReadInt32();

            switch (Magic)
            {
            case "PFS0":
                Type = PartitionFileSystemType.Standard;
                break;

            case "HFS0":
                Type = PartitionFileSystemType.Hashed;
                break;

            default:
                ThrowHelper.ThrowResult(ResultFs.InvalidPartitionFileSystemMagic, $"Invalid Partition FS type \"{Magic}\"");
                break;
            }

            int entrySize         = PartitionFileEntry.GetEntrySize(Type);
            int stringTableOffset = 16 + entrySize * NumFiles;

            HeaderSize = stringTableOffset + StringTableSize;

            Files = new PartitionFileEntry[NumFiles];
            for (int i = 0; i < NumFiles; i++)
            {
                Files[i] = new PartitionFileEntry(reader, Type)
                {
                    Index = i
                };
            }

            for (int i = 0; i < NumFiles; i++)
            {
                reader.BaseStream.Position = stringTableOffset + Files[i].StringTableOffset;
                Files[i].Name = reader.ReadAsciiZ();
            }
        }
Esempio n. 6
0
 public NcaItem(Nca nca, PartitionFileEntry partitionFileEntry, IFile file, PartitionFileSystemItemBase parentItem)
     : base(partitionFileEntry, file, parentItem)
 {
     Nca = nca ?? throw new ArgumentNullException(nameof(nca));
     Id  = PartitionFileEntry.Name.Split('.', 2)[0];
 }
 public PartitionFileEntryItemBase(PartitionFileEntry partitionFileEntry, IFile file, PartitionFileSystemItemBase parentItem)
 {
     PartitionFileEntry = partitionFileEntry ?? throw new ArgumentNullException(nameof(partitionFileEntry));
     File       = file ?? throw new ArgumentNullException(nameof(file));
     ParentItem = parentItem ?? throw new ArgumentNullException(nameof(parentItem));
 }
Esempio n. 8
0
 public TicketItem(Ticket ticket, PartitionFileEntry partitionFileEntry, IFile file, PartitionFileSystemItemBase parentItem) : base(partitionFileEntry, file, parentItem)
 {
     _ticket = ticket ?? throw new ArgumentNullException(nameof(ticket));
 }
Esempio n. 9
0
 public PartitionFileEntryItem(PartitionFileEntry partitionFileEntry, IFile file, PartitionFileSystemItemBase parentItem)
     : base(partitionFileEntry, file, parentItem)
 {
 }