Ejemplo n.º 1
0
            public static async Task <Arm11LocalSystemCapabilities> Load(IReadOnlyBinaryDataAccessor data)
            {
                var capabilities = new Arm11LocalSystemCapabilities
                {
                    ProgramId   = await data.ReadInt64Async(0),
                    CoreVersion = await data.ReadInt32Async(0x8),
                    Flag1       = await data.ReadByteAsync(0xC),
                    Flag2       = await data.ReadByteAsync(0xD),
                    Flag0       = await data.ReadByteAsync(0xE),
                    Priority    = await data.ReadByteAsync(0xF),
                    ResourceLimitDescriptors = await data.ReadArrayAsync(0x10, 0x20),
                    StorageInformation       = await StorageInfo.Load(data.Slice(0x30, 0x20)),
                };

                var accessControl = new long[32];
                await AsyncFor.For(0, 32 - 1, async i =>
                {
                    accessControl[i] = await data.ReadInt64Async(0x50 + 8 * i);
                });

                capabilities.ServiceAccessControl         = accessControl;
                capabilities.ExtendedServiceAccessControl = new long[] { await data.ReadInt64Async(0x150), await data.ReadInt64Async(0x158) };
                capabilities.Reserved = await data.ReadArrayAsync(0x160, 0xF);

                capabilities.ResourceLimitCategory = await data.ReadByteAsync(0x16F);

                return(capabilities);
            }
Ejemplo n.º 2
0
            public override async ValueTask <(int, int)?> ReadAsync(IReadOnlyBinaryDataAccessor data, long position, byte[] dest, int offset, int count)
            {
                if (byteCount <= 0)
                {
                    return(null);
                }

                var toWrite = Math.Min(count, byteCount);
                var toRead  = Math.Max(toWrite / 2, (byteCount + 1) % 2);

                var bytes = await data.ReadArrayAsync(position, toRead);

                for (int i = 0; i < toWrite; i++)
                {
                    if ((byteCount + i) % 2 == 0)
                    {
                        dest[offset + i] = separator;
                    }
                    else
                    {
                        dest[offset + i] = bytes[i / 2];
                    }
                }

                byteCount -= toWrite;
                return(toRead, toWrite);
            }
Ejemplo n.º 3
0
            public static async Task <DirectoryMetadata> Load(IReadOnlyBinaryDataAccessor data, IvfcLevelHeader header, int offsetOffDirTable)
            {
                var offset   = header.DirectoryMetadataTableOffset + offsetOffDirTable;
                var metadata = new DirectoryMetadata(data, header);

                metadata.ParentDirectoryOffset = await data.ReadInt32Async(offset + 0);

                metadata.SiblingDirectoryOffset = await data.ReadInt32Async(offset + 4);

                metadata.FirstChildDirectoryOffset = await data.ReadInt32Async(offset + 8);

                metadata.FirstFileOffset = await data.ReadInt32Async(offset + 0xC);

                metadata.NextDirectoryOffset = await data.ReadInt32Async(offset + 0x10);

                metadata.NameLength = await data.ReadInt32Async(offset + 0x14);

                if (metadata.NameLength > 0)
                {
                    metadata.Name = Encoding.Unicode.GetString(await data.ReadArrayAsync(offset + 0x18, Math.Min(metadata.NameLength, MaxFilenameLength)));
                }

                await Task.WhenAll(
                    metadata.LoadChildDirectories(),
                    metadata.LoadChildFiles()
                    );

                return(metadata);
            }
Ejemplo n.º 4
0
            public static async Task <IvfcLevel> Load(IReadOnlyBinaryDataAccessor romfsData, IvfcLevelLocation location)
            {
                var header = new IvfcLevelHeader(await romfsData.ReadArrayAsync(location.DataOffset, 0x28));
                var level  = new IvfcLevel(romfsData.Slice(location.DataOffset, location.DataSize), header);
                await level.Initialize();

                return(level);
            }
Ejemplo n.º 5
0
        /// <summary>
        /// Loads an existing ROM file system from the given data.
        /// </summary>
        /// <param name="data">Accessor to the raw data to load as a ROM file system</param>
        /// <returns>The ROM file system the given data represents</returns>
        public static async Task <RomFs> Load(IReadOnlyBinaryDataAccessor data)
        {
            var header = new RomFsHeader(await data.ReadArrayAsync(0, 0x6B));
            var romfs  = new RomFs(data, header);
            await romfs.Initialize();

            return(romfs);
        }
Ejemplo n.º 6
0
 public static async Task <Arm9AccessControl> Load(IReadOnlyBinaryDataAccessor data)
 {
     return(new Arm9AccessControl
     {
         Descriptors = (Descriptor)(await data.ReadInt64Async(0)),
         Descriptors2 = await data.ReadArrayAsync(0x8, 0x7),
         Version = await data.ReadByteAsync(0xF)
     });
 }
Ejemplo n.º 7
0
 public static async Task <SystemInfo> Load(IReadOnlyBinaryDataAccessor data)
 {
     return(new SystemInfo
     {
         SaveDataSize = await data.ReadInt64Async(0),
         JumpId = await data.ReadInt64Async(8),
         Reserved = await data.ReadArrayAsync(0x10, 0x30)
     });
 }
Ejemplo n.º 8
0
        public static async Task <NcchExtendedHeader> Load(IReadOnlyBinaryDataAccessor data)
        {
            var header = new NcchExtendedHeader
            {
                ApplicationTitle    = await data.ReadStringAsync(0, 8, Encoding.ASCII),
                Reserved1           = await data.ReadArrayAsync(8, 5),
                Flag                = await data.ReadByteAsync(0xD),
                RemasterVersion     = await data.ReadInt16Async(0xE),
                TextCodeSetInfo     = await CodeSetInfo.Load(data.Slice(0x10, 0xC)),
                StackSize           = await data.ReadInt32Async(0x1C),
                ReadOnlyCodeSetInfo = await CodeSetInfo.Load(data.Slice(0x20, 0xC)),
                Reserved2           = await data.ReadInt32Async(0x2C),
                DataCodeSetInfo     = await CodeSetInfo.Load(data.Slice(0x30, 0xC)),
                BssSize             = await data.ReadInt32Async(0x3C)
            };

            var moduleIds = new long[48];
            await AsyncFor.For(0, 48 - 1, async i =>
            {
                moduleIds[i] = await data.ReadInt64Async(0x40 + i * 8);
            });

            header.DependencyModuleIds = moduleIds;

            header.SystemInformation = await SystemInfo.Load(data.Slice(0x1C0, 0x40));

            header.LocalSystemCapabilities = await Arm11LocalSystemCapabilities.Load(data.Slice(0x200, 0x170));

            header.KernelCapabilities = await Arm11KernelCapabilities.Load(data.Slice(0x370, 0x80));

            header.AccessControl = await Arm9AccessControl.Load(data.Slice(0x3F0, 0x10));

            header.AccessDescSignature = await data.ReadArrayAsync(0x400, 0x100);

            header.NcchHdrPublicKey = await data.ReadArrayAsync(0x500, 0x100);

            header.Aci = await data.ReadArrayAsync(0x600, 0x200);

            return(header);
        }
Ejemplo n.º 9
0
            public override async ValueTask <(int, int)?> ReadAsync(IReadOnlyBinaryDataAccessor data, long position, byte[] dest, int offset, int count)
            {
                if (byteCount <= 0)
                {
                    return(null);
                }

                var bytes = await data.ReadArrayAsync(position, Math.Min(count, byteCount));

                bytes.CopyTo(dest, offset);
                byteCount -= bytes.Length;
                return(bytes.Length, bytes.Length);
            }
Ejemplo n.º 10
0
            public static async Task <Arm11KernelCapabilities> Load(IReadOnlyBinaryDataAccessor data)
            {
                var capabilities = new Arm11KernelCapabilities();
                var descriptors  = new int[28];
                await AsyncFor.For(0, 28 - 1, async i =>
                {
                    descriptors[i] = await data.ReadInt32Async(i * 4);
                });

                capabilities.Descriptors = descriptors;
                capabilities.Reserved    = await data.ReadArrayAsync(0x70, 0x10);

                return(capabilities);
            }
Ejemplo n.º 11
0
        public static async Task <NcchPartition> Load(IReadOnlyBinaryDataAccessor data)
        {
            NcchHeader?header = null;

            if (data.Length > 0)
            {
                header = new NcchHeader(await data.ReadArrayAsync(0, 0x200));
            }

            var partition = new NcchPartition(header);
            await partition.Initialize(data);

            return(partition);
        }
Ejemplo n.º 12
0
        public static async Task <NcsdFile> Load(IReadOnlyBinaryDataAccessor data)
        {
            var header     = new CartridgeNcsdHeader(await data.ReadArrayAsync(0, 0x1500));
            var partitions = new NcchPartition[header.Partitions.Length];

            await Task.WhenAll(Enumerable.Range(0, header.Partitions.Length).Select(async i =>
            {
                var partitionStart  = (long)header.Partitions[i].Offset * MediaUnitSize;
                var partitionLength = (long)header.Partitions[i].Length * MediaUnitSize;
                partitions[i]       = await NcchPartition.Load(data.Slice(partitionStart, partitionLength));
            }));

            return(new NcsdFile(header, partitions));
        }
Ejemplo n.º 13
0
        public async Task Initialize(IReadOnlyBinaryDataAccessor data)
        {
            this.RawData = data;
            if (Header != null && Header.RomFsSize > 0)
            {
                if (Header.ExeFsOffset > 0 && Header.ExeFsSize > 0)
                {
                    ExeFs = await ExeFs.Load(data.Slice((long)Header.ExeFsOffset *MediaUnitSize, (long)Header.ExeFsSize *MediaUnitSize));
                }
                if (Header.RomFsOffset > 0 && Header.RomFsOffset > 0)
                {
                    RomFs = await RomFs.Load(data.Slice((long)Header.RomFsOffset *MediaUnitSize, (long)Header.RomFsSize *MediaUnitSize));
                }
                if (Header.ExHeaderSize > 0)
                {
                    ExHeader = await NcchExtendedHeader.Load(data.Slice(0x200, Header.ExHeaderSize));
                }

                PlainRegion = await data.ReadStringAsync(Header.PlainRegionOffset *MediaUnitSize, Header.PlainRegionSize *MediaUnitSize, Encoding.ASCII);

                Logo = await data.ReadArrayAsync(Header.LogoRegionOffset *MediaUnitSize, Header.LogoRegionSize *MediaUnitSize);
            }
        }
Ejemplo n.º 14
0
            public static async Task <FileMetadata> Load(IReadOnlyBinaryDataAccessor data, IvfcLevelHeader header, long offsetFromMetadataTable)
            {
                var offset   = header.FileMetadataTableOffset + offsetFromMetadataTable;
                var metadata = new FileMetadata(data, header);

                metadata.ContainingDirectoryOffset = await data.ReadInt32Async(offset + 0);

                metadata.NextSiblingFileOffset = await data.ReadInt32Async(offset + 4);

                metadata.FileDataOffset = await data.ReadInt64Async(offset + 8);

                metadata.FileDataLength = await data.ReadInt64Async(offset + 0x10);

                metadata.NextFileOffset = await data.ReadInt32Async(offset + 0x18);

                metadata.NameLength = await data.ReadInt32Async(offset + 0x1C);

                if (metadata.NameLength > 0)
                {
                    metadata.Name = Encoding.Unicode.GetString(await data.ReadArrayAsync(offset + 0x20, Math.Min(metadata.NameLength, MaxFilenameLength)));
                }
                return(metadata);
            }
Ejemplo n.º 15
0
        public static async Task <byte[]> GetSuperblockHash(SHA256 sha, IReadOnlyBinaryDataAccessor data, RomFsHeader header)
        {
            var buffer = await data.ReadArrayAsync(0, header.MasterHashSize);

            return(sha.ComputeHash(buffer));
        }