public static PfsHeader ReadFromStream(System.IO.Stream s)
        {
            var start = s.Position;
            var hdr   = new PfsHeader
            {
                Version          = s.ReadInt64LE(),
                Magic            = s.ReadInt64LE(),
                Id               = s.ReadInt64LE(),
                Fmode            = s.ReadUInt8(),
                Clean            = s.ReadUInt8(),
                ReadOnly         = s.ReadUInt8(),
                Rsv              = s.ReadUInt8(),
                Mode             = (PfsMode)s.ReadUInt16LE(),
                Unk1             = s.ReadUInt16LE(),
                BlockSize        = s.ReadUInt32LE(),
                NBackup          = s.ReadUInt32LE(),
                NBlock           = s.ReadInt64LE(),
                DinodeCount      = s.ReadInt64LE(),
                Ndblock          = s.ReadInt64LE(),
                DinodeBlockCount = s.ReadInt64LE(),
                InodeBlockSig    = DinodeS64.ReadFromStream(s)
            };

            s.Position = start + 0x370;
            hdr.Seed   = s.ReadBytes(16);
            return(hdr);
        }
Example #2
0
        public static PfsHeader ReadFromStream(System.IO.Stream s)
        {
            var start = s.Position;
            var hdr   = new PfsHeader
            {
                Version          = s.ReadInt64LE(),
                Magic            = s.ReadInt64LE(),
                Id               = s.ReadInt64LE(),
                Fmode            = s.ReadUInt8(),
                Clean            = s.ReadUInt8(),
                ReadOnly         = s.ReadUInt8(),
                Rsv              = s.ReadUInt8(),
                Mode             = (PfsMode)s.ReadUInt16LE(),
                Unk1             = s.ReadUInt16LE(),
                BlockSize        = s.ReadUInt32LE(),
                NBackup          = s.ReadUInt32LE(),
                NBlock           = s.ReadInt64LE(),
                DinodeCount      = s.ReadInt64LE(),
                Ndblock          = s.ReadInt64LE(),
                DinodeBlockCount = s.ReadInt64LE(),
            };

            s.Position       += 8; // skip a 64-bit zero
            hdr.InodeBlockSig = DinodeS64.ReadFromStream(s);
            if (hdr.Version != 1 || hdr.Magic != 20130315)
            {
                throw new InvalidDataException($"Invalid PFS superblock version ({hdr.Version}) or magic ({hdr.Magic})");
            }
            s.Position = start + 0x370;
            hdr.Seed   = s.ReadBytes(16);
            return(hdr);
        }
        public static DinodeS64 ReadFromStream(Stream s)
        {
            var di = new DinodeS64
            {
                Mode           = (InodeMode)s.ReadUInt16LE(),
                Nlink          = s.ReadUInt16LE(),
                Flags          = (InodeFlags)s.ReadUInt32LE(),
                Size           = s.ReadInt64LE(),
                SizeCompressed = s.ReadInt64LE(),
                Time1_sec      = s.ReadInt64LE(),
                Time2_sec      = s.ReadInt64LE(),
                Time3_sec      = s.ReadInt64LE(),
                Time4_sec      = s.ReadInt64LE(),
                Time1_nsec     = s.ReadUInt32LE(),
                Time2_nsec     = s.ReadUInt32LE(),
                Time3_nsec     = s.ReadUInt32LE(),
                Time4_nsec     = s.ReadUInt32LE(),
                Uid            = s.ReadUInt32LE(),
                Gid            = s.ReadUInt32LE(),
                Unk1           = s.ReadUInt64LE(),
                Unk2           = s.ReadUInt64LE(),
                Blocks         = (uint)s.ReadInt64LE(),
                db             = new block_sig64[12],
                ib             = new block_sig64[5],
            };

            for (var i = 0; i < 12; i++)
            {
                di.db[i] = new block_sig64
                {
                    sig   = s.ReadBytes(32),
                    block = s.ReadInt64LE()
                }
            }
            ;
            for (var i = 0; i < 5; i++)
            {
                di.ib[i] = new block_sig64
                {
                    sig   = s.ReadBytes(32),
                    block = s.ReadInt64LE()
                }
            }
            ;
            return(di);
        }
    };