Ejemplo n.º 1
0
        public IndirectStorage(IStorage bucketTreeData, bool leaveOpen, params IStorage[] sources)
        {
            Sources.AddRange(sources);

            LeaveOpen = leaveOpen;

            BucketTree = new BucketTree <RelocationEntry>(bucketTreeData);

            RelocationEntries = BucketTree.GetEntryList();
            RelocationOffsets = RelocationEntries.Select(x => x.Offset).ToList();

            Length = BucketTree.BucketOffsets.OffsetEnd;
        }
Ejemplo n.º 2
0
        public IndirectStorage(IStorage bucketTreeHeader, IStorage bucketTreeData, bool leaveOpen, params IStorage[] sources)
        {
            Sources.AddRange(sources);

            if (!leaveOpen)
            {
                ToDispose.AddRange(sources);
            }

            BucketTree = new BucketTree <RelocationEntry>(bucketTreeHeader, bucketTreeData);

            RelocationEntries = BucketTree.GetEntryList();
            RelocationOffsets = RelocationEntries.Select(x => x.Offset).ToList();

            _length = BucketTree.BucketOffsets.OffsetEnd;
        }
Ejemplo n.º 3
0
        public Bktr(Stream patchRomfs, Stream baseRomfs, NcaSection section)
        {
            if (section.Header.EncryptionType != NcaEncryptionType.AesCtrEx)
            {
                throw new ArgumentException("Section is not of type BKTR");
            }
            Patch = patchRomfs ?? throw new NullReferenceException($"{nameof(patchRomfs)} cannot be null");
            Base  = baseRomfs ?? throw new NullReferenceException($"{nameof(baseRomfs)} cannot be null");

            IvfcLevelHeader level5 = section.Header.IvfcInfo.LevelHeaders[5];

            Length = level5.LogicalOffset + level5.HashDataSize;

            using (var reader = new BinaryReader(patchRomfs, Encoding.Default, true))
            {
                patchRomfs.Position = section.Header.BktrInfo.RelocationHeader.Offset;
                RelocationBlock     = new RelocationBlock(reader);
            }

            foreach (RelocationBucket bucket in RelocationBlock.Buckets)
            {
                RelocationEntries.AddRange(bucket.Entries);
            }

            for (int i = 0; i < RelocationEntries.Count - 1; i++)
            {
                RelocationEntries[i].Next          = RelocationEntries[i + 1];
                RelocationEntries[i].VirtOffsetEnd = RelocationEntries[i + 1].VirtOffset;
            }

            RelocationEntries[RelocationEntries.Count - 1].VirtOffsetEnd = level5.LogicalOffset + level5.HashDataSize;
            RelocationOffsets = RelocationEntries.Select(x => x.VirtOffset).ToList();

            CurrentEntry = GetRelocationEntry(0);
            UpdateSourceStreamPositions();
        }