From ea49386b486b51dbfb0d7a360379978801fa0847 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Sun, 17 Mar 2024 09:32:59 -0700 Subject: [PATCH] Add StorageOnNcaCreator --- src/LibHac/Fs/ContentAttributes.cs | 7 + .../FsSrv/FsCreator/IStorageOnNcaCreator.cs | 24 ++- .../FsCreator/RomResultConvertStorage.cs | 57 ++++++ .../FsSrv/FsCreator/RomResultConverter.cs | 183 ++++++++++++++++++ .../FsSrv/FsCreator/StorageOnNcaCreator17.cs | 84 ++++++++ src/LibHac/FsSystem/NcaFileSystemDriver.cs | 169 ++++++++++------ src/LibHac/FsSystem/NcaReader17.cs | 4 + 7 files changed, 466 insertions(+), 62 deletions(-) create mode 100644 src/LibHac/Fs/ContentAttributes.cs create mode 100644 src/LibHac/FsSrv/FsCreator/RomResultConvertStorage.cs create mode 100644 src/LibHac/FsSrv/FsCreator/RomResultConverter.cs create mode 100644 src/LibHac/FsSrv/FsCreator/StorageOnNcaCreator17.cs diff --git a/src/LibHac/Fs/ContentAttributes.cs b/src/LibHac/Fs/ContentAttributes.cs new file mode 100644 index 00000000..b7838b69 --- /dev/null +++ b/src/LibHac/Fs/ContentAttributes.cs @@ -0,0 +1,7 @@ +namespace LibHac.Fs; + +public enum ContentAttributes : byte +{ + None = 0, + All = 0xF +} \ No newline at end of file diff --git a/src/LibHac/FsSrv/FsCreator/IStorageOnNcaCreator.cs b/src/LibHac/FsSrv/FsCreator/IStorageOnNcaCreator.cs index 46378436..79b1cf37 100644 --- a/src/LibHac/FsSrv/FsCreator/IStorageOnNcaCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/IStorageOnNcaCreator.cs @@ -1,14 +1,26 @@ using LibHac.Common; using LibHac.Fs; -using LibHac.Fs.Fsa; -using LibHac.Tools.FsSystem.NcaUtils; +using LibHac.FsSystem; namespace LibHac.FsSrv.FsCreator; public interface IStorageOnNcaCreator { - Result Create(ref SharedRef outStorage, out NcaFsHeader fsHeader, Nca nca, int fsIndex, bool isCodeFs); - Result CreateWithPatch(ref SharedRef outStorage, out NcaFsHeader fsHeader, Nca baseNca, Nca patchNca, int fsIndex, bool isCodeFs); - Result OpenNca(out Nca nca, IStorage ncaStorage); - Result VerifyAcidSignature(IFileSystem codeFileSystem, Nca nca); + Result Create(ref SharedRef outStorage, out LibHac.Tools.FsSystem.NcaUtils.NcaFsHeader fsHeader, LibHac.Tools.FsSystem.NcaUtils.Nca nca, int fsIndex, bool isCodeFs); + Result OpenNca(out LibHac.Tools.FsSystem.NcaUtils.Nca nca, IStorage ncaStorage); +} + +public interface IStorageOnNcaCreator17 +{ + Result Create(ref SharedRef outStorage, + ref SharedRef outStorageAccessSplitter, out NcaFsHeaderReader17 outHeaderReader, + ref readonly SharedRef ncaReader, int fsIndex); + + Result CreateWithPatch(ref SharedRef outStorage, + ref SharedRef outStorageAccessSplitter, out NcaFsHeaderReader17 outHeaderReader, + ref readonly SharedRef originalNcaReader, ref readonly SharedRef currentNcaReader, + int fsIndex); + + Result CreateNcaReader(ref SharedRef outReader, ref readonly SharedRef baseStorage, + ContentAttributes contentAttributes); } \ No newline at end of file diff --git a/src/LibHac/FsSrv/FsCreator/RomResultConvertStorage.cs b/src/LibHac/FsSrv/FsCreator/RomResultConvertStorage.cs new file mode 100644 index 00000000..92dcf5dd --- /dev/null +++ b/src/LibHac/FsSrv/FsCreator/RomResultConvertStorage.cs @@ -0,0 +1,57 @@ +using System; +using LibHac.Common; +using LibHac.Fs; + +namespace LibHac.FsSrv.FsCreator; + +/// +/// Converts internal RomFS s returned by an to external s. +/// +/// Based on nnSdk 17.5.0 (FS 17.0.0) +public class RomResultConvertStorage : IStorage +{ + private SharedRef _baseStorage; + + public RomResultConvertStorage(ref readonly SharedRef baseStorage) + { + _baseStorage = SharedRef.CreateCopy(in baseStorage); + } + + public override void Dispose() + { + _baseStorage.Destroy(); + base.Dispose(); + } + + public override Result Read(long offset, Span destination) + { + return RomResultConverter.ConvertRomResult(_baseStorage.Get.Read(offset, destination)).Ret(); + } + + public override Result Write(long offset, ReadOnlySpan source) + { + return RomResultConverter.ConvertRomResult(_baseStorage.Get.Write(offset, source)).Ret(); + } + + public override Result Flush() + { + return RomResultConverter.ConvertRomResult(_baseStorage.Get.Flush()).Ret(); + } + + public override Result SetSize(long size) + { + return RomResultConverter.ConvertRomResult(_baseStorage.Get.SetSize(size)).Ret(); + } + + public override Result GetSize(out long size) + { + return RomResultConverter.ConvertRomResult(_baseStorage.Get.GetSize(out size)).Ret(); + } + + public override Result OperateRange(Span outBuffer, OperationId operationId, long offset, long size, + ReadOnlySpan inBuffer) + { + return RomResultConverter + .ConvertRomResult(_baseStorage.Get.OperateRange(outBuffer, operationId, offset, size, inBuffer)).Ret(); + } +} \ No newline at end of file diff --git a/src/LibHac/FsSrv/FsCreator/RomResultConverter.cs b/src/LibHac/FsSrv/FsCreator/RomResultConverter.cs new file mode 100644 index 00000000..5d265797 --- /dev/null +++ b/src/LibHac/FsSrv/FsCreator/RomResultConverter.cs @@ -0,0 +1,183 @@ +using LibHac.Diag; +using LibHac.Fs; + +namespace LibHac.FsSrv.FsCreator; + +/// +/// Converts internal RomFS values to external s. +/// +/// Based on nnSdk 17.5.0 (FS 17.0.0) +public static class RomResultConverter +{ + private static Result ConvertCorruptedResult(Result result) + { + if (ResultFs.NcaCorrupted.Includes(result)) + { + if (ResultFs.InvalidNcaFileSystemType.Includes(result)) + return ResultFs.InvalidRomNcaFileSystemType.LogConverted(result); + + if (ResultFs.InvalidNcaSignature.Includes(result)) + return ResultFs.InvalidRomNcaSignature.LogConverted(result); + + if (ResultFs.NcaHeaderSignature1VerificationFailed.Includes(result)) + return ResultFs.RomNcaHeaderSignature1VerificationFailed.LogConverted(result); + + if (ResultFs.NcaFsHeaderHashVerificationFailed.Includes(result)) + return ResultFs.RomNcaFsHeaderHashVerificationFailed.LogConverted(result); + + if (ResultFs.InvalidNcaKeyIndex.Includes(result)) + return ResultFs.InvalidRomNcaKeyIndex.LogConverted(result); + + if (ResultFs.InvalidNcaFsHeaderHashType.Includes(result)) + return ResultFs.InvalidRomNcaFsHeaderHashType.LogConverted(result); + + if (ResultFs.InvalidNcaFsHeaderEncryptionType.Includes(result)) + return ResultFs.InvalidRomNcaFsHeaderEncryptionType.LogConverted(result); + + if (ResultFs.InvalidNcaPatchInfoIndirectSize.Includes(result)) + return ResultFs.InvalidRomNcaPatchInfoIndirectSize.LogConverted(result); + + if (ResultFs.InvalidNcaPatchInfoAesCtrExSize.Includes(result)) + return ResultFs.InvalidRomNcaPatchInfoAesCtrExSize.LogConverted(result); + + if (ResultFs.InvalidNcaPatchInfoAesCtrExOffset.Includes(result)) + return ResultFs.InvalidRomNcaPatchInfoAesCtrExOffset.LogConverted(result); + + if (ResultFs.InvalidNcaId.Includes(result)) + return ResultFs.InvalidRomNcaId.LogConverted(result); + + if (ResultFs.InvalidNcaHeader.Includes(result)) + return ResultFs.InvalidRomNcaHeader.LogConverted(result); + + if (ResultFs.InvalidNcaFsHeader.Includes(result)) + return ResultFs.InvalidRomNcaFsHeader.LogConverted(result); + + if (ResultFs.InvalidNcaPatchInfoIndirectOffset.Includes(result)) + return ResultFs.InvalidRomNcaPatchInfoIndirectOffset.LogConverted(result); + + if (ResultFs.InvalidHierarchicalSha256BlockSize.Includes(result)) + return ResultFs.InvalidRomHierarchicalSha256BlockSize.LogConverted(result); + + if (ResultFs.InvalidHierarchicalSha256LayerCount.Includes(result)) + return ResultFs.InvalidRomHierarchicalSha256LayerCount.LogConverted(result); + + if (ResultFs.HierarchicalSha256BaseStorageTooLarge.Includes(result)) + return ResultFs.RomHierarchicalSha256BaseStorageTooLarge.LogConverted(result); + + if (ResultFs.HierarchicalSha256HashVerificationFailed.Includes(result)) + return ResultFs.RomHierarchicalSha256HashVerificationFailed.LogConverted(result); + + if (ResultFs.InvalidHierarchicalIntegrityVerificationLayerCount.Includes(result)) + return ResultFs.InvalidRomHierarchicalIntegrityVerificationLayerCount.LogConverted(result); + + if (ResultFs.NcaIndirectStorageOutOfRange.Includes(result)) + return ResultFs.RomNcaIndirectStorageOutOfRange.LogConverted(result); + + if (ResultFs.NcaInvalidCompressionInfo.Includes(result)) + return ResultFs.RomNcaInvalidCompressionInfo.LogConverted(result); + + Assert.SdkAssert(ResultFs.InvalidNcaHeader1SignatureKeyGeneration.Includes(result), $"Unknown Result 0x{result.Value:X8}"); + return result.Rethrow(); + } + + if (ResultFs.IntegrityVerificationStorageCorrupted.Includes(result)) + { + if (ResultFs.IncorrectIntegrityVerificationMagicCode.Includes(result)) + return ResultFs.IncorrectRomIntegrityVerificationMagicCode.LogConverted(result); + + if (ResultFs.InvalidZeroHash.Includes(result)) + return ResultFs.InvalidRomZeroSignature.LogConverted(result); + + if (ResultFs.NonRealDataVerificationFailed.Includes(result)) + return ResultFs.RomNonRealDataVerificationFailed.LogConverted(result); + + if (ResultFs.ClearedRealDataVerificationFailed.Includes(result)) + return ResultFs.ClearedRomRealDataVerificationFailed.LogConverted(result); + + if (ResultFs.UnclearedRealDataVerificationFailed.Includes(result)) + return ResultFs.UnclearedRomRealDataVerificationFailed.LogConverted(result); + + Assert.SdkAssert(false, $"Unknown Result 0x{result.Value:X8}"); + return result.Rethrow(); + } + + if (ResultFs.PartitionFileSystemCorrupted.Includes(result)) + { + if (ResultFs.InvalidSha256PartitionHashTarget.Includes(result)) + return ResultFs.InvalidRomSha256PartitionHashTarget.LogConverted(result); + + if (ResultFs.Sha256PartitionHashVerificationFailed.Includes(result)) + return ResultFs.RomSha256PartitionHashVerificationFailed.LogConverted(result); + + if (ResultFs.PartitionSignatureVerificationFailed.Includes(result)) + return ResultFs.RomPartitionSignatureVerificationFailed.LogConverted(result); + + if (ResultFs.Sha256PartitionSignatureVerificationFailed.Includes(result)) + return ResultFs.RomSha256PartitionSignatureVerificationFailed.LogConverted(result); + + if (ResultFs.InvalidPartitionEntryOffset.Includes(result)) + return ResultFs.InvalidRomPartitionEntryOffset.LogConverted(result); + + if (ResultFs.InvalidSha256PartitionMetaDataSize.Includes(result)) + return ResultFs.InvalidRomSha256PartitionMetaDataSize.LogConverted(result); + + Assert.SdkAssert(false, $"Unknown Result 0x{result.Value:X8}"); + return result.Rethrow(); + } + + if (ResultFs.HostFileSystemCorrupted.Includes(result)) + { + if (ResultFs.HostEntryCorrupted.Includes(result)) + return ResultFs.RomHostEntryCorrupted.LogConverted(result); + + if (ResultFs.HostFileDataCorrupted.Includes(result)) + return ResultFs.RomHostFileDataCorrupted.LogConverted(result); + + if (ResultFs.HostFileCorrupted.Includes(result)) + return ResultFs.RomHostFileCorrupted.LogConverted(result); + + if (ResultFs.InvalidHostHandle.Includes(result)) + return ResultFs.InvalidRomHostHandle.LogConverted(result); + + Assert.SdkAssert(false, $"Unknown Result 0x{result.Value:X8}"); + return result.Rethrow(); + } + + if (result.IsSuccess()) + return Result.Success; + + return result.Miss(); + } + + public static Result ConvertRomResult(Result result) + { + if (result.IsSuccess()) + return Result.Success; + + if (ResultFs.UnsupportedVersion.Includes(result)) + return ResultFs.UnsupportedRomVersion.LogConverted(result); + + if (ResultFs.NcaCorrupted.Includes(result) || + ResultFs.IntegrityVerificationStorageCorrupted.Includes(result) || + ResultFs.BuiltInStorageCorrupted.Includes(result) || + ResultFs.PartitionFileSystemCorrupted.Includes(result) || + ResultFs.HostFileSystemCorrupted.Includes(result)) + { + return ConvertCorruptedResult(result); + } + + if (ResultFs.FatFileSystemCorrupted.Includes(result)) + return result.Miss(); + + if (ResultFs.NotFound.Includes(result)) + return ResultFs.PathNotFound.LogConverted(result); + + if (ResultFs.FileNotFound.Includes(result) || + ResultFs.IncompatiblePath.Includes(result)) + { + return ResultFs.PathNotFound.LogConverted(result); + } + + return result; + } +} \ No newline at end of file diff --git a/src/LibHac/FsSrv/FsCreator/StorageOnNcaCreator17.cs b/src/LibHac/FsSrv/FsCreator/StorageOnNcaCreator17.cs new file mode 100644 index 00000000..9e311964 --- /dev/null +++ b/src/LibHac/FsSrv/FsCreator/StorageOnNcaCreator17.cs @@ -0,0 +1,84 @@ +using LibHac.Common; +using LibHac.Fs; +using LibHac.FsSystem; + +namespace LibHac.FsSrv.FsCreator; + +/// +/// Opens the partitions in NCAs as s. +/// +/// Based on nnSdk 17.5.0 (FS 17.0.0) +public class StorageOnNcaCreator17 : IStorageOnNcaCreator17 +{ + private MemoryResource _memoryResource; + private NcaCompressionConfiguration _compressionConfig; + private IBufferManager _bufferManager; + private NcaReaderInitializer _ncaReaderInitializer; + private IHash256GeneratorFactorySelector _hashGeneratorFactorySelector; + + public StorageOnNcaCreator17(MemoryResource memoryResource, IBufferManager bufferManager, + NcaReaderInitializer ncaReaderInitializer, in NcaCompressionConfiguration compressionConfig, + IHash256GeneratorFactorySelector hashGeneratorFactorySelector) + { + _memoryResource = memoryResource; + _compressionConfig = compressionConfig; + _bufferManager = bufferManager; + _ncaReaderInitializer = ncaReaderInitializer; + _hashGeneratorFactorySelector = hashGeneratorFactorySelector; + } + + public Result Create(ref SharedRef outStorage, + ref SharedRef outStorageAccessSplitter, out NcaFsHeaderReader17 outHeaderReader, + ref readonly SharedRef ncaReader, int fsIndex) + { + var ncaFsDriver = new NcaFileSystemDriver(in ncaReader, _memoryResource, _bufferManager, _hashGeneratorFactorySelector); + + using var storage = new SharedRef(); + using var storageAccessSplitter = new SharedRef(); + Result res = RomResultConverter.ConvertRomResult(ncaFsDriver.OpenStorage(ref storage.Ref, + ref storageAccessSplitter.Ref, out outHeaderReader, fsIndex)); + if (res.IsFailure()) return res.Miss(); + + using var resultConvertStorage = new SharedRef(new RomResultConvertStorage(in storage)); + + outStorage.SetByMove(ref resultConvertStorage.Ref); + outStorageAccessSplitter.SetByMove(ref storageAccessSplitter.Ref); + + return Result.Success; + } + + public Result CreateWithPatch(ref SharedRef outStorage, + ref SharedRef outStorageAccessSplitter, out NcaFsHeaderReader17 outHeaderReader, + ref readonly SharedRef originalNcaReader, ref readonly SharedRef currentNcaReader, + int fsIndex) + { + var ncaFsDriver = new NcaFileSystemDriver(in originalNcaReader, in currentNcaReader, _memoryResource, + _bufferManager, _hashGeneratorFactorySelector); + + using var storage = new SharedRef(); + using var storageAccessSplitter = new SharedRef(); + Result res = RomResultConverter.ConvertRomResult(ncaFsDriver.OpenStorage(ref storage.Ref, + ref storageAccessSplitter.Ref, out outHeaderReader, fsIndex)); + if (res.IsFailure()) return res.Miss(); + + using var resultConvertStorage = new SharedRef(new RomResultConvertStorage(in storage)); + + outStorage.SetByMove(ref resultConvertStorage.Ref); + outStorageAccessSplitter.SetByMove(ref storageAccessSplitter.Ref); + + return Result.Success; + } + + public Result CreateNcaReader(ref SharedRef outReader, ref readonly SharedRef baseStorage, + ContentAttributes contentAttributes) + { + using var ncaReader = new SharedRef(); + + Result res = RomResultConverter.ConvertRomResult(_ncaReaderInitializer(ref ncaReader.Ref, in baseStorage, + in _compressionConfig, _hashGeneratorFactorySelector, contentAttributes)); + if (res.IsFailure()) return res.Miss(); + + outReader.SetByMove(ref ncaReader.Ref); + return Result.Success; + } +} \ No newline at end of file diff --git a/src/LibHac/FsSystem/NcaFileSystemDriver.cs b/src/LibHac/FsSystem/NcaFileSystemDriver.cs index a4ade503..d31d651c 100644 --- a/src/LibHac/FsSystem/NcaFileSystemDriver.cs +++ b/src/LibHac/FsSystem/NcaFileSystemDriver.cs @@ -3,6 +3,7 @@ using System; using LibHac.Common; using LibHac.Common.FixedArrays; using LibHac.Crypto; +using LibHac.Diag; using LibHac.Fs; using LibHac.FsSrv; @@ -85,6 +86,75 @@ public enum KeyType SaveDataTransferMac = NcaCryptoConfiguration.KeyAreaEncryptionKeyCount + 5 } +file static class Anonymous +{ + public static long GetFsOffset(NcaReader17 reader, int index) + { + return (long)reader.GetFsOffset(index); + } + + public static long GetFsEndOffset(NcaReader17 reader, int index) + { + return (long)reader.GetFsEndOffset(index); + } +} + +file class SharedNcaBodyStorage : IStorage +{ + private SharedRef _storage; + private SharedRef _ncaReader; + + public SharedNcaBodyStorage(in SharedRef baseStorage, in SharedRef ncaReader) + { + _storage = SharedRef.CreateCopy(in baseStorage); + _ncaReader = SharedRef.CreateCopy(in ncaReader); + } + + public override void Dispose() + { + _storage.Destroy(); + _ncaReader.Destroy(); + base.Dispose(); + } + + public override Result Read(long offset, Span destination) + { + Assert.SdkRequiresNotNull(in _storage); + return _storage.Get.Read(offset, destination).Ret(); + } + + public override Result Write(long offset, ReadOnlySpan source) + { + Assert.SdkRequiresNotNull(in _storage); + return _storage.Get.Write(offset, source).Ret(); + } + + public override Result Flush() + { + Assert.SdkRequiresNotNull(in _storage); + return _storage.Get.Flush().Ret(); + } + + public override Result SetSize(long size) + { + Assert.SdkRequiresNotNull(in _storage); + return _storage.Get.SetSize(size).Ret(); + } + + public override Result GetSize(out long size) + { + Assert.SdkRequiresNotNull(in _storage); + return _storage.Get.GetSize(out size).Ret(); + } + + public override Result OperateRange(Span outBuffer, OperationId operationId, long offset, long size, + ReadOnlySpan inBuffer) + { + Assert.SdkRequiresNotNull(in _storage); + return _storage.Get.OperateRange(outBuffer, operationId, offset, size, inBuffer).Ret(); + } +} + public class NcaFileSystemDriver : IDisposable { [NonCopyableDisposable] @@ -132,14 +202,14 @@ public class NcaFileSystemDriver : IDisposable None = 1 } - public NcaFileSystemDriver(ref SharedRef ncaReader, MemoryResource allocator, + public NcaFileSystemDriver(ref readonly SharedRef ncaReader, MemoryResource allocator, IBufferManager bufferManager, IHash256GeneratorFactorySelector hashGeneratorFactorySelector) { throw new NotImplementedException(); } - public NcaFileSystemDriver(ref SharedRef originalNcaReader, ref SharedRef currentNcaReader, - MemoryResource allocator, IBufferManager bufferManager, + public NcaFileSystemDriver(ref readonly SharedRef originalNcaReader, + ref readonly SharedRef currentNcaReader, MemoryResource allocator, IBufferManager bufferManager, IHash256GeneratorFactorySelector hashGeneratorFactorySelector) { throw new NotImplementedException(); @@ -150,36 +220,21 @@ public class NcaFileSystemDriver : IDisposable throw new NotImplementedException(); } - private bool IsUsingHwAesCtrForSpeedEmulation(FileSystemServer fs) - { - throw new NotImplementedException(); - } - - private long GetFsOffset(NcaReader reader, int index) - { - return (long)reader.GetFsOffset(index); - } - - private long GetFsEndOffset(NcaReader reader, int index) - { - return (long)reader.GetFsEndOffset(index); - } - public Result OpenStorage(ref SharedRef outStorage, - ref SharedRef outStorageAccessSplitter, out NcaFsHeaderReader outHeaderReader, + ref SharedRef outStorageAccessSplitter, out NcaFsHeaderReader17 outHeaderReader, int fsIndex) { throw new NotImplementedException(); } - private Result OpenStorageImpl(ref SharedRef outStorage, out NcaFsHeaderReader outHeaderReader, + private Result OpenStorageImpl(ref SharedRef outStorage, out NcaFsHeaderReader17 outHeaderReader, int fsIndex, ref StorageContext storageContext) { throw new NotImplementedException(); } private Result OpenIndirectableStorageAsOriginal(ref SharedRef outStorage, - in NcaFsHeaderReader headerReader, ref StorageContext storageContext) + in NcaFsHeaderReader17 headerReader, ref StorageContext storageContext) { throw new NotImplementedException(); } @@ -189,7 +244,7 @@ public class NcaFileSystemDriver : IDisposable throw new NotImplementedException(); } - private Result CreateAesCtrStorage(ref SharedRef outStorage, ref SharedRef baseStorage, + private Result CreateAesCtrStorage(ref SharedRef outStorage, ref readonly SharedRef baseStorage, long offset, in NcaAesCtrUpperIv upperIv, AlignmentStorageRequirement alignmentRequirement) { throw new NotImplementedException(); @@ -202,22 +257,23 @@ public class NcaFileSystemDriver : IDisposable } private Result CreateSparseStorageMetaStorage(ref SharedRef outStorage, - ref SharedRef baseStorage, long offset, in NcaAesCtrUpperIv upperIv, in NcaSparseInfo sparseInfo) + ref readonly SharedRef baseStorage, long offset, in NcaAesCtrUpperIv upperIv, + in NcaSparseInfo sparseInfo) { throw new NotImplementedException(); } private Result CreateSparseStorageMetaStorageWithVerification(ref SharedRef outStorage, - ref SharedRef outLayerInfoStorage, ref SharedRef baseStorage, long offset, - in NcaAesCtrUpperIv upperIv, in NcaSparseInfo sparseInfo, in NcaMetaDataHashDataInfo metaDataHashDataInfo, - IHash256GeneratorFactory hashGeneratorFactory) + ref SharedRef outLayerInfoStorage, ref readonly SharedRef baseStorage, long offset, + NcaFsHeader.EncryptionType encryptionType, in NcaAesCtrUpperIv upperIv, in NcaSparseInfo sparseInfo, + in NcaMetaDataHashDataInfo metaDataHashDataInfo, IHash256GeneratorFactory hashGeneratorFactory) { throw new NotImplementedException(); } - private Result CreateSparseStorageCore(ref SharedRef outStorage, ref SharedRef baseStorage, - long baseStorageSize, ref SharedRef sparseStorageMetaStorage, in NcaSparseInfo sparseInfo, - bool hasExternalInfo) + private Result CreateSparseStorageCore(ref SharedRef outStorage, + ref readonly SharedRef baseStorage, long baseStorageSize, + ref readonly SharedRef sparseStorageMetaStorage, in NcaSparseInfo sparseInfo, bool hasExternalInfo) { throw new NotImplementedException(); } @@ -231,8 +287,8 @@ public class NcaFileSystemDriver : IDisposable private Result CreateSparseStorageWithVerification(ref SharedRef outStorage, out long outFsDataOffset, out SharedRef outSparseStorage, ref SharedRef outSparseStorageMetaStorage, - ref SharedRef outLayerInfoStorage, int index, in NcaAesCtrUpperIv upperIv, - in NcaSparseInfo sparseInfo, in NcaMetaDataHashDataInfo metaDataHashDataInfo, + ref SharedRef outLayerInfoStorage, int index, NcaFsHeader.EncryptionType encryptionType, + in NcaAesCtrUpperIv upperIv, in NcaSparseInfo sparseInfo, in NcaMetaDataHashDataInfo metaDataHashDataInfo, NcaFsHeader.MetaDataHashType metaDataHashType) { throw new NotImplementedException(); @@ -240,86 +296,87 @@ public class NcaFileSystemDriver : IDisposable private Result CreatePatchMetaStorage(ref SharedRef outAesCtrExMetaStorage, ref SharedRef outIndirectMetaStorage, ref SharedRef outLayerInfoStorage, - ref SharedRef baseStorage, long offset, in NcaAesCtrUpperIv upperIv, in NcaPatchInfo patchInfo, - in NcaMetaDataHashDataInfo metaDataHashDataInfo, IHash256GeneratorFactory hashGeneratorFactory) + ref readonly SharedRef baseStorage, long offset, NcaFsHeader.EncryptionType encryptionType, + in NcaAesCtrUpperIv upperIv, in NcaPatchInfo patchInfo, in NcaMetaDataHashDataInfo metaDataHashDataInfo, + IHash256GeneratorFactory hashGeneratorFactory) { throw new NotImplementedException(); } private Result CreateAesCtrExStorageMetaStorage(ref SharedRef outStorage, - ref SharedRef baseStorage, long offset, NcaFsHeader.EncryptionType encryptionType, + ref readonly SharedRef baseStorage, long offset, NcaFsHeader.EncryptionType encryptionType, in NcaAesCtrUpperIv upperIv, in NcaPatchInfo patchInfo) { throw new NotImplementedException(); } private Result CreateAesCtrExStorage(ref SharedRef outStorage, - ref SharedRef outAesCtrExStorage, ref SharedRef baseStorage, - ref SharedRef aesCtrExMetaStorage, long counterOffset, in NcaAesCtrUpperIv upperIv, + ref SharedRef outAesCtrExStorage, ref readonly SharedRef baseStorage, + ref readonly SharedRef aesCtrExMetaStorage, long counterOffset, in NcaAesCtrUpperIv upperIv, in NcaPatchInfo patchInfo) { throw new NotImplementedException(); } private Result CreateIndirectStorageMetaStorage(ref SharedRef outStorage, - ref SharedRef baseStorage, in NcaPatchInfo patchInfo) + ref readonly SharedRef baseStorage, in NcaPatchInfo patchInfo) { throw new NotImplementedException(); } private Result CreateIndirectStorage(ref SharedRef outStorage, - ref SharedRef outIndirectStorage, ref SharedRef baseStorage, - ref SharedRef originalDataStorage, ref SharedRef indirectStorageMetaStorage, - in NcaPatchInfo patchInfo) + ref SharedRef outIndirectStorage, ref readonly SharedRef baseStorage, + ref readonly SharedRef originalDataStorage, + ref readonly SharedRef indirectStorageMetaStorage, in NcaPatchInfo patchInfo) { throw new NotImplementedException(); } - private Result CreateSha256Storage(ref SharedRef outStorage, ref SharedRef baseStorage, + private Result CreateSha256Storage(ref SharedRef outStorage, ref readonly SharedRef baseStorage, in NcaFsHeader.HashData.HierarchicalSha256Data sha256Data, IHash256GeneratorFactory hashGeneratorFactory) { throw new NotImplementedException(); } private Result CreateIntegrityVerificationStorage(ref SharedRef outStorage, - ref SharedRef baseStorage, in NcaFsHeader.HashData.IntegrityMetaInfo metaInfo, - IHash256GeneratorFactory hashGeneratorFactory) - { - throw new NotImplementedException(); - } - - private Result CreateIntegrityVerificationStorageImpl(ref SharedRef outStorage, - ref SharedRef baseStorage, in NcaFsHeader.HashData.IntegrityMetaInfo metaInfo, long layerInfoOffset, - int maxDataCacheEntries, int maxHashCacheEntries, sbyte bufferLevel, + ref readonly SharedRef baseStorage, in NcaFsHeader.HashData.IntegrityMetaInfo metaInfo, IHash256GeneratorFactory hashGeneratorFactory) { throw new NotImplementedException(); } private Result CreateIntegrityVerificationStorageForMeta(ref SharedRef outStorage, - ref SharedRef outLayerInfoStorage, ref SharedRef baseStorage, long offset, + ref SharedRef outLayerInfoStorage, ref readonly SharedRef baseStorage, long offset, in NcaMetaDataHashDataInfo metaDataHashDataInfo, IHash256GeneratorFactory hashGeneratorFactory) { throw new NotImplementedException(); } + private Result CreateIntegrityVerificationStorageImpl(ref SharedRef outStorage, + ref readonly SharedRef baseStorage, in NcaFsHeader.HashData.IntegrityMetaInfo metaInfo, + long layerInfoOffset, int maxDataCacheEntries, int maxHashCacheEntries, sbyte bufferLevel, + IHash256GeneratorFactory hashGeneratorFactory) + { + throw new NotImplementedException(); + } + public static Result CreateCompressedStorage(ref SharedRef outStorage, ref SharedRef outCompressedStorage, ref SharedRef outMetaStorage, - ref SharedRef baseStorage, in NcaCompressionInfo compressionInfo, + ref readonly SharedRef baseStorage, in NcaCompressionInfo compressionInfo, GetDecompressorFunction getDecompressor, MemoryResource allocator, IBufferManager bufferManager) { throw new NotImplementedException(); } - public Result CreateCompressedStorage(ref SharedRef outStorage, + private Result CreateCompressedStorage(ref SharedRef outStorage, ref SharedRef outCompressedStorage, ref SharedRef outMetaStorage, - ref SharedRef baseStorage, in NcaCompressionInfo compressionInfo) + ref readonly SharedRef baseStorage, in NcaCompressionInfo compressionInfo) { throw new NotImplementedException(); } - public Result CreateRegionSwitchStorage(ref SharedRef outStorage, NcaFsHeaderReader headerReader, - ref SharedRef insideRegionStorage, ref SharedRef outsideRegionStorage) + private Result CreateRegionSwitchStorage(ref SharedRef outStorage, in NcaFsHeaderReader17 headerReader, + ref readonly SharedRef insideRegionStorage, ref readonly SharedRef outsideRegionStorage) { throw new NotImplementedException(); } diff --git a/src/LibHac/FsSystem/NcaReader17.cs b/src/LibHac/FsSystem/NcaReader17.cs index b04ecd1a..b9deb1e7 100644 --- a/src/LibHac/FsSystem/NcaReader17.cs +++ b/src/LibHac/FsSystem/NcaReader17.cs @@ -8,6 +8,10 @@ using LibHac.Spl; namespace LibHac.FsSystem; +public delegate Result NcaReaderInitializer(ref SharedRef outReader, in SharedRef baseStorage, + in NcaCompressionConfiguration compressionConfig, IHash256GeneratorFactorySelector hashGeneratorFactorySelector, + ContentAttributes contentAttributes); + /// /// Handles reading information from an NCA's header. ///