diff --git a/src/LibHac/Common/ResultNameResolver.cs b/src/LibHac/Common/ResultNameResolver.cs index 128c0c5e..59079a2b 100644 --- a/src/LibHac/Common/ResultNameResolver.cs +++ b/src/LibHac/Common/ResultNameResolver.cs @@ -25,8 +25,8 @@ internal partial class ResultNameResolver : Result.IResultNameResolver private static byte[] DecompressArchive() { - var deflateStream = new DeflateStream(new MemoryStream(ArchiveData.ToArray()), CompressionMode.Decompress); - var archiveDataStream = new MemoryStream(); + using var deflateStream = new DeflateStream(new MemoryStream(ArchiveData.ToArray()), CompressionMode.Decompress); + using var archiveDataStream = new MemoryStream(); deflateStream.CopyTo(archiveDataStream); return archiveDataStream.ToArray(); } diff --git a/src/LibHac/FsSystem/BucketTreeBuilder.cs b/src/LibHac/FsSystem/BucketTreeBuilder.cs index 99cea147..0b92254e 100644 --- a/src/LibHac/FsSystem/BucketTreeBuilder.cs +++ b/src/LibHac/FsSystem/BucketTreeBuilder.cs @@ -284,7 +284,7 @@ public partial class BucketTree l2NodeHeader.EntryCount = indexInL2Node != 0 ? indexInL2Node : _offsetsPerNode; l2NodeHeader.OffsetEnd = endOffset; - long l2NodeStorageOffset = _nodeSize * (l2NodeIndex + 1); + long l2NodeStorageOffset = (long)_nodeSize * (l2NodeIndex + 1); res = _nodeStorage.Write(l2NodeStorageOffset, _l2Node.GetBuffer()); if (res.IsFailure()) return res.Miss(); } diff --git a/src/LibHac/FsSystem/CompressedStorage.cs b/src/LibHac/FsSystem/CompressedStorage.cs index c68764ed..5fee1e67 100644 --- a/src/LibHac/FsSystem/CompressedStorage.cs +++ b/src/LibHac/FsSystem/CompressedStorage.cs @@ -291,6 +291,8 @@ public class CompressedStorage : IStorage, IAsynchronousAccessSplitter FinalizeObject(); _cacheManager.Dispose(); _core.Dispose(); + + base.Dispose(); } public Result Initialize(MemoryResource allocatorForBucketTree, IBufferManager allocatorForCacheManager, diff --git a/src/LibHac/FsSystem/NcaHeader.cs b/src/LibHac/FsSystem/NcaHeader.cs index 96b6943f..4efacc51 100644 --- a/src/LibHac/FsSystem/NcaHeader.cs +++ b/src/LibHac/FsSystem/NcaHeader.cs @@ -92,7 +92,7 @@ public struct NcaHeader public Array4 FsHeaderHashes; public Array256 EncryptedKeys; - public static ulong SectorToByte(uint sectorIndex) => sectorIndex << SectorShift; + public static ulong SectorToByte(uint sectorIndex) => (ulong)sectorIndex << SectorShift; public static uint ByteToSector(ulong byteIndex) => (uint)(byteIndex >> SectorShift); public readonly byte GetProperKeyGeneration() => Math.Max(KeyGeneration1, KeyGeneration2); diff --git a/src/LibHac/FsSystem/NcaReader.cs b/src/LibHac/FsSystem/NcaReader.cs index 02c8e8fc..e969a0fc 100644 --- a/src/LibHac/FsSystem/NcaReader.cs +++ b/src/LibHac/FsSystem/NcaReader.cs @@ -204,7 +204,7 @@ public class NcaReader : IDisposable Assert.SdkRequiresInRange(index, 0, NcaHeader.FsCountMax); - long offset = Unsafe.SizeOf() + Unsafe.SizeOf() * index; + long offset = Unsafe.SizeOf() + Unsafe.SizeOf() * (long)index; return _headerStorage.Get.Read(offset, SpanHelpers.AsByteSpan(ref outHeader)); } diff --git a/src/LibHac/Tools/FsSystem/AesXtsFileHeader.cs b/src/LibHac/Tools/FsSystem/AesXtsFileHeader.cs index 7eaa2ed2..6904d1a6 100644 --- a/src/LibHac/Tools/FsSystem/AesXtsFileHeader.cs +++ b/src/LibHac/Tools/FsSystem/AesXtsFileHeader.cs @@ -93,10 +93,7 @@ public class AesXtsFileHeader private void GenerateKek(byte[] kekSeed, string path) { - var hash = new HMACSHA256(kekSeed); - byte[] pathBytes = Encoding.UTF8.GetBytes(path); - - byte[] checksum = hash.ComputeHash(pathBytes, 0, pathBytes.Length); + byte[] checksum = HMACSHA256.HashData(kekSeed, Encoding.UTF8.GetBytes(path)); Array.Copy(checksum, 0, Kek1, 0, 0x10); Array.Copy(checksum, 0x10, Kek2, 0, 0x10); } @@ -104,9 +101,8 @@ public class AesXtsFileHeader private byte[] CalculateHmac(byte[] key) { byte[] message = ToBytes(true).AsSpan(0x20).ToArray(); - var hash = new HMACSHA256(message); - return hash.ComputeHash(key); + return HMACSHA256.HashData(message, key); } public byte[] ToBytes(bool writeDecryptedKey) diff --git a/src/LibHac/Tools/FsSystem/HierarchicalIntegrityVerificationStorage.cs b/src/LibHac/Tools/FsSystem/HierarchicalIntegrityVerificationStorage.cs index 1bdfa1b8..de60a8df 100644 --- a/src/LibHac/Tools/FsSystem/HierarchicalIntegrityVerificationStorage.cs +++ b/src/LibHac/Tools/FsSystem/HierarchicalIntegrityVerificationStorage.cs @@ -90,7 +90,7 @@ public class HierarchicalIntegrityVerificationStorage : IStorage { Data = levels[i], BlockSize = 1 << ivfc.LevelHeaders[i - 1].BlockSizePower, - Salt = new HMACSHA256(Encoding.ASCII.GetBytes(SaltSources[i - 1])).ComputeHash(ivfc.SaltSource), + Salt = HMACSHA256.HashData(Encoding.ASCII.GetBytes(SaltSources[i - 1]), ivfc.SaltSource), Type = type }; } diff --git a/src/LibHac/Tools/FsSystem/NcaUtils/NcaExtensions.cs b/src/LibHac/Tools/FsSystem/NcaUtils/NcaExtensions.cs index ed7ae471..b85e66ee 100644 --- a/src/LibHac/Tools/FsSystem/NcaUtils/NcaExtensions.cs +++ b/src/LibHac/Tools/FsSystem/NcaUtils/NcaExtensions.cs @@ -82,7 +82,7 @@ public static class NcaExtensions expectedHash = ivfcInfo.MasterHash.ToArray(); offset = ivfcInfo.GetLevelOffset(0); - size = 1 << ivfcInfo.GetLevelBlockSize(0); + size = 1L << ivfcInfo.GetLevelBlockSize(0); break; case NcaHashType.Sha256: diff --git a/src/LibHac/Tools/FsSystem/Save/AllocationTableStorage.cs b/src/LibHac/Tools/FsSystem/Save/AllocationTableStorage.cs index 992f785d..17ece1ac 100644 --- a/src/LibHac/Tools/FsSystem/Save/AllocationTableStorage.cs +++ b/src/LibHac/Tools/FsSystem/Save/AllocationTableStorage.cs @@ -21,7 +21,7 @@ public class AllocationTableStorage : IStorage Fat = table; InitialBlock = initialBlock; - _length = initialBlock == -1 ? 0 : table.GetListLength(initialBlock) * blockSize; + _length = initialBlock == -1 ? 0 : (long)table.GetListLength(initialBlock) * blockSize; } public override Result Read(long offset, Span destination) @@ -42,7 +42,7 @@ public class AllocationTableStorage : IStorage } int segmentPos = (int)(inPos - (long)iterator.VirtualBlock * BlockSize); - long physicalOffset = iterator.PhysicalBlock * BlockSize + segmentPos; + long physicalOffset = (long)iterator.PhysicalBlock * BlockSize + segmentPos; int remainingInSegment = iterator.CurrentSegmentSize * BlockSize - segmentPos; int bytesToRead = Math.Min(remaining, remainingInSegment); @@ -76,7 +76,7 @@ public class AllocationTableStorage : IStorage } int segmentPos = (int)(inPos - (long)iterator.VirtualBlock * BlockSize); - long physicalOffset = iterator.PhysicalBlock * BlockSize + segmentPos; + long physicalOffset = (long)iterator.PhysicalBlock * BlockSize + segmentPos; int remainingInSegment = iterator.CurrentSegmentSize * BlockSize - segmentPos; int bytesToWrite = Math.Min(remaining, remainingInSegment); @@ -115,7 +115,7 @@ public class AllocationTableStorage : IStorage InitialBlock = Fat.Allocate(newBlockCount); if (InitialBlock == -1) throw new IOException("Not enough space to resize file."); - _length = newBlockCount * BlockSize; + _length = (long)newBlockCount * BlockSize; return Result.Success; } @@ -143,7 +143,7 @@ public class AllocationTableStorage : IStorage Fat.Free(oldBlocks); } - _length = newBlockCount * BlockSize; + _length = (long)newBlockCount * BlockSize; return Result.Success; } diff --git a/src/LibHac/Tools/FsSystem/Save/JournalStorage.cs b/src/LibHac/Tools/FsSystem/Save/JournalStorage.cs index e585eb49..c299068b 100644 --- a/src/LibHac/Tools/FsSystem/Save/JournalStorage.cs +++ b/src/LibHac/Tools/FsSystem/Save/JournalStorage.cs @@ -48,7 +48,7 @@ public class JournalStorage : IStorage int blockNum = (int)(inPos / BlockSize); int blockPos = (int)(inPos % BlockSize); - long physicalOffset = Map.GetPhysicalBlock(blockNum) * BlockSize + blockPos; + long physicalOffset = (long)Map.GetPhysicalBlock(blockNum) * BlockSize + blockPos; int bytesToRead = Math.Min(remaining, BlockSize - blockPos); @@ -77,7 +77,7 @@ public class JournalStorage : IStorage int blockNum = (int)(inPos / BlockSize); int blockPos = (int)(inPos % BlockSize); - long physicalOffset = Map.GetPhysicalBlock(blockNum) * BlockSize + blockPos; + long physicalOffset = (long)Map.GetPhysicalBlock(blockNum) * BlockSize + blockPos; int bytesToWrite = Math.Min(remaining, BlockSize - blockPos); diff --git a/src/LibHac/Tools/FsSystem/Save/RemapStorage.cs b/src/LibHac/Tools/FsSystem/Save/RemapStorage.cs index 2f4e23db..0fb470f7 100644 --- a/src/LibHac/Tools/FsSystem/Save/RemapStorage.cs +++ b/src/LibHac/Tools/FsSystem/Save/RemapStorage.cs @@ -140,6 +140,8 @@ public class RemapStorage : IStorage { BaseStorage?.Dispose(); } + + base.Dispose(); } public IStorage GetBaseStorage() => BaseStorage; @@ -211,7 +213,7 @@ public class RemapStorage : IStorage private long GetOffsetMask() { - return (1 << (64 - Header.SegmentBits)) - 1; + return (1L << (64 - Header.SegmentBits)) - 1; } private long GetSegmentMask() diff --git a/src/LibHac/Tools/FsSystem/SectorStorage.cs b/src/LibHac/Tools/FsSystem/SectorStorage.cs index 1d95e147..bec4bce9 100644 --- a/src/LibHac/Tools/FsSystem/SectorStorage.cs +++ b/src/LibHac/Tools/FsSystem/SectorStorage.cs @@ -76,6 +76,8 @@ public class SectorStorage : IStorage { BaseStorage?.Dispose(); } + + base.Dispose(); } /// diff --git a/src/LibHac/Tools/FsSystem/StreamStorage.cs b/src/LibHac/Tools/FsSystem/StreamStorage.cs index b869bae3..ae71b992 100644 --- a/src/LibHac/Tools/FsSystem/StreamStorage.cs +++ b/src/LibHac/Tools/FsSystem/StreamStorage.cs @@ -83,5 +83,7 @@ public class StreamStorage : IStorage { BaseStream?.Dispose(); } + + base.Dispose(); } } \ No newline at end of file diff --git a/src/LibHac/Tools/Npdm/KernelAccessControl.cs b/src/LibHac/Tools/Npdm/KernelAccessControl.cs index da9b5585..ab787708 100644 --- a/src/LibHac/Tools/Npdm/KernelAccessControl.cs +++ b/src/LibHac/Tools/Npdm/KernelAccessControl.cs @@ -94,7 +94,7 @@ public class KernelAccessControl descriptor >>= 7; - ulong mmioSize = (descriptor & 0xffffff) << 12; + ulong mmioSize = (descriptor & 0xffffffUL) << 12; bool isNormal = (descriptor >> 24) != 0; items[index].NormalMmio.Add(new KernelAccessControlMmio(address, mmioSize, isRo, isNormal)); @@ -107,7 +107,7 @@ public class KernelAccessControl //Map Normal Page. case 7: { - ulong address = descriptor << 12; + ulong address = (ulong)descriptor << 12; items[index].PageMmio.Add(new KernelAccessControlMmio(address, 0x1000, false, false));