From 60575d9a496bd4b796bab73888b69c249a1f8048 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Fri, 8 Apr 2016 23:51:29 +0200 Subject: Windows: start implementation of volume ID mechanism that will be used to identify VeraCrypt disk volumes instead of device name. --- src/Mount/Favorites.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/Mount/Favorites.cpp') diff --git a/src/Mount/Favorites.cpp b/src/Mount/Favorites.cpp index 825562f2..5dde8da0 100644 --- a/src/Mount/Favorites.cpp +++ b/src/Mount/Favorites.cpp @@ -98,6 +98,7 @@ namespace VeraCrypt favorite.SystemEncryption = prop.partitionInInactiveSysEncScope ? true : false; favorite.OpenExplorerWindow = (bExplore == TRUE); favorite.Pim = prop.volumePim; + memcpy (favorite.VolumeID, prop.volumeID, SHA512_DIGESTSIZE); if (favorite.VolumePathId.empty() && IsVolumeDeviceHosted (favorite.Path.c_str()) @@ -416,6 +417,19 @@ namespace VeraCrypt case WM_CLOSE: EndDialog (hwndDlg, IDCLOSE); return 1; + case WM_CTLCOLORSTATIC: + { + HDC hdc = (HDC) wParam; + HWND hw = (HWND) lParam; + if (hw == GetDlgItem(hwndDlg, IDC_FAVORITE_ID)) + { + // This the favorite ID field. Make its background like normal edit + HBRUSH hbr = GetSysColorBrush (COLOR_WINDOW); + ::SelectObject(hdc, hbr); + return (BOOL) hbr; + } + } + break; } return 0; @@ -566,6 +580,17 @@ namespace VeraCrypt favorite.Path = Utf8StringToWide (volume); char label[1024]; + + XmlGetAttributeText (xml, "ID", label, sizeof (label)); + if (strlen (label) == 128) + { + std::vector arr; + if (HexWideStringToArray (Utf8StringToWide (label).c_str(), arr) && arr.size() == SHA512_DIGEST_SIZE) + { + memcpy (favorite.VolumeID, &arr[0], SHA512_DIGEST_SIZE); + } + } + XmlGetAttributeText (xml, "label", label, sizeof (label)); favorite.Label = Utf8StringToWide (label); @@ -612,6 +637,10 @@ namespace VeraCrypt if (boolVal[0]) favorite.UseLabelInExplorer = (boolVal[0] == '1') && !favorite.ReadOnly; + XmlGetAttributeText (xml, "useVolumeID", boolVal, sizeof (boolVal)); + if (boolVal[0]) + favorite.UseVolumeID = (boolVal[0] == '1') && !IsRepeatedByteArray (0, favorite.VolumeID, SHA512_DIGEST_SIZE); + if (favorite.Path.find (L"\\\\?\\Volume{") == 0 && favorite.Path.rfind (L"}\\") == favorite.Path.size() - 2) { wstring resolvedPath = VolumeGuidPathToDevicePath (favorite.Path); @@ -709,6 +738,9 @@ namespace VeraCrypt wstring s = L"\n\t\t" + wstring (tq) + L""; fwprintf (f, L"%ws", s.c_str()); @@ -819,6 +854,12 @@ namespace VeraCrypt SetCheckBox (hwndDlg, IDC_FAVORITE_MOUNT_ON_ARRIVAL, favorite.MountOnArrival); SetCheckBox (hwndDlg, IDC_FAVORITE_MOUNT_READONLY, favorite.ReadOnly); SetCheckBox (hwndDlg, IDC_FAVORITE_MOUNT_REMOVABLE, favorite.Removable); + SetCheckBox (hwndDlg, IDC_FAVORITE_USE_VOLUME_ID, favorite.UseVolumeID); + + if (!IsRepeatedByteArray (0, favorite.VolumeID, SHA512_DIGESTSIZE)) + { + SetDlgItemText (hwndDlg, IDC_FAVORITE_ID, ArrayToHexWideString (favorite.VolumeID, SHA512_DIGESTSIZE).c_str()); + } if (systemFavoritesMode) { @@ -873,6 +914,7 @@ namespace VeraCrypt favorite.Pim = GetPim (hwndDlg, IDC_PIM); favorite.UseLabelInExplorer = (IsDlgButtonChecked (hwndDlg, IDC_FAVORITE_USE_LABEL_IN_EXPLORER) != 0); + favorite.UseVolumeID = (IsDlgButtonChecked (hwndDlg, IDC_FAVORITE_USE_VOLUME_ID) != 0); favorite.ReadOnly = (IsDlgButtonChecked (hwndDlg, IDC_FAVORITE_MOUNT_READONLY) != 0); favorite.Removable = (IsDlgButtonChecked (hwndDlg, IDC_FAVORITE_MOUNT_REMOVABLE) != 0); -- cgit v1.2.3