Exemplo n.º 1
0
        public PfsHeader(BinaryReader reader)
        {
            Magic           = reader.ReadAscii(4);
            NumFiles        = reader.ReadInt32();
            StringTableSize = reader.ReadInt32();
            Reserved        = reader.ReadInt32();

            switch (Magic)
            {
            case "PFS0":
                Type = PfsType.Pfs0;
                break;

            case "HFS0":
                Type = PfsType.Hfs0;
                break;

            default:
                throw new InvalidDataException($"Invalid Partition FS type \"{Magic}\"");
            }

            int entrysize         = GetFileEntrySize(Type);
            int stringTableOffset = 16 + entrysize * NumFiles;

            HeaderSize = stringTableOffset + StringTableSize;

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

            for (int i = 0; i < NumFiles; i++)
            {
                reader.BaseStream.Position = stringTableOffset + Files[i].StringTableOffset;
                Files[i].Name = reader.ReadAsciiZ();
            }


            if (Type == PfsType.Hfs0)
            {
                for (int i = 0; i < NumFiles; i++)
                {
                    reader.BaseStream.Position = HeaderSize + Files[i].Offset;
                    Files[i].HashValidity      = Crypto.CheckMemoryHashTable(reader.ReadBytes(Files[i].HashedRegionSize), Files[i].Hash, 0, Files[i].HashedRegionSize);
                }
            }
        }
Exemplo n.º 2
0
 public IStorage OpenFile(PfsFileEntry file)
 {
     return(BaseStorage.Slice(HeaderSize + file.Offset, file.Size));
 }
Exemplo n.º 3
0
 public Stream OpenFile(PfsFileEntry file)
 {
     return(StreamSource.CreateStream(HeaderSize + file.Offset, file.Size));
 }