VeraCrypt
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2018-06-13 18:03:21 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2018-06-14 00:31:05 +0200
commit22b9ca94b3b863c734d3733f235383b8388d61ee (patch)
treeef264673c66d61b49ccb767de386baf788cd8dd7
parentd5dca62b044290475d9dd793e4abb58fbfe776d5 (diff)
downloadVeraCrypt-22b9ca94b3b863c734d3733f235383b8388d61ee.tar.gz
VeraCrypt-22b9ca94b3b863c734d3733f235383b8388d61ee.zip
Linux/MacOSX/FreeBSD: better handling for mounting systen encrypted disks whose first sector has been overwritten (e.g. during windows repair).
-rw-r--r--src/Volume/Volume.cpp32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/Volume/Volume.cpp b/src/Volume/Volume.cpp
index d4d799d1..74d102a6 100644
--- a/src/Volume/Volume.cpp
+++ b/src/Volume/Volume.cpp
@@ -316,6 +316,7 @@ namespace VeraCrypt
uint64 length = buffer.Size();
uint64 hostOffset = VolumeDataOffset + byteOffset;
+ size_t bufferOffset = 0;
if (length % SectorSize != 0 || byteOffset % SectorSize != 0)
throw ParameterIncorrect (SRC_POS);
@@ -323,31 +324,30 @@ namespace VeraCrypt
if (VolumeFile->ReadAt (buffer, hostOffset) != length)
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
- if (hostOffset < EncryptedDataSize)
- {
- size_t bufferOffset = 0;
-
- // first sector is not encrypted in case of incomplete encryption
- if (hostOffset == 0)
- {
- bufferOffset = (size_t) SectorSize;
- hostOffset += SectorSize;
- length -= SectorSize;
- }
+ bufferOffset = (size_t) SectorSize;
+ hostOffset += SectorSize;
+ length -= SectorSize;
+ }
- if (length && (hostOffset < EncryptedDataSize))
+ if (length)
+ {
+ if (EncryptionNotCompleted)
+ {
+ // if encryption is not complete, we decrypt only the encrypted sectors
+ if (hostOffset < EncryptedDataSize)
{
uint64 encryptedLength = VC_MIN (length, (EncryptedDataSize - hostOffset));
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;
}