From cf5729d4e184831d8d1a9bb3a83db9b645f96c24 Mon Sep 17 00:00:00 2001 From: kavsrf Date: Sun, 26 Feb 2017 10:48:24 +0300 Subject: Beta2 patch 1 Edit DcsProp and PlatformInfo from System->Settings EFI loader updated --- src/Common/BootEncryption.cpp | 64 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 8 deletions(-) (limited to 'src/Common/BootEncryption.cpp') diff --git a/src/Common/BootEncryption.cpp b/src/Common/BootEncryption.cpp index 6dc2c979..a8481f3b 100644 --- a/src/Common/BootEncryption.cpp +++ b/src/Common/BootEncryption.cpp @@ -1565,7 +1565,7 @@ namespace VeraCrypt { if (GetSystemDriveConfiguration().SystemPartition.IsGPT) { - byte confContent[4096]; + byte confContent[4096*8]; DWORD dwSize; // for now, we don't support any boot config flags, like hidden OS one @@ -2032,13 +2032,17 @@ namespace VeraCrypt BOOL EfiBootConf::Save (const wchar_t* fileName, HWND hwnd) { - FILE *configFile = _wfopen (fileName, L"w,ccs=UTF-8"); - if (configFile == NULL) - return FALSE; BOOL bRet = FALSE; DWORD size = 0; char* configContent = LoadFile (fileName, &size); + + FILE *configFile = _wfopen (fileName, L"w,ccs=UTF-8"); + if (configFile == NULL) { + burn (configContent, size); + free (configContent); + return FALSE; + } XmlWriteHeader (configFile); @@ -2088,15 +2092,43 @@ namespace VeraCrypt static const wchar_t* EfiVarGuid = L"{8BE4DF61-93CA-11D2-AA0D-00E098032B8C}"; + void + GetVolumeESP(wstring& path) + { + ULONG len; + NTSTATUS res; + WCHAR tempBuf[1024]; + memset(tempBuf, 0, sizeof(tempBuf)); + + // Load NtQuerySystemInformation function point + if (!NtQuerySystemInformationPtr) + { + NtQuerySystemInformationPtr = (NtQuerySystemInformationFn) GetProcAddress (GetModuleHandle (L"ntdll.dll"), "NtQuerySystemInformation"); + if (!NtQuerySystemInformationPtr) + throw SystemException (SRC_POS); + } + + res = NtQuerySystemInformationPtr((SYSTEM_INFORMATION_CLASS)SYSPARTITIONINFORMATION, tempBuf, sizeof(tempBuf), &len); + if (res != S_OK) + { + SetLastError (res); + throw SystemException (SRC_POS); + } + + PUNICODE_STRING pStr = (PUNICODE_STRING) tempBuf; + path = L"\\\\?"; + path += &pStr->Buffer[7]; + } + EfiBoot::EfiBoot() { ZeroMemory(EfiBootPartPath, sizeof(EfiBootPartPath)); - ZeroMemory (systemPartitionPath, sizeof (systemPartitionPath)); + ZeroMemory (BootVolumePath, sizeof (BootVolumePath)); ZeroMemory (&sdn, sizeof (sdn)); ZeroMemory (&partInfo, sizeof (partInfo)); m_bMounted = false; } - void EfiBoot::MountBootPartition(WCHAR letter) { + void EfiBoot::SelectBootVolumeESP() { NTSTATUS res; ULONG len; memset(tempBuf, 0, sizeof(tempBuf)); @@ -2117,7 +2149,23 @@ namespace VeraCrypt } PUNICODE_STRING pStr = (PUNICODE_STRING) tempBuf; - memcpy (systemPartitionPath, pStr->Buffer, min (pStr->Length, (sizeof (systemPartitionPath) - 2))); + memcpy (BootVolumePath, pStr->Buffer, min (pStr->Length, (sizeof (BootVolumePath) - 2))); + bBootVolumePathSelected = TRUE; + } + + void EfiBoot::SelectBootVolume(WCHAR* bootVolumePath) { + wstring str; + str = bootVolumePath; + memcpy (BootVolumePath, &str[0], min (str.length() * 2, (sizeof (BootVolumePath) - 2))); + bBootVolumePathSelected = TRUE; + } + + void EfiBoot::MountBootPartition(WCHAR letter) { + NTSTATUS res; + ULONG len; + if (!bBootVolumePathSelected) { + SelectBootVolumeESP(); + } if (!letter) { if (!GetFreeDriveLetter(&EfiBootPartPath[0])) { @@ -2128,7 +2176,7 @@ namespace VeraCrypt } EfiBootPartPath[1] = ':'; EfiBootPartPath[2] = 0; - throw_sys_if(!DefineDosDevice(DDD_RAW_TARGET_PATH, EfiBootPartPath, systemPartitionPath)); + throw_sys_if(!DefineDosDevice(DDD_RAW_TARGET_PATH, EfiBootPartPath, BootVolumePath)); Device dev(EfiBootPartPath, TRUE); -- cgit v1.2.3