Skip to content

Commit

Permalink
quickfix: Reading decrypted xvd without DataIntegrity
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxuser committed Aug 22, 2023
1 parent 395db97 commit 13cb908
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
25 changes: 17 additions & 8 deletions LibXboxOne/XVD/XVDFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,25 +212,34 @@ public bool VirtualToLogicalDriveOffset(ulong virtualOffset, out ulong logicalOf
pageNumber = XvdMath.OffsetToPageNumber(dataStartOffset);
}

var dataBackingBlockNum = XvdMath.ComputeDataBackingPageNumber(Header.Type,
if (IsDataIntegrityEnabled)
{
var dataBackingBlockNum = XvdMath.ComputeDataBackingPageNumber(Header.Type,
HashTreeLevels,
HashTreePageCount,
pageNumber);
logicalOffset = XvdMath.PageNumberToOffset(dataBackingBlockNum);
logicalOffset = XvdMath.PageNumberToOffset(dataBackingBlockNum);
}
else
{
logicalOffset = XvdMath.PageNumberToOffset(pageNumber);
}

logicalOffset += XvdMath.InPageOffset(dataStartOffset);
logicalOffset += XvdMath.PageNumberToOffset(Header.EmbeddedXvdPageCount);
logicalOffset += Header.MutableDataLength;
logicalOffset += XVD_HEADER_INCL_SIGNATURE_SIZE;
logicalOffset += PAGE_SIZE;
// logicalOffset += PAGE_SIZE;
}
else
{ // Xvd type fixed
logicalOffset = virtualOffset;
logicalOffset += XvdMath.PageNumberToOffset(Header.EmbeddedXvdPageCount);
logicalOffset += Header.MutableDataLength;
logicalOffset += XvdMath.PageNumberToOffset(Header.NumberOfMetadataPages);
logicalOffset += XVD_HEADER_INCL_SIGNATURE_SIZE;
logicalOffset += PAGE_SIZE;
logicalOffset += DriveDataOffset;
// logicalOffset += XvdMath.PageNumberToOffset(Header.EmbeddedXvdPageCount);
// logicalOffset += Header.MutableDataLength;
// logicalOffset += XvdMath.PageNumberToOffset(Header.NumberOfMetadataPages);
// logicalOffset += XVD_HEADER_INCL_SIGNATURE_SIZE;
// logicalOffset += PAGE_SIZE;
}

return true;
Expand Down
8 changes: 7 additions & 1 deletion LibXboxOne/XVD/XvdFilesystemStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,26 @@ byte[] ReadDynamic(int count)

public override int Read(byte[] buffer, int offset, int count)
{
byte[] dataRead;
// byte[] dataRead;

if (Position + count > Length)
throw new IOException("Desired range out-of-bounds for stream");
else if (offset + count > buffer.Length)
throw new IOException("Target buffer to small to hold read data");

/*
else if (_xvdFile.Header.Type == XvdType.Fixed)
dataRead = InternalRead(count);
else if (_xvdFile.Header.Type == XvdType.Dynamic)
dataRead = ReadDynamic(count);
else
throw new IOException($"Unsupported XvdType: {_xvdFile.Header.Type}");
*/
_xvdFile.VirtualToLogicalDriveOffset((ulong)(Position + offset), out ulong logicalOffset);
Position = (long)logicalOffset;
// Console.WriteLine("0x{0:X}", Position);
var dataRead = InternalReadAbsolute((long)logicalOffset, count);

Array.Copy(dataRead, 0, buffer, offset, count);
return dataRead.Length;
Expand Down

0 comments on commit 13cb908

Please sign in to comment.