mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Fix some issues found by static code analysis
This commit is contained in:
parent
2e769ea70a
commit
eccd91bc15
14 changed files with 27 additions and 23 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -291,6 +291,8 @@ public class CompressedStorage : IStorage, IAsynchronousAccessSplitter
|
|||
FinalizeObject();
|
||||
_cacheManager.Dispose();
|
||||
_core.Dispose();
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public Result Initialize(MemoryResource allocatorForBucketTree, IBufferManager allocatorForCacheManager,
|
||||
|
|
|
@ -92,7 +92,7 @@ public struct NcaHeader
|
|||
public Array4<Hash> FsHeaderHashes;
|
||||
public Array256<byte> 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);
|
||||
|
|
|
@ -204,7 +204,7 @@ public class NcaReader : IDisposable
|
|||
|
||||
Assert.SdkRequiresInRange(index, 0, NcaHeader.FsCountMax);
|
||||
|
||||
long offset = Unsafe.SizeOf<NcaHeader>() + Unsafe.SizeOf<NcaFsHeader>() * index;
|
||||
long offset = Unsafe.SizeOf<NcaHeader>() + Unsafe.SizeOf<NcaFsHeader>() * (long)index;
|
||||
return _headerStorage.Get.Read(offset, SpanHelpers.AsByteSpan(ref outHeader));
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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<byte> 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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -76,6 +76,8 @@ public class SectorStorage : IStorage
|
|||
{
|
||||
BaseStorage?.Dispose();
|
||||
}
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -83,5 +83,7 @@ public class StreamStorage : IStorage
|
|||
{
|
||||
BaseStream?.Dispose();
|
||||
}
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
|
||||
|
|
Loading…
Reference in a new issue