diff options
Diffstat (limited to 'src/Common/BootEncryption.cpp')
-rw-r--r-- | src/Common/BootEncryption.cpp | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/Common/BootEncryption.cpp b/src/Common/BootEncryption.cpp index 1a467eed..0fec2878 100644 --- a/src/Common/BootEncryption.cpp +++ b/src/Common/BootEncryption.cpp | |||
@@ -32,6 +32,8 @@ | |||
32 | #include "Mount/MainCom.h" | 32 | #include "Mount/MainCom.h" |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #include <Strsafe.h> | ||
36 | |||
35 | namespace VeraCrypt | 37 | namespace VeraCrypt |
36 | { | 38 | { |
37 | #if !defined (SETUP) | 39 | #if !defined (SETUP) |
@@ -604,7 +606,7 @@ namespace VeraCrypt | |||
604 | GetSystemDriveConfiguration(); | 606 | GetSystemDriveConfiguration(); |
605 | 607 | ||
606 | ProbeRealDriveSizeRequest request; | 608 | ProbeRealDriveSizeRequest request; |
607 | _snwprintf (request.DeviceName, array_capacity (request.DeviceName), L"%hs", DriveConfig.DrivePartition.DevicePath.c_str()); | 609 | StringCbPrintfW (request.DeviceName, sizeof (request.DeviceName), L"%hs", DriveConfig.DrivePartition.DevicePath.c_str()); |
608 | 610 | ||
609 | CallDriver (TC_IOCTL_PROBE_REAL_DRIVE_SIZE, &request, sizeof (request), &request, sizeof (request)); | 611 | CallDriver (TC_IOCTL_PROBE_REAL_DRIVE_SIZE, &request, sizeof (request), &request, sizeof (request)); |
610 | DriveConfig.DrivePartition.Info.PartitionLength = request.RealDriveSize; | 612 | DriveConfig.DrivePartition.Info.PartitionLength = request.RealDriveSize; |
@@ -633,7 +635,7 @@ namespace VeraCrypt | |||
633 | partPath << "\\Device\\Harddisk" << driveNumber << "\\Partition" << partNumber; | 635 | partPath << "\\Device\\Harddisk" << driveNumber << "\\Partition" << partNumber; |
634 | 636 | ||
635 | DISK_PARTITION_INFO_STRUCT diskPartInfo; | 637 | DISK_PARTITION_INFO_STRUCT diskPartInfo; |
636 | _snwprintf (diskPartInfo.deviceName, array_capacity (diskPartInfo.deviceName), L"%hs", partPath.str().c_str()); | 638 | StringCbPrintfW (diskPartInfo.deviceName, sizeof (diskPartInfo.deviceName), L"%hs", partPath.str().c_str()); |
637 | 639 | ||
638 | try | 640 | try |
639 | { | 641 | { |
@@ -663,7 +665,7 @@ namespace VeraCrypt | |||
663 | 665 | ||
664 | // Volume ID | 666 | // Volume ID |
665 | wchar_t volumePath[TC_MAX_PATH]; | 667 | wchar_t volumePath[TC_MAX_PATH]; |
666 | if (ResolveSymbolicLink ((wchar_t *) ws.str().c_str(), volumePath)) | 668 | if (ResolveSymbolicLink ((wchar_t *) ws.str().c_str(), volumePath, sizeof(volumePath))) |
667 | { | 669 | { |
668 | wchar_t volumeName[TC_MAX_PATH]; | 670 | wchar_t volumeName[TC_MAX_PATH]; |
669 | HANDLE fh = FindFirstVolumeW (volumeName, array_capacity (volumeName)); | 671 | HANDLE fh = FindFirstVolumeW (volumeName, array_capacity (volumeName)); |
@@ -742,8 +744,8 @@ namespace VeraCrypt | |||
742 | memset (&openTestStruct, 0, sizeof (openTestStruct)); | 744 | memset (&openTestStruct, 0, sizeof (openTestStruct)); |
743 | DWORD dwResult; | 745 | DWORD dwResult; |
744 | 746 | ||
745 | strcpy ((char *) &openTestStruct.wszFileName[0], devicePath); | 747 | StringCbCopyA ((char *) &openTestStruct.wszFileName[0], sizeof(openTestStruct.wszFileName),devicePath); |
746 | ToUNICODE ((char *) &openTestStruct.wszFileName[0]); | 748 | ToUNICODE ((char *) &openTestStruct.wszFileName[0], sizeof(openTestStruct.wszFileName)); |
747 | 749 | ||
748 | openTestStruct.bDetectTCBootLoader = TRUE; | 750 | openTestStruct.bDetectTCBootLoader = TRUE; |
749 | 751 | ||
@@ -844,7 +846,7 @@ namespace VeraCrypt | |||
844 | bool BootEncryption::SystemDriveIsDynamic () | 846 | bool BootEncryption::SystemDriveIsDynamic () |
845 | { | 847 | { |
846 | GetSystemDriveConfigurationRequest request; | 848 | GetSystemDriveConfigurationRequest request; |
847 | _snwprintf (request.DevicePath, array_capacity (request.DevicePath), L"%hs", GetSystemDriveConfiguration().DeviceKernelPath.c_str()); | 849 | StringCbPrintfW (request.DevicePath, sizeof (request.DevicePath), L"%hs", GetSystemDriveConfiguration().DeviceKernelPath.c_str()); |
848 | 850 | ||
849 | CallDriver (TC_IOCTL_GET_SYSTEM_DRIVE_CONFIG, &request, sizeof (request), &request, sizeof (request)); | 851 | CallDriver (TC_IOCTL_GET_SYSTEM_DRIVE_CONFIG, &request, sizeof (request), &request, sizeof (request)); |
850 | return request.DriveIsDynamic ? true : false; | 852 | return request.DriveIsDynamic ? true : false; |
@@ -1095,7 +1097,7 @@ namespace VeraCrypt | |||
1095 | throw ParameterIncorrect (SRC_POS); | 1097 | throw ParameterIncorrect (SRC_POS); |
1096 | 1098 | ||
1097 | GetSystemDriveConfigurationRequest request; | 1099 | GetSystemDriveConfigurationRequest request; |
1098 | _snwprintf (request.DevicePath, array_capacity (request.DevicePath), L"%hs", GetSystemDriveConfiguration().DeviceKernelPath.c_str()); | 1100 | StringCbPrintfW (request.DevicePath, sizeof (request.DevicePath), L"%hs", GetSystemDriveConfiguration().DeviceKernelPath.c_str()); |
1099 | 1101 | ||
1100 | try | 1102 | try |
1101 | { | 1103 | { |
@@ -1402,8 +1404,10 @@ namespace VeraCrypt | |||
1402 | memset (image, 0, RescueIsoImageSize); | 1404 | memset (image, 0, RescueIsoImageSize); |
1403 | 1405 | ||
1404 | // Primary volume descriptor | 1406 | // Primary volume descriptor |
1405 | strcpy ((char *)image + 0x8000, "\001CD001\001"); | 1407 | const char* szPrimVolDesc = "\001CD001\001"; |
1406 | strcpy ((char *)image + 0x7fff + 41, "VeraCrypt Rescue Disk "); | 1408 | const char* szPrimVolLabel = "VeraCrypt Rescue Disk "; |
1409 | memcpy (image + 0x8000, szPrimVolDesc, strlen(szPrimVolDesc) + 1); | ||
1410 | memcpy (image + 0x7fff + 41, szPrimVolLabel, strlen(szPrimVolLabel) + 1); | ||
1407 | *(uint32 *) (image + 0x7fff + 81) = RescueIsoImageSize / 2048; | 1411 | *(uint32 *) (image + 0x7fff + 81) = RescueIsoImageSize / 2048; |
1408 | *(uint32 *) (image + 0x7fff + 85) = BE32 (RescueIsoImageSize / 2048); | 1412 | *(uint32 *) (image + 0x7fff + 85) = BE32 (RescueIsoImageSize / 2048); |
1409 | image[0x7fff + 121] = 1; | 1413 | image[0x7fff + 121] = 1; |
@@ -1420,11 +1424,13 @@ namespace VeraCrypt | |||
1420 | image[0x7fff + 159] = 0x18; | 1424 | image[0x7fff + 159] = 0x18; |
1421 | 1425 | ||
1422 | // Boot record volume descriptor | 1426 | // Boot record volume descriptor |
1423 | strcpy ((char *)image + 0x8801, "CD001\001EL TORITO SPECIFICATION"); | 1427 | const char* szBootRecDesc = "CD001\001EL TORITO SPECIFICATION"; |
1428 | memcpy (image + 0x8801, szBootRecDesc, strlen(szBootRecDesc) + 1); | ||
1424 | image[0x8800 + 0x47] = 0x19; | 1429 | image[0x8800 + 0x47] = 0x19; |
1425 | 1430 | ||
1426 | // Volume descriptor set terminator | 1431 | // Volume descriptor set terminator |
1427 | strcpy ((char *)image + 0x9000, "\377CD001\001"); | 1432 | const char* szVolDescTerm = "\377CD001\001"; |
1433 | memcpy (image + 0x9000, szVolDescTerm, strlen(szVolDescTerm) + 1); | ||
1428 | 1434 | ||
1429 | // Path table | 1435 | // Path table |
1430 | image[0xA000 + 0] = 1; | 1436 | image[0xA000 + 0] = 1; |
@@ -1722,7 +1728,7 @@ namespace VeraCrypt | |||
1722 | DWORD size = sizeof (regKeyBuf) - strSize; | 1728 | DWORD size = sizeof (regKeyBuf) - strSize; |
1723 | 1729 | ||
1724 | // SetupInstallFromInfSection() does not support prepending of values so we have to modify the registry directly | 1730 | // SetupInstallFromInfSection() does not support prepending of values so we have to modify the registry directly |
1725 | strncpy ((char *) regKeyBuf, filter.c_str(), sizeof (regKeyBuf)); | 1731 | StringCbCopyA ((char *) regKeyBuf, sizeof(regKeyBuf), filter.c_str()); |
1726 | 1732 | ||
1727 | if (RegQueryValueEx (regKey, filterReg.c_str(), NULL, NULL, regKeyBuf + strSize, &size) != ERROR_SUCCESS) | 1733 | if (RegQueryValueEx (regKey, filterReg.c_str(), NULL, NULL, regKeyBuf + strSize, &size) != ERROR_SUCCESS) |
1728 | size = 1; | 1734 | size = 1; |
@@ -2318,7 +2324,7 @@ namespace VeraCrypt | |||
2318 | void BootEncryption::RestrictPagingFilesToSystemPartition () | 2324 | void BootEncryption::RestrictPagingFilesToSystemPartition () |
2319 | { | 2325 | { |
2320 | char pagingFiles[128]; | 2326 | char pagingFiles[128]; |
2321 | strncpy (pagingFiles, "X:\\pagefile.sys 0 0", sizeof (pagingFiles)); | 2327 | StringCbCopyA (pagingFiles, sizeof(pagingFiles), "X:\\pagefile.sys 0 0"); |
2322 | pagingFiles[0] = GetWindowsDirectory()[0]; | 2328 | pagingFiles[0] = GetWindowsDirectory()[0]; |
2323 | 2329 | ||
2324 | throw_sys_if (!WriteLocalMachineRegistryMultiString ("System\\CurrentControlSet\\Control\\Session Manager\\Memory Management", "PagingFiles", pagingFiles, strlen (pagingFiles) + 2)); | 2330 | throw_sys_if (!WriteLocalMachineRegistryMultiString ("System\\CurrentControlSet\\Control\\Session Manager\\Memory Management", "PagingFiles", pagingFiles, strlen (pagingFiles) + 2)); |