VeraCrypt
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2017-06-07 10:21:00 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2017-06-08 01:17:46 +0200
commit9b0cc3d6795b8c0f38e3986bdddcb91e8aa384a1 (patch)
treeb8ef47ce0c3780933af7f4aec3c32d445ea2bcb1
parent9b4e087882e167d6816c468743fef50a050a1ca4 (diff)
downloadVeraCrypt-9b0cc3d6795b8c0f38e3986bdddcb91e8aa384a1.tar.gz
VeraCrypt-9b0cc3d6795b8c0f38e3986bdddcb91e8aa384a1.zip
Windows: correctly handle UTF-8 BOM when editing EFI DcsProp XML file
-rw-r--r--src/Mount/Mount.c41
1 files changed, 32 insertions, 9 deletions
diff --git a/src/Mount/Mount.c b/src/Mount/Mount.c
index 32f57a4e..2525a65a 100644
--- a/src/Mount/Mount.c
+++ b/src/Mount/Mount.c
@@ -10977,15 +10977,24 @@ static BOOL CALLBACK BootLoaderPreferencesDlgProc (HWND hwndDlg, UINT msg, WPARA
try
{
std::string platforminfo;
- DWORD sz;
+ ByteArray fileContent;
+ DWORD sz, offset;
std::wstring path;
GetVolumeESP(path);
path += L"\\EFI\\VeraCrypt\\PlatformInfo";
File fPlatformInfo(path);
fPlatformInfo.GetFileSize(sz);
- platforminfo.resize(sz + 1);
- platforminfo[sz] = 0;
- fPlatformInfo.Read((byte*)&platforminfo[0], sz);
+ fileContent.resize(sz + 1);
+ fileContent[sz] = 0;
+ fPlatformInfo.Read((byte*)&fileContent[0], sz);
+ // remove UTF-8 BOM if any
+ if (0 == memcmp (fileContent.data(), "\xEF\xBB\xBF", 3))
+ {
+ offset = 3;
+ }
+ else
+ offset = 0;
+ platforminfo = (const char*) &fileContent[offset];
TextEditDialogBox(0, hwndDlg, L"PlatformInfo", platforminfo);
}
catch (Exception &e) { e.Show(hwndDlg); }
@@ -10997,19 +11006,33 @@ static BOOL CALLBACK BootLoaderPreferencesDlgProc (HWND hwndDlg, UINT msg, WPARA
try
{
std::string dcsprop;
- DWORD sz;
+ ByteArray fileContent;
+ DWORD sz, offset;
std::wstring path;
GetVolumeESP(path);
path += L"\\EFI\\VeraCrypt\\DcsProp";
File f1(path);
f1.GetFileSize(sz);
- dcsprop.resize(sz + 1);
- dcsprop[sz] = 0;
- f1.Read((byte*)&dcsprop[0], sz);
+ fileContent.resize(sz + 1);
+ fileContent[sz] = 0;
+ f1.Read((byte*)&fileContent[0], sz);
f1.Close();
+ // remove UTF-8 BOM if any
+ if (0 == memcmp (fileContent.data(), "\xEF\xBB\xBF", 3))
+ {
+ offset = 3;
+ }
+ else
+ offset = 0;
+
+ dcsprop = (const char*) &fileContent[offset];
if(TextEditDialogBox(0, hwndDlg, L"DcsProp", dcsprop) == IDOK) {
+ // Add UTF-8 BOM
+ fileContent.resize (dcsprop.length() + 3);
+ memcpy (fileContent.data(), "\xEF\xBB\xBF", 3);
+ memcpy (&fileContent[3], &dcsprop[0], dcsprop.length());
File f2(path,false,true);
- f2.Write((byte*)&dcsprop[0], dcsprop.length());
+ f2.Write(fileContent.data(), fileContent.size());
f2.Close();
}
}