From a36cf1f01e75930a2afbb3697e1ef6f9870f4028 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Tue, 8 Sep 2015 01:07:09 +0200 Subject: Windows Traveler Disk Setup: Include Volume Expander. Force selection of target directory through Browse button. Use Unicode functions for handling the creation files. --- src/Mount/Mount.c | 170 ++++++++++++++++++++++++++++++++++------------------- src/Mount/Mount.rc | 42 ++++++------- 2 files changed, 132 insertions(+), 80 deletions(-) (limited to 'src/Mount') diff --git a/src/Mount/Mount.c b/src/Mount/Mount.c index 72728321..01c5108d 100644 --- a/src/Mount/Mount.c +++ b/src/Mount/Mount.c @@ -3844,15 +3844,18 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa { case WM_INITDIALOG: { - char i; + WCHAR i; int index; - char drive[] = { 0, ':', 0 }; + WCHAR drive[] = { 0, L':', 0 }; LocalizeDialog (hwndDlg, "IDD_TRAVELER_DLG"); SendDlgItemMessage (hwndDlg, IDC_COPY_WIZARD, BM_SETCHECK, BST_CHECKED, 0); + SendDlgItemMessage (hwndDlg, IDC_COPY_EXPANDER, BM_SETCHECK, + BST_CHECKED, 0); + SendDlgItemMessage (hwndDlg, IDC_TRAVEL_OPEN_EXPLORER, BM_SETCHECK, BST_CHECKED, 0); @@ -3864,18 +3867,33 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa index = (int) SendDlgItemMessageW (hwndDlg, IDC_DRIVELIST, CB_ADDSTRING, 0, (LPARAM) GetString ("FIRST_AVAILABLE")); SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_SETITEMDATA, index, (LPARAM) 0); - for (i = 'D'; i <= 'Z'; i++) + for (i = L'A'; i <= L'Z'; i++) { + if (i == L'C') + continue; drive[0] = i; - index = (int) SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_ADDSTRING, 0, (LPARAM) drive); - SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_SETITEMDATA, index, (LPARAM) i); + index = (int) SendDlgItemMessageW (hwndDlg, IDC_DRIVELIST, CB_ADDSTRING, 0, (LPARAM) drive); + SendDlgItemMessageW (hwndDlg, IDC_DRIVELIST, CB_SETITEMDATA, index, (LPARAM) i); } - SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_SETCURSEL, 0, 0); + SendDlgItemMessageW (hwndDlg, IDC_DRIVELIST, CB_SETCURSEL, 0, 0); return 0; } + case WM_CTLCOLORSTATIC: + { + HDC hdc = (HDC) wParam; + HWND hw = (HWND) lParam; + if (hw == GetDlgItem(hwndDlg, IDC_DIRECTORY)) + { + // This the directory field. Make its background like normal edit + HBRUSH hbr = GetSysColorBrush (COLOR_WINDOW); + ::SelectObject(hdc, hbr); + return (BOOL) hbr; + } + } + return 0; case WM_COMMAND: @@ -3937,24 +3955,24 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa if (lw == IDC_CREATE) { - BOOL copyWizard, bExplore, bCacheInDriver, bAutoRun, bAutoMount, bMountReadOnly; - char dstDir[MAX_PATH]; - char srcPath[MAX_PATH * 2]; - char dstPath[MAX_PATH * 2]; - char appDir[MAX_PATH]; - char sysDir[MAX_PATH]; - char volName[MAX_PATH]; + BOOL copyWizard, copyExpander, bExplore, bCacheInDriver, bAutoRun, bAutoMount, bMountReadOnly; + WCHAR dstDir[MAX_PATH + 1]; + WCHAR srcPath[1024 + MAX_PATH + 1]; + WCHAR dstPath[2*MAX_PATH + 1]; + WCHAR appDir[1024]; + WCHAR volName[MAX_PATH + 2]; int drive; - char* ptr; + WCHAR* ptr; - GetDlgItemText (hwndDlg, IDC_DIRECTORY, dstDir, sizeof dstDir); + GetDlgItemTextW (hwndDlg, IDC_DIRECTORY, dstDir, array_capacity (dstDir)); volName[0] = 0; - GetDlgItemText (hwndDlg, IDC_VOLUME_NAME, volName + 1, (sizeof volName) - 1); + GetDlgItemTextW (hwndDlg, IDC_VOLUME_NAME, volName + 1, (array_capacity (volName)) - 1); drive = (int) SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_GETCURSEL, 0, 0); drive = (int) SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_GETITEMDATA, drive, 0); copyWizard = IsButtonChecked (GetDlgItem (hwndDlg, IDC_COPY_WIZARD)); + copyExpander = IsButtonChecked (GetDlgItem (hwndDlg, IDC_COPY_EXPANDER)); bExplore = IsButtonChecked (GetDlgItem (hwndDlg, IDC_TRAVEL_OPEN_EXPLORER)); bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_TRAV_CACHE_PASSWORDS)); bMountReadOnly = IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY)); @@ -3978,27 +3996,30 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa if (volName[1] != 0) { - volName[0] = '"'; - StringCbCatA (volName, sizeof(volName), "\""); + volName[0] = L'"'; + StringCbCatW (volName, sizeof(volName), L"\""); } - GetModuleFileName (NULL, appDir, sizeof (appDir)); - if (ptr = strrchr (appDir, '\\')) + GetModuleFileNameW (NULL, appDir, array_capacity (appDir)); + if (ptr = wcsrchr (appDir, L'\\')) ptr[0] = 0; WaitCursor (); - GetSystemDirectory (sysDir, sizeof (sysDir)); - StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt", dstDir); - CreateDirectory (dstPath, NULL); + StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt", dstDir); + if (!CreateDirectoryW (dstPath, NULL)) + { + handleWin32Error (hwndDlg, SRC_POS); + goto stop; + } // Main app 32-bit if (Is64BitOs ()) - StringCbPrintfA (srcPath, sizeof(srcPath), "%s\\VeraCrypt-x86.exe", appDir); + StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\VeraCrypt-x86.exe", appDir); else - StringCbPrintfA (srcPath, sizeof(srcPath), "%s\\VeraCrypt.exe", appDir); - StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\VeraCrypt.exe", dstDir); - if (!TCCopyFile (srcPath, dstPath)) + StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\VeraCrypt.exe", appDir); + StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCrypt.exe", dstDir); + if (!TCCopyFileW (srcPath, dstPath)) { handleWin32Error (hwndDlg, SRC_POS); goto stop; @@ -4006,11 +4027,11 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa // Main app 64-bit if (Is64BitOs ()) - StringCbPrintfA (srcPath, sizeof(srcPath), "%s\\VeraCrypt.exe", appDir); + StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\VeraCrypt.exe", appDir); else - StringCbPrintfA (srcPath, sizeof(srcPath), "%s\\VeraCrypt-x64.exe", appDir); - StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\VeraCrypt-x64.exe", dstDir); - if (!TCCopyFile (srcPath, dstPath)) + StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\VeraCrypt-x64.exe", appDir); + StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCrypt-x64.exe", dstDir); + if (!TCCopyFileW (srcPath, dstPath)) { handleWin32Error (hwndDlg, SRC_POS); goto stop; @@ -4021,11 +4042,11 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa { // Wizard 32-bit if (Is64BitOs ()) - StringCbPrintfA (srcPath, sizeof(srcPath), "%s\\VeraCrypt Format-x86.exe", appDir); + StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\VeraCrypt Format-x86.exe", appDir); else - StringCbPrintfA (srcPath, sizeof(srcPath), "%s\\VeraCrypt Format.exe", appDir); - StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\VeraCrypt Format.exe", dstDir); - if (!TCCopyFile (srcPath, dstPath)) + StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\VeraCrypt Format.exe", appDir); + StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCrypt Format.exe", dstDir); + if (!TCCopyFileW (srcPath, dstPath)) { handleWin32Error (hwndDlg, SRC_POS); goto stop; @@ -4033,11 +4054,39 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa // Wizard 64-bit if (Is64BitOs ()) - StringCbPrintfA (srcPath, sizeof(srcPath), "%s\\VeraCrypt Format.exe", appDir); + StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\VeraCrypt Format.exe", appDir); + else + StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\VeraCrypt Format-x64.exe", appDir); + StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCrypt Format-x64.exe", dstDir); + if (!TCCopyFileW (srcPath, dstPath)) + { + handleWin32Error (hwndDlg, SRC_POS); + goto stop; + } + } + + // Expander + if (copyExpander) + { + // Expander 32-bit + if (Is64BitOs ()) + StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\VeraCryptExpander-x86.exe", appDir); + else + StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\VeraCryptExpander.exe", appDir); + StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCryptExpander.exe", dstDir); + if (!TCCopyFileW (srcPath, dstPath)) + { + handleWin32Error (hwndDlg, SRC_POS); + goto stop; + } + + // Expander 64-bit + if (Is64BitOs ()) + StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\VeraCryptExpander.exe", appDir); else - StringCbPrintfA (srcPath, sizeof(srcPath), "%s\\VeraCrypt Format-x64.exe", appDir); - StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\VeraCrypt Format-x64.exe", dstDir); - if (!TCCopyFile (srcPath, dstPath)) + StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\VeraCryptExpander-x64.exe", appDir); + StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCryptExpander-x64.exe", dstDir); + if (!TCCopyFileW (srcPath, dstPath)) { handleWin32Error (hwndDlg, SRC_POS); goto stop; @@ -4045,18 +4094,18 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa } // Driver - StringCbPrintfA (srcPath, sizeof(srcPath), "%s\\veracrypt.sys", appDir); - StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\veracrypt.sys", dstDir); - if (!TCCopyFile (srcPath, dstPath)) + StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\veracrypt.sys", appDir); + StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\veracrypt.sys", dstDir); + if (!TCCopyFileW (srcPath, dstPath)) { handleWin32Error (hwndDlg, SRC_POS); goto stop; } // Driver x64 - StringCbPrintfA (srcPath, sizeof(srcPath), "%s\\veracrypt-x64.sys", appDir); - StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\veracrypt-x64.sys", dstDir); - if (!TCCopyFile (srcPath, dstPath)) + StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\veracrypt-x64.sys", appDir); + StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\veracrypt-x64.sys", dstDir); + if (!TCCopyFileW (srcPath, dstPath)) { handleWin32Error (hwndDlg, SRC_POS); goto stop; @@ -4065,21 +4114,21 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa if (GetPreferredLangId () && strcmp (GetPreferredLangId (), "en") != 0) { // Language pack - StringCbPrintfA (srcPath, sizeof(srcPath), "%s\\Language.%s.xml", appDir, GetPreferredLangId ()); - StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\Language.%s.xml", dstDir, GetPreferredLangId ()); - TCCopyFile (srcPath, dstPath); + StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\Language.%s.xml", appDir, GetPreferredLangId ()); + StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\Language.%s.xml", dstDir, GetPreferredLangId ()); + TCCopyFileW (srcPath, dstPath); } // AutoRun - StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\autorun.inf", dstDir); - DeleteFile (dstPath); + StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\autorun.inf", dstDir); + DeleteFileW (dstPath); if (bAutoRun) { FILE *af; - char autoMount[100]; - char driveLetter[] = { ' ', '/', 'l', (char) drive, 0 }; + wchar_t autoMount[2*MAX_PATH + 2]; + wchar_t driveLetter[] = { L' ', L'/', L'l', L' ', (wchar_t) drive, 0 }; - af = fopen (dstPath, "w,ccs=UNICODE"); + af = _wfopen (dstPath, L"w,ccs=UNICODE"); if (af == NULL) { @@ -4087,20 +4136,21 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa goto stop; } - StringCbPrintfA (autoMount, sizeof(autoMount), "VeraCrypt\\VeraCrypt.exe /q background%s%s%s%s /m rm /v %s", - drive > 0 ? driveLetter : "", - bExplore ? " /e" : "", - bCacheInDriver ? " /c y" : "", - bMountReadOnly ? " /m ro" : "", + StringCbPrintfW (autoMount, sizeof(autoMount), L"VeraCrypt\\VeraCrypt.exe /q background%s%s%s%s /m rm /v %s", + drive > 0 ? driveLetter : L"", + bExplore ? L" /e" : L"", + bCacheInDriver ? L" /c y" : L"", + bMountReadOnly ? L" /m ro" : L"", volName); fwprintf (af, L"[autorun]\nlabel=%s\nicon=VeraCrypt\\VeraCrypt.exe\n", GetString ("TC_TRAVELER_DISK")); fwprintf (af, L"action=%s\n", bAutoMount ? GetString ("MOUNT_TC_VOLUME") : GetString ("IDC_PREF_LOGON_START")); - fwprintf (af, L"open=%hs\n", bAutoMount ? autoMount : "VeraCrypt\\VeraCrypt.exe"); + fwprintf (af, L"open=%s\n", bAutoMount ? autoMount : L"VeraCrypt\\VeraCrypt.exe"); fwprintf (af, L"shell\\start=%s\nshell\\start\\command=VeraCrypt\\VeraCrypt.exe\n", GetString ("IDC_PREF_LOGON_START")); fwprintf (af, L"shell\\dismount=%s\nshell\\dismount\\command=VeraCrypt\\VeraCrypt.exe /q /d\n", GetString ("DISMOUNT_ALL_TC_VOLUMES")); - CheckFileStreamWriteErrors (hwndDlg, af, dstPath); + ToSBCS (dstPath, sizeof (dstPath)); + CheckFileStreamWriteErrors (hwndDlg, af, (char*) dstPath); fclose (af); } MessageBoxW (hwndDlg, GetString ("TRAVELER_DISK_CREATED"), lpszTitle, MB_ICONINFORMATION); diff --git a/src/Mount/Mount.rc b/src/Mount/Mount.rc index 14283f4e..09a2b637 100644 --- a/src/Mount/Mount.rc +++ b/src/Mount/Mount.rc @@ -198,36 +198,38 @@ BEGIN RTEXT "Volume PIM:",IDT_PIM,0,46,65,8,NOT WS_VISIBLE END -IDD_TRAVELER_DLG DIALOGEX 0, 0, 300, 269 +IDD_TRAVELER_DLG DIALOGEX 0, 0, 300, 287 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "VeraCrypt Traveler Disk Setup" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN - EDITTEXT IDC_DIRECTORY,17,29,205,13,ES_AUTOHSCROLL + EDITTEXT IDC_DIRECTORY,17,29,205,13,ES_AUTOHSCROLL | ES_READONLY PUSHBUTTON "Browse...",IDC_BROWSE_DIRS,228,28,57,14 CONTROL "Include VeraCrypt Volume Creation Wizard",IDC_COPY_WIZARD, "Button",BS_AUTOCHECKBOX | WS_TABSTOP,19,48,258,10 - CONTROL "Do nothing",IDC_AUTORUN_DISABLE,"Button",BS_AUTORADIOBUTTON,15,97,262,10 - CONTROL "&Start VeraCrypt",IDC_AUTORUN_START,"Button",BS_AUTORADIOBUTTON,15,108,262,11 + CONTROL "Do nothing",IDC_AUTORUN_DISABLE,"Button",BS_AUTORADIOBUTTON,15,115,262,10 + CONTROL "&Start VeraCrypt",IDC_AUTORUN_START,"Button",BS_AUTORADIOBUTTON,15,126,262,11 CONTROL "&Auto-mount VeraCrypt volume (specified below)",IDC_AUTORUN_MOUNT, - "Button",BS_AUTORADIOBUTTON,15,120,262,11 - EDITTEXT IDC_VOLUME_NAME,21,157,194,13,ES_AUTOHSCROLL | WS_DISABLED - PUSHBUTTON "Browse...",IDC_BROWSE_FILES,221,156,57,14,WS_DISABLED - COMBOBOX IDC_DRIVELIST,120,175,96,69,CBS_DROPDOWNLIST | WS_DISABLED | WS_VSCROLL | WS_TABSTOP + "Button",BS_AUTORADIOBUTTON,15,138,262,11 + EDITTEXT IDC_VOLUME_NAME,21,175,194,13,ES_AUTOHSCROLL | WS_DISABLED + PUSHBUTTON "Browse...",IDC_BROWSE_FILES,221,174,57,14,WS_DISABLED + COMBOBOX IDC_DRIVELIST,120,193,96,69,CBS_DROPDOWNLIST | WS_DISABLED | WS_VSCROLL | WS_TABSTOP CONTROL "Open &Explorer window for mounted volume",IDC_TRAVEL_OPEN_EXPLORER, - "Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,22,193,256,10 - CONTROL "Mount volume as read-&only",IDC_MOUNT_READONLY,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,22,206,256,10 + "Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,22,211,256,10 + CONTROL "Mount volume as read-&only",IDC_MOUNT_READONLY,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,22,224,256,10 CONTROL "&Cache password in driver memory",IDC_TRAV_CACHE_PASSWORDS, - "Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,22,219,256,10 - DEFPUSHBUTTON "Create",IDC_CREATE,173,249,57,14 - PUSHBUTTON "Close",IDCLOSE,236,249,57,14 - GROUPBOX "File Settings",IDT_FILE_SETTINGS,6,7,287,59 - GROUPBOX "AutoRun Configuration (autorun.inf)",IDT_AUTORUN,5,70,288,172 - LTEXT "VeraCrypt volume to mount (relative to traveler disk root):",IDT_TRAVELER_MOUNT,21,147,248,8,WS_DISABLED - RTEXT "Mount volume as drive letter:",IDT_MOUNT_LETTER,18,177,99,8,WS_DISABLED + "Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,22,237,256,10 + DEFPUSHBUTTON "Create",IDC_CREATE,173,267,57,14 + PUSHBUTTON "Close",IDCLOSE,236,267,57,14 + GROUPBOX "File Settings",IDT_FILE_SETTINGS,6,7,287,71 + GROUPBOX "AutoRun Configuration (autorun.inf)",IDT_AUTORUN,5,88,288,172 + LTEXT "VeraCrypt volume to mount (relative to traveler disk root):",IDT_TRAVELER_MOUNT,21,165,248,8,WS_DISABLED + RTEXT "Mount volume as drive letter:",IDT_MOUNT_LETTER,18,195,99,8,WS_DISABLED LTEXT "Create traveler disk files at (traveler disk root directory):",IDT_TRAVEL_ROOT,18,19,259,8 - GROUPBOX "Mount Settings",IDT_MOUNT_SETTINGS,13,134,272,100,WS_DISABLED - LTEXT "Upon insertion of traveler disk: ",IDT_TRAVEL_INSERTION,13,84,263,8 + GROUPBOX "Mount Settings",IDT_MOUNT_SETTINGS,13,152,272,100,WS_DISABLED + LTEXT "Upon insertion of traveler disk: ",IDT_TRAVEL_INSERTION,13,102,263,8 + CONTROL "Include VeraCrypt Volume Expander",IDC_COPY_EXPANDER, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,19,62,258,10 END IDD_HOTKEYS_DLG DIALOGEX 0, 0, 389, 257 @@ -413,7 +415,7 @@ BEGIN LEFTMARGIN, 7 RIGHTMARGIN, 293 TOPMARGIN, 7 - BOTTOMMARGIN, 262 + BOTTOMMARGIN, 280 END IDD_HOTKEYS_DLG, DIALOG -- cgit v1.2.3