mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 11:08:02 -06:00
Linux/MacOSX/FreeBSD: better handling for mounting systen encrypted disks whose first sector has been overwritten (e.g. during windows repair).
This commit is contained in:
@@ -316,6 +316,7 @@ namespace VeraCrypt
|
|||||||
|
|
||||||
uint64 length = buffer.Size();
|
uint64 length = buffer.Size();
|
||||||
uint64 hostOffset = VolumeDataOffset + byteOffset;
|
uint64 hostOffset = VolumeDataOffset + byteOffset;
|
||||||
|
size_t bufferOffset = 0;
|
||||||
|
|
||||||
if (length % SectorSize != 0 || byteOffset % SectorSize != 0)
|
if (length % SectorSize != 0 || byteOffset % SectorSize != 0)
|
||||||
throw ParameterIncorrect (SRC_POS);
|
throw ParameterIncorrect (SRC_POS);
|
||||||
@@ -323,31 +324,30 @@ namespace VeraCrypt
|
|||||||
if (VolumeFile->ReadAt (buffer, hostOffset) != length)
|
if (VolumeFile->ReadAt (buffer, hostOffset) != length)
|
||||||
throw MissingVolumeData (SRC_POS);
|
throw MissingVolumeData (SRC_POS);
|
||||||
|
|
||||||
if (EncryptionNotCompleted)
|
// first sector can be unencrypted in some cases (e.g. windows repair)
|
||||||
|
// detect this case by looking for NTFS header
|
||||||
|
if (SystemEncryption && (hostOffset == 0) && ((BE64 (*(uint64 *) buffer.Get ())) == 0xEB52904E54465320ULL))
|
||||||
{
|
{
|
||||||
// if encryption is not complete, we decrypt only the encrypted sectors
|
bufferOffset = (size_t) SectorSize;
|
||||||
if (hostOffset < EncryptedDataSize)
|
hostOffset += SectorSize;
|
||||||
|
length -= SectorSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (length)
|
||||||
|
{
|
||||||
|
if (EncryptionNotCompleted)
|
||||||
{
|
{
|
||||||
size_t bufferOffset = 0;
|
// if encryption is not complete, we decrypt only the encrypted sectors
|
||||||
|
if (hostOffset < EncryptedDataSize)
|
||||||
// first sector is not encrypted in case of incomplete encryption
|
|
||||||
if (hostOffset == 0)
|
|
||||||
{
|
|
||||||
bufferOffset = (size_t) SectorSize;
|
|
||||||
hostOffset += SectorSize;
|
|
||||||
length -= SectorSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (length && (hostOffset < EncryptedDataSize))
|
|
||||||
{
|
{
|
||||||
uint64 encryptedLength = VC_MIN (length, (EncryptedDataSize - hostOffset));
|
uint64 encryptedLength = VC_MIN (length, (EncryptedDataSize - hostOffset));
|
||||||
|
|
||||||
EA->DecryptSectors (buffer.GetRange (bufferOffset, encryptedLength), hostOffset / SectorSize, encryptedLength / SectorSize, SectorSize);
|
EA->DecryptSectors (buffer.GetRange (bufferOffset, encryptedLength), hostOffset / SectorSize, encryptedLength / SectorSize, SectorSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
EA->DecryptSectors (buffer.GetRange (bufferOffset, length), hostOffset / SectorSize, length / SectorSize, SectorSize);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
EA->DecryptSectors (buffer, hostOffset / SectorSize, length / SectorSize, SectorSize);
|
|
||||||
|
|
||||||
TotalDataRead += length;
|
TotalDataRead += length;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user