mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Limit the hash target size to the file size when building a hashed PFS
This commit is contained in:
parent
71fafcac85
commit
4e0db17192
1 changed files with 7 additions and 3 deletions
|
@ -23,6 +23,7 @@ public enum PartitionFileSystemType
|
|||
public class PartitionFileSystemBuilder
|
||||
{
|
||||
private const int HeaderSize = 0x10;
|
||||
private const int DefaultHashTargetSize = 0x200;
|
||||
|
||||
private List<Entry> Entries { get; } = new List<Entry>();
|
||||
private long CurrentOffset { get; set; }
|
||||
|
@ -58,7 +59,7 @@ public class PartitionFileSystemBuilder
|
|||
Offset = CurrentOffset,
|
||||
NameLength = Encoding.UTF8.GetByteCount(filename),
|
||||
HashOffset = 0,
|
||||
HashLength = 0x200
|
||||
HashLength = (int)Math.Min(DefaultHashTargetSize, fileSize)
|
||||
};
|
||||
|
||||
CurrentOffset += entry.Length;
|
||||
|
@ -163,7 +164,10 @@ public class PartitionFileSystemBuilder
|
|||
|
||||
foreach (Entry entry in Entries)
|
||||
{
|
||||
if (entry.HashLength == 0) entry.HashLength = 0x200;
|
||||
if (entry.HashLength == 0)
|
||||
{
|
||||
entry.HashLength = (int)Math.Min(DefaultHashTargetSize, entry.Length);
|
||||
}
|
||||
|
||||
byte[] data = new byte[entry.HashLength];
|
||||
entry.File.Read(out long bytesRead, entry.HashOffset, data);
|
||||
|
@ -180,7 +184,7 @@ public class PartitionFileSystemBuilder
|
|||
sha.GetHash(entry.Hash);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static int GetEntrySize(PartitionFileSystemType type)
|
||||
{
|
||||
switch (type)
|
||||
|
|
Loading…
Reference in a new issue