diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2016-08-09 23:26:15 +0200 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2016-08-15 01:09:13 +0200 |
commit | 07ee8c10691d05e4e290ecdaa634ad5311b3cbb1 (patch) | |
tree | 436fc236acefb75237622da0e4cf7f3f05f7f48b /src/Common/BaseCom.cpp | |
parent | 246233c40262c5be2edfa916cf841dd4bce6598e (diff) | |
download | VeraCrypt-07ee8c10691d05e4e290ecdaa634ad5311b3cbb1.tar.gz VeraCrypt-07ee8c10691d05e4e290ecdaa634ad5311b3cbb1.zip |
Windows: Implement support for EFI system encryption in Windows GUI.
Diffstat (limited to 'src/Common/BaseCom.cpp')
-rw-r--r-- | src/Common/BaseCom.cpp | 217 |
1 files changed, 216 insertions, 1 deletions
diff --git a/src/Common/BaseCom.cpp b/src/Common/BaseCom.cpp index 5905b6a8..26e2650a 100644 --- a/src/Common/BaseCom.cpp +++ b/src/Common/BaseCom.cpp @@ -3,7 +3,7 @@ Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed by the TrueCrypt License 3.0. - Modifications and additions to the original source code (contained in this file) + Modifications and additions to the original source code (contained in this file) and all other portions of this file are Copyright (c) 2013-2016 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source @@ -161,6 +161,63 @@ DWORD BaseCom::ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *buff return ERROR_SUCCESS; } +DWORD BaseCom::GetFileSize (BSTR filePath, unsigned __int64 *pSize) +{ + if (!pSize) + return ERROR_INVALID_PARAMETER; + + try + { + std::wstring path (filePath); + File file(filePath, true); + file.CheckOpened (SRC_POS); + file.GetFileSize (*pSize); + } + catch (SystemException &) + { + return GetLastError(); + } + catch (Exception &e) + { + e.Show (NULL); + return ERROR_EXCEPTION_IN_SERVICE; + } + catch (...) + { + return ERROR_EXCEPTION_IN_SERVICE; + } + + return ERROR_SUCCESS; +} + +DWORD BaseCom::DeviceIoControl (BOOL readOnly, BOOL device, BSTR filePath, DWORD dwIoControlCode, BSTR input, BSTR *output) +{ + try + { + auto_ptr <File> file (device ? new Device (filePath, readOnly == TRUE) : new File (filePath, readOnly == TRUE)); + file->CheckOpened (SRC_POS); + if (!file->IoCtl (dwIoControlCode, (BYTE *) input, !(BYTE *) input ? 0 : ((DWORD *) ((BYTE *) input))[-1], + (BYTE *) *output, !(BYTE *) *output ? 0 : ((DWORD *) ((BYTE *) *output))[-1])) + { + return GetLastError(); + } + } + catch (SystemException &) + { + return GetLastError(); + } + catch (Exception &e) + { + e.Show (NULL); + return ERROR_EXCEPTION_IN_SERVICE; + } + catch (...) + { + return ERROR_EXCEPTION_IN_SERVICE; + } + + return ERROR_SUCCESS; +} DWORD BaseCom::RegisterFilterDriver (BOOL registerDriver, int filterType) { @@ -244,3 +301,161 @@ DWORD BaseCom::WriteLocalMachineRegistryDwordValue (BSTR keyPath, BSTR valueName return ERROR_SUCCESS; } +DWORD BaseCom::InstallEfiBootLoader (BOOL preserveUserConfig, BOOL hiddenOSCreation, int pim, int hashAlg) +{ + try + { + BootEncryption bootEnc (NULL); + bootEnc.InstallBootLoader (preserveUserConfig? true : false, hiddenOSCreation? true : false, pim, hashAlg); + } + catch (SystemException &) + { + return GetLastError(); + } + catch (Exception &e) + { + e.Show (NULL); + return ERROR_EXCEPTION_IN_SERVICE; + } + catch (...) + { + return ERROR_EXCEPTION_IN_SERVICE; + } + + return ERROR_SUCCESS; +} + +DWORD BaseCom::BackupEfiSystemLoader () +{ + try + { + BootEncryption bootEnc (NULL); + bootEnc.BackupSystemLoader (); + } + catch (SystemException &) + { + return GetLastError(); + } + catch (Exception &e) + { + e.Show (NULL); + return ERROR_EXCEPTION_IN_SERVICE; + } + catch (...) + { + return ERROR_EXCEPTION_IN_SERVICE; + } + + return ERROR_SUCCESS; +} + +DWORD BaseCom::RestoreEfiSystemLoader () +{ + try + { + BootEncryption bootEnc (NULL); + bootEnc.RestoreSystemLoader (); + } + catch (SystemException &) + { + return GetLastError(); + } + catch (Exception &e) + { + e.Show (NULL); + return ERROR_EXCEPTION_IN_SERVICE; + } + catch (...) + { + return ERROR_EXCEPTION_IN_SERVICE; + } + + return ERROR_SUCCESS; +} + +DWORD BaseCom::GetEfiBootDeviceNumber (BSTR* pSdn) +{ + if (!pSdn || !(*pSdn) || ((((DWORD *) ((BYTE *) *pSdn))[-1]) < sizeof (STORAGE_DEVICE_NUMBER))) + return ERROR_INVALID_PARAMETER; + + try + { + BootEncryption bootEnc (NULL); + bootEnc.GetEfiBootDeviceNumber ((PSTORAGE_DEVICE_NUMBER) *pSdn); + } + catch (SystemException &) + { + return GetLastError(); + } + catch (Exception &e) + { + e.Show (NULL); + return ERROR_EXCEPTION_IN_SERVICE; + } + catch (...) + { + return ERROR_EXCEPTION_IN_SERVICE; + } + + return ERROR_SUCCESS; +} + +DWORD BaseCom::ReadEfiConfig (BSTR* pContent, DWORD *pcbRead) +{ + if (!pContent || !(*pContent)) + return ERROR_INVALID_PARAMETER; + + try + { + DWORD maxSize = ((DWORD *) ((BYTE *) *pContent))[-1]; + BootEncryption bootEnc (NULL); + bootEnc.ReadEfiConfig ((byte*) *pContent, maxSize, pcbRead); + } + catch (SystemException &) + { + return GetLastError(); + } + catch (Exception &e) + { + e.Show (NULL); + return ERROR_EXCEPTION_IN_SERVICE; + } + catch (...) + { + return ERROR_EXCEPTION_IN_SERVICE; + } + + return ERROR_SUCCESS; +} + +DWORD BaseCom::WriteEfiBootSectorUserConfig (DWORD userConfig, BSTR customUserMessage, int pim, int hashAlg) +{ + if (!customUserMessage) + return ERROR_INVALID_PARAMETER; + + try + { + DWORD maxSize = ((DWORD *) ((BYTE *) customUserMessage))[-1]; + char* msg = (char*) *customUserMessage; + if (maxSize > 0) + msg [maxSize - 1] = 0; + std::string msgStr = maxSize > 0 ? msg : ""; + BootEncryption bootEnc (NULL); + bootEnc.WriteEfiBootSectorUserConfig ((byte) userConfig, msgStr, pim, hashAlg); + } + catch (SystemException &) + { + return GetLastError(); + } + catch (Exception &e) + { + e.Show (NULL); + return ERROR_EXCEPTION_IN_SERVICE; + } + catch (...) + { + return ERROR_EXCEPTION_IN_SERVICE; + } + + return ERROR_SUCCESS; +}
\ No newline at end of file |