Example #1
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(),
                InodeBlockSig    = DinodeS64.ReadFromStream(s)
            };

            s.Position = start + 0x370;
            hdr.Seed   = s.ReadBytes(16);
            return(hdr);
        }
Example #2
0
        void Setup()
        {
            // TODO: Combine the superroot-specific stuff with the rest of the data block writing.
            // I think this is as simple as adding superroot and flat_path_table to allNodes

            // This doesn't seem to really matter when verifying a PKG so use all zeroes for now
            var seed = new byte[16];

            // Insert header digest to be calculated with the rest of the digests
            final_sigs.Push(new BlockSigInfo(0, 0x380, 0x5A0));
            hdr = new PfsHeader
            {
                BlockSize = properties.BlockSize,
                ReadOnly  = 1,
                Mode      = (properties.Sign ? PfsMode.Signed : 0)
                            | (properties.Encrypt ? PfsMode.Encrypted : 0)
                            | PfsMode.UnknownFlagAlwaysSet,
                UnknownIndex = 1,
                Seed         = properties.Encrypt || properties.Sign ? seed : null
            };
            inodes = new List <inode>();

            Log("Setting up filesystem structure...");
            SetupRootStructure();
            allDirs = root.GetAllChildrenDirs();
            //allFiles = root.GetAllChildrenFiles().Where(f => f.Parent?.name != "sce_sys" || !PKG.EntryNames.NameToId.ContainsKey(f.name)).ToList();
            allNodes = new List <FSNode>(allDirs.Count);
            //allNodes.AddRange(allFiles);

            Log($"Creating inodes ({allDirs.Count} dirs and {allFiles.Count} files)...");
            addDirInodes();
            addFileInodes();

            fpt = new FlatPathTable(allNodes);

            Log("Calculating data block layout...");
            allNodes.Insert(0, root);
            CalculateDataBlockLayout();
        }