Fix bktr crypto regression

This commit is contained in:
Alex Barney 2018-08-25 16:46:08 -05:00
parent d7929fc458
commit f5d0e547e2
2 changed files with 26 additions and 8 deletions

View file

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using libhac.XTSSharp;
@ -69,14 +70,26 @@ namespace libhac
public override int Read(byte[] buffer, int offset, int count)
{
var ret = base.Read(buffer, offset, count);
if (Position >= CurrentEntry.OffsetEnd)
int totalBytesRead = 0;
var outPos = offset;
while (count > 0)
{
CurrentEntry = CurrentEntry.Next;
UpdateCounterSubsection(CurrentEntry.Counter);
int bytesToRead = (int)Math.Min(CurrentEntry.OffsetEnd - Position, count);
int bytesRead = base.Read(buffer, outPos, bytesToRead);
outPos += bytesRead;
totalBytesRead += bytesRead;
count -= bytesRead;
if (Position >= CurrentEntry.OffsetEnd)
{
CurrentEntry = CurrentEntry.Next;
UpdateCounterSubsection(CurrentEntry.Counter);
}
}
return ret;
return totalBytesRead;
}
private SubsectionEntry GetSubsectionEntry(long offset)
@ -93,5 +106,10 @@ namespace libhac
Counter[5] = (byte)(value >> 16);
Counter[4] = (byte)(value >> 24);
}
// todo: Make SectorStream play nicer with reading multiple
// blocks at a time to remove the need for this hack
protected override void ValidateSize(int value) { }
protected override void ValidateSize(long value) { }
}
}

View file

@ -154,7 +154,7 @@ namespace libhac.XTSSharp
/// <summary>
/// Validates that the size is equal to the sector size
/// </summary>
protected void ValidateSize(long value)
protected virtual void ValidateSize(long value)
{
if (value != SectorSize)
throw new ArgumentException(string.Format("Value needs to be {0}", SectorSize));
@ -163,7 +163,7 @@ namespace libhac.XTSSharp
/// <summary>
/// Validates that the size is equal to the sector size
/// </summary>
protected void ValidateSize(int value)
protected virtual void ValidateSize(int value)
{
if (value != SectorSize)
throw new ArgumentException(string.Format("Value needs to be {0}", SectorSize));