diff options
Diffstat (limited to 'src/Common/Dlgcode.c')
-rw-r--r-- | src/Common/Dlgcode.c | 1464 |
1 files changed, 697 insertions, 767 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c index 65801bea..48dc1dd2 100644 --- a/src/Common/Dlgcode.c +++ b/src/Common/Dlgcode.c @@ -72,9 +72,9 @@ using namespace VeraCrypt; LONG DriverVersion;
char *LastDialogId;
-char szHelpFile[TC_MAX_PATH];
-char szHelpFile2[TC_MAX_PATH];
-char SecurityTokenLibraryPath[TC_MAX_PATH];
+wchar_t szHelpFile[TC_MAX_PATH];
+wchar_t szHelpFile2[TC_MAX_PATH];
+wchar_t SecurityTokenLibraryPath[TC_MAX_PATH];
HFONT hFixedDigitFont = NULL;
HFONT hBoldFont = NULL;
@@ -170,9 +170,9 @@ BOOL bSysPartitionSelected = FALSE; /* TRUE if the user selected the system par BOOL bSysDriveSelected = FALSE; /* TRUE if the user selected the system drive via the Select Device dialog */
/* To populate these arrays, call GetSysDevicePaths(). If they contain valid paths, bCachedSysDevicePathsValid is TRUE. */
-char SysPartitionDevicePath [TC_MAX_PATH];
-char SysDriveDevicePath [TC_MAX_PATH];
-string ExtraBootPartitionDevicePath;
+wchar_t SysPartitionDevicePath [TC_MAX_PATH];
+wchar_t SysDriveDevicePath [TC_MAX_PATH];
+wstring ExtraBootPartitionDevicePath;
char bCachedSysDevicePathsValid = FALSE;
BOOL bHyperLinkBeingTracked = FALSE;
@@ -219,7 +219,7 @@ enum typedef struct
{
int id;
- char name[100];
+ wchar_t name[100];
unsigned __int64 encSpeed;
unsigned __int64 decSpeed;
unsigned __int64 meanBytesPerSec;
@@ -321,23 +321,23 @@ void cleanup () }
-void LowerCaseCopy (char *lpszDest, const char *lpszSource)
+void LowerCaseCopy (wchar_t *lpszDest, const wchar_t *lpszSource)
{
- size_t i = strlen (lpszSource) + 1;
+ size_t i = wcslen (lpszSource) + 1;
lpszDest[i - 1] = 0;
while (--i > 0)
{
- lpszDest[i - 1] = (char) tolower (lpszSource[i - 1]);
+ lpszDest[i - 1] = (wchar_t) towlower (lpszSource[i - 1]);
}
}
-void UpperCaseCopy (char *lpszDest, size_t cbDest, const char *lpszSource)
+void UpperCaseCopy (wchar_t *lpszDest, size_t cbDest, const wchar_t *lpszSource)
{
if (lpszDest && cbDest)
{
- size_t i = strlen (lpszSource);
+ size_t i = wcslen (lpszSource);
if (i >= cbDest)
i = cbDest - 1;
@@ -345,7 +345,7 @@ void UpperCaseCopy (char *lpszDest, size_t cbDest, const char *lpszSource) i++;
while (--i > 0)
{
- lpszDest[i - 1] = (char) toupper (lpszSource[i - 1]);
+ lpszDest[i - 1] = (wchar_t) towupper (lpszSource[i - 1]);
}
}
}
@@ -362,16 +362,27 @@ std::string ToUpperCase (const std::string &str) return u;
}
-size_t TrimWhiteSpace(char *str)
+std::wstring ToUpperCase (const std::wstring &str)
{
- char *end, *ptr = str;
+ wstring u;
+ foreach (wchar_t c, str)
+ {
+ u += (wchar_t) towupper (c);
+ }
+
+ return u;
+}
+
+size_t TrimWhiteSpace(wchar_t *str)
+{
+ wchar_t *end, *ptr = str;
size_t out_size;
if(!str || *str == 0)
return 0;
// Trim leading space
- while(isspace(*ptr)) ptr++;
+ while(iswspace(*ptr)) ptr++;
if(*ptr == 0) // All spaces?
{
@@ -380,32 +391,32 @@ size_t TrimWhiteSpace(char *str) }
// Trim trailing space
- end = str + strlen(str) - 1;
- while(end > ptr && isspace(*end)) end--;
+ end = str + wcslen(str) - 1;
+ while(end > ptr && iswspace(*end)) end--;
end++;
// Set output size to trimmed string length
out_size = (end - ptr);
// Copy trimmed string and add null terminator
- memmove(str, ptr, out_size);
+ wmemmove(str, ptr, out_size);
str[out_size] = 0;
return out_size;
}
// check the validity of a file name
-BOOL IsValidFileName(const char* str)
+BOOL IsValidFileName(const wchar_t* str)
{
- static char invalidChars[9] = {'<', '>', ':', '"', '/', '\\', '|', '?', '*'};
- char c;
+ static wchar_t invalidChars[9] = {L'<', L'>', L':', L'"', L'/', L'\\', L'|', L'?', L'*'};
+ wchar_t c;
int i;
BOOL bNotDotOnly = FALSE;
while ((c = *str))
{
- if (c != '.')
+ if (c != L'.')
bNotDotOnly = TRUE;
- for (i= 0; i < sizeof(invalidChars); i++)
+ for (i= 0; i < ARRAYSIZE(invalidChars); i++)
if (c == invalidChars[i])
return FALSE;
str++;
@@ -414,38 +425,38 @@ BOOL IsValidFileName(const char* str) return bNotDotOnly;
}
-BOOL IsVolumeDeviceHosted (const char *lpszDiskFile)
+BOOL IsVolumeDeviceHosted (const wchar_t *lpszDiskFile)
{
- return strstr (lpszDiskFile, "\\Device\\") == lpszDiskFile
- || strstr (lpszDiskFile, "\\DEVICE\\") == lpszDiskFile;
+ return wcsstr (lpszDiskFile, L"\\Device\\") == lpszDiskFile
+ || wcsstr (lpszDiskFile, L"\\DEVICE\\") == lpszDiskFile;
}
-void CreateFullVolumePath (char *lpszDiskFile, size_t cbDiskFile, const char *lpszFileName, BOOL * bDevice)
+void CreateFullVolumePath (wchar_t *lpszDiskFile, size_t cbDiskFile, const wchar_t *lpszFileName, BOOL * bDevice)
{
UpperCaseCopy (lpszDiskFile, cbDiskFile, lpszFileName);
*bDevice = FALSE;
- if (memcmp (lpszDiskFile, "\\DEVICE", sizeof (char) * 7) == 0)
+ if (wmemcmp (lpszDiskFile, L"\\DEVICE", 7) == 0)
{
*bDevice = TRUE;
}
- StringCbCopyA (lpszDiskFile, cbDiskFile, lpszFileName);
+ StringCbCopyW (lpszDiskFile, cbDiskFile, lpszFileName);
#if _DEBUG
- OutputDebugString ("CreateFullVolumePath: ");
+ OutputDebugString (L"CreateFullVolumePath: ");
OutputDebugString (lpszDiskFile);
- OutputDebugString ("\n");
+ OutputDebugString (L"\n");
#endif
}
-int FakeDosNameForDevice (const char *lpszDiskFile , char *lpszDosDevice , size_t cbDosDevice, char *lpszCFDevice , size_t cbCFDevice, BOOL bNameOnly)
+int FakeDosNameForDevice (const wchar_t *lpszDiskFile , wchar_t *lpszDosDevice , size_t cbDosDevice, wchar_t *lpszCFDevice , size_t cbCFDevice, BOOL bNameOnly)
{
BOOL bDosLinkCreated = TRUE;
- StringCbPrintfA (lpszDosDevice, cbDosDevice,"veracrypt%lu", GetCurrentProcessId ());
+ StringCbPrintfW (lpszDosDevice, cbDosDevice,L"veracrypt%lu", GetCurrentProcessId ());
if (bNameOnly == FALSE)
bDosLinkCreated = DefineDosDevice (DDD_RAW_TARGET_PATH, lpszDosDevice, lpszDiskFile);
@@ -453,12 +464,12 @@ int FakeDosNameForDevice (const char *lpszDiskFile , char *lpszDosDevice , size_ if (bDosLinkCreated == FALSE)
return ERR_OS_ERROR;
else
- StringCbPrintfA (lpszCFDevice, cbCFDevice,"\\\\.\\%s", lpszDosDevice);
+ StringCbPrintfW (lpszCFDevice, cbCFDevice,L"\\\\.\\%s", lpszDosDevice);
return 0;
}
-int RemoveFakeDosName (char *lpszDiskFile, char *lpszDosDevice)
+int RemoveFakeDosName (wchar_t *lpszDiskFile, wchar_t *lpszDosDevice)
{
BOOL bDosLinkRemoved = DefineDosDevice (DDD_RAW_TARGET_PATH | DDD_EXACT_MATCH_ON_REMOVE |
DDD_REMOVE_DEFINITION, lpszDosDevice, lpszDiskFile);
@@ -700,9 +711,9 @@ int GetTextGfxHeight (HWND hwndDlgItem, const wchar_t *text, HFONT hFont) }
-std::string FitPathInGfxWidth (HWND hwnd, HFONT hFont, LONG width, const std::string &path)
+std::wstring FitPathInGfxWidth (HWND hwnd, HFONT hFont, LONG width, const std::wstring &path)
{
- string newPath;
+ wstring newPath;
RECT rect;
rect.left = 0;
@@ -713,8 +724,8 @@ std::string FitPathInGfxWidth (HWND hwnd, HFONT hFont, LONG width, const std::st HDC hdc = GetDC (hwnd);
SelectObject (hdc, (HGDIOBJ) hFont);
- char pathBuf[TC_MAX_PATH];
- strcpy_s (pathBuf, sizeof (pathBuf), path.c_str());
+ wchar_t pathBuf[TC_MAX_PATH];
+ StringCbCopyW (pathBuf, sizeof (pathBuf), path.c_str());
if (DrawText (hdc, pathBuf, (int) path.size(), &rect, DT_CALCRECT | DT_MODIFYSTRING | DT_PATH_ELLIPSIS | DT_SINGLELINE) != 0)
newPath = pathBuf;
@@ -964,13 +975,13 @@ BOOL CALLBACK AboutDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam {
case WM_INITDIALOG:
{
- char szTmp[100];
+ wchar_t szTmp[100];
RECT rec;
LocalizeDialog (hwndDlg, "IDD_ABOUT_DLG");
// Hyperlink
- SetWindowText (GetDlgItem (hwndDlg, IDC_HOMEPAGE), "www.idrix.fr");
+ SetWindowText (GetDlgItem (hwndDlg, IDC_HOMEPAGE), L"www.idrix.fr");
ToHyperlink (hwndDlg, IDC_HOMEPAGE);
// Logo area background (must not keep aspect ratio; must retain Windows-imposed distortion)
@@ -990,14 +1001,14 @@ BOOL CALLBACK AboutDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam // Version
SendMessage (GetDlgItem (hwndDlg, IDT_ABOUT_VERSION), WM_SETFONT, (WPARAM) hUserBoldFont, 0);
- StringCbPrintfA (szTmp, sizeof(szTmp), "VeraCrypt %s", VERSION_STRING);
+ StringCbPrintfW (szTmp, sizeof(szTmp), L"VeraCrypt %s", _T(VERSION_STRING));
#ifdef _WIN64
- StringCbCatA (szTmp, sizeof(szTmp), " (64-bit)");
+ StringCbCatW (szTmp, sizeof(szTmp), L" (64-bit)");
#else
- StringCbCatA (szTmp, sizeof(szTmp), " (32-bit)");
+ StringCbCatW (szTmp, sizeof(szTmp), L" (32-bit)");
#endif
#if (defined(_DEBUG) || defined(DEBUG))
- StringCbCatA (szTmp, sizeof(szTmp), " (debug)");
+ StringCbCatW (szTmp, sizeof(szTmp), L" (debug)");
#endif
SetDlgItemText (hwndDlg, IDT_ABOUT_VERSION, szTmp);
SetDlgItemText (hwndDlg, IDT_ABOUT_RELEASE, TC_STR_RELEASED_BY);
@@ -1010,19 +1021,19 @@ BOOL CALLBACK AboutDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam case WM_APP:
SetWindowText (GetDlgItem (hwndDlg, IDC_ABOUT_CREDITS),
- "Based on TrueCrypt 7.1a, freely available at http://www.truecrypt.org/ .\r\n\r\n"
+ L"Based on TrueCrypt 7.1a, freely available at http://www.truecrypt.org/ .\r\n\r\n"
- "Portions of this software:\r\n"
- "Copyright \xA9 2013-2015 IDRIX. All rights reserved.\r\n"
- "Copyright \xA9 2003-2012 TrueCrypt Developers Association. All Rights Reserved.\r\n"
- "Copyright \xA9 1998-2000 Paul Le Roux. All Rights Reserved.\r\n"
- "Copyright \xA9 1998-2008 Brian Gladman. All Rights Reserved.\r\n"
- "Copyright \xA9 2002-2004 Mark Adler. All Rights Reserved.\r\n\r\n"
+ L"Portions of this software:\r\n"
+ L"Copyright \xA9 2013-2015 IDRIX. All rights reserved.\r\n"
+ L"Copyright \xA9 2003-2012 TrueCrypt Developers Association. All Rights Reserved.\r\n"
+ L"Copyright \xA9 1998-2000 Paul Le Roux. All Rights Reserved.\r\n"
+ L"Copyright \xA9 1998-2008 Brian Gladman. All Rights Reserved.\r\n"
+ L"Copyright \xA9 2002-2004 Mark Adler. All Rights Reserved.\r\n\r\n"
- "This software as a whole:\r\n"
- "Copyright \xA9 2013-2015 IDRIX. All rights reserved.\r\n\r\n"
+ L"This software as a whole:\r\n"
+ L"Copyright \xA9 2013-2015 IDRIX. All rights reserved.\r\n\r\n"
- "An IDRIX Release");
+ L"An IDRIX Release");
return 1;
@@ -1137,7 +1148,7 @@ void CheckButton (HWND hButton) }
-void LeftPadString (char *szTmp, int len, int targetLen, char filler)
+void LeftPadString (wchar_t *szTmp, int len, int targetLen, wchar_t filler)
{
int i;
@@ -1147,62 +1158,10 @@ void LeftPadString (char *szTmp, int len, int targetLen, char filler) for (i = targetLen-1; i >= (targetLen-len); i--)
szTmp [i] = szTmp [i-(targetLen-len)];
- memset (szTmp, filler, targetLen-len);
+ wmemset (szTmp, filler, targetLen-len);
szTmp [targetLen] = 0;
}
-
-/*****************************************************************************
- ToSBCS: converts a unicode string to Single Byte Character String (SBCS).
- ***************************************************************************/
-
-void ToSBCS (LPWSTR lpszText, size_t cbSize)
-{
- if (lpszText)
- {
- int j = (int) wcslen (lpszText);
- if (j == 0)
- {
- *((char *) lpszText) = 0;
- return;
- }
- else
- {
- char *lpszNewText = (char *) err_malloc (j + 1);
- j = WideCharToMultiByte (CP_ACP, 0L, lpszText, -1, lpszNewText, j + 1, NULL, NULL);
- if (j > 0)
- StringCbCopyA ((char *) lpszText, cbSize, lpszNewText);
- else
- *((char *) lpszText) = 0;
- free (lpszNewText);
- }
- }
-}
-
-/*****************************************************************************
- ToUNICODE: converts a SBCS string to a UNICODE string.
- ***************************************************************************/
-
-void ToUNICODE (char *lpszText, size_t cbSize)
-{
- int j = (int) strlen (lpszText);
- if (j == 0)
- {
- StringCbCopyW ((LPWSTR) lpszText, cbSize, (LPWSTR) WIDE (""));
- return;
- }
- else
- {
- LPWSTR lpszNewText = (LPWSTR) err_malloc ((j + 1) * 2);
- j = MultiByteToWideChar (CP_ACP, 0L, lpszText, -1, lpszNewText, j + 1);
- if (j > 0)
- StringCbCopyW ((LPWSTR) lpszText, cbSize, lpszNewText);
- else
- StringCbCopyW ((LPWSTR) lpszText, cbSize, (LPWSTR) WIDE (""));
- free (lpszNewText);
- }
-}
-
/* InitDialog - initialize the applications main dialog, this function should
be called only once in the dialogs WM_INITDIALOG message handler */
void InitDialog (HWND hwndDlg)
@@ -1333,7 +1292,7 @@ void InitDialog (HWND hwndDlg) if (!aboutMenuAppended)
{
hMenu = GetSystemMenu (hwndDlg, FALSE);
- AppendMenu (hMenu, MF_SEPARATOR, 0, "");
+ AppendMenu (hMenu, MF_SEPARATOR, 0, L"");
AppendMenuW (hMenu, MF_ENABLED | MF_STRING, IDC_ABOUT, GetString ("ABOUTBOX"));
aboutMenuAppended = TRUE;
@@ -1354,7 +1313,7 @@ void ProcessPaintMessages (HWND hwnd, int maxMessagesToProcess) }
-HDC CreateMemBitmap (HINSTANCE hInstance, HWND hwnd, char *resource)
+HDC CreateMemBitmap (HINSTANCE hInstance, HWND hwnd, wchar_t *resource)
{
HBITMAP picture = LoadBitmap (hInstance, resource);
HDC viewDC = GetDC (hwnd), dcMem;
@@ -1384,7 +1343,7 @@ deleted by calling DeleteObject() with the handle passed as the parameter. Known Windows issues:
- For some reason, anti-aliasing is not applied if the source bitmap contains less than 16K pixels.
- Windows 2000 may produce slightly inaccurate colors even when source, buffer, and target are 24-bit true color. */
-HBITMAP RenderBitmap (char *resource, HWND hwndDest, int x, int y, int nWidth, int nHeight, BOOL bDirectRender, BOOL bKeepAspectRatio)
+HBITMAP RenderBitmap (wchar_t *resource, HWND hwndDest, int x, int y, int nWidth, int nHeight, BOOL bDirectRender, BOOL bKeepAspectRatio)
{
LRESULT lResult = 0;
@@ -1711,15 +1670,15 @@ wchar_t *GetWipeModeName (WipeAlgorithmId modeId) }
}
-wchar_t *GetPathType (const char *path, BOOL bUpperCase, BOOL *bIsPartition)
+wchar_t *GetPathType (const wchar_t *path, BOOL bUpperCase, BOOL *bIsPartition)
{
- if (strstr (path, "Partition")
- && strstr (path, "Partition0") == NULL)
+ if (wcsstr (path, L"Partition")
+ && wcsstr (path, L"Partition0") == NULL)
{
*bIsPartition = TRUE;
return GetString (bUpperCase ? "PARTITION_UPPER_CASE" : "PARTITION_LOWER_CASE");
}
- else if (strstr (path, "HarddiskVolume"))
+ else if (wcsstr (path, L"HarddiskVolume"))
{
*bIsPartition = TRUE;
return GetString (bUpperCase ? "VOLUME_UPPER_CASE" : "VOLUME_LOWER_CASE");
@@ -2088,7 +2047,7 @@ BOOL IsTrueCryptInstallerRunning (void) // Returns TRUE if the mutex is (or had been) successfully acquired (otherwise FALSE).
-BOOL TCCreateMutex (volatile HANDLE *hMutex, char *name)
+BOOL TCCreateMutex (volatile HANDLE *hMutex, wchar_t *name)
{
if (*hMutex != NULL)
return TRUE; // This instance already has the mutex
@@ -2128,7 +2087,7 @@ void TCCloseMutex (volatile HANDLE *hMutex) // Returns TRUE if a process running on the system has the specified mutex (otherwise FALSE).
-BOOL MutexExistsOnSystem (char *name)
+BOOL MutexExistsOnSystem (wchar_t *name)
{
if (name[0] == 0)
return FALSE;
@@ -2156,7 +2115,7 @@ uint32 ReadDriverConfigurationFlags () {
DWORD configMap;
- if (!ReadLocalMachineRegistryDword ("SYSTEM\\CurrentControlSet\\Services\\veracrypt", TC_DRIVER_CONFIG_REG_VALUE_NAME, &configMap))
+ if (!ReadLocalMachineRegistryDword (L"SYSTEM\\CurrentControlSet\\Services\\veracrypt", TC_DRIVER_CONFIG_REG_VALUE_NAME, &configMap))
configMap = 0;
return configMap;
@@ -2167,7 +2126,7 @@ uint32 ReadEncryptionThreadPoolFreeCpuCountLimit () {
DWORD count;
- if (!ReadLocalMachineRegistryDword ("SYSTEM\\CurrentControlSet\\Services\\veracrypt", TC_ENCRYPTION_FREE_CPU_COUNT_REG_VALUE_NAME, &count))
+ if (!ReadLocalMachineRegistryDword (L"SYSTEM\\CurrentControlSet\\Services\\veracrypt", TC_ENCRYPTION_FREE_CPU_COUNT_REG_VALUE_NAME, &count))
count = 0;
return count;
@@ -2260,13 +2219,13 @@ int LoadNonSysInPlaceEncSettings (WipeAlgorithmId *wipeAlgorithm) void RemoveNonSysInPlaceEncNotifications (void)
{
if (FileExists (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC)))
- remove (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC));
+ _wremove (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC));
if (FileExists (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE)))
- remove (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE));
+ _wremove (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE));
if (!IsNonInstallMode () && SystemEncryptionStatus == SYSENC_STATUS_NONE)
- ManageStartupSeqWiz (TRUE, "");
+ ManageStartupSeqWiz (TRUE, L"");
}
@@ -2280,16 +2239,16 @@ void SavePostInstallTasksSettings (int command) switch (command)
{
case TC_POST_INSTALL_CFG_REMOVE_ALL:
- remove (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_TUTORIAL));
- remove (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_RELEASE_NOTES));
+ _wremove (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_TUTORIAL));
+ _wremove (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_RELEASE_NOTES));
break;
case TC_POST_INSTALL_CFG_TUTORIAL:
- f = fopen (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_TUTORIAL), "w");
+ f = _wfopen (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_TUTORIAL), L"w");
break;
case TC_POST_INSTALL_CFG_RELEASE_NOTES:
- f = fopen (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_RELEASE_NOTES), "w");
+ f = _wfopen (GetConfigPath (TC_APPD_FILENAME_POST_INSTALL_TASK_RELEASE_NOTES), L"w");
break;
default:
@@ -2299,7 +2258,7 @@ void SavePostInstallTasksSettings (int command) if (f == NULL)
return;
- if (fputs ("1", f) < 0)
+ if (fputws (L"1", f) < 0)
{
// Error
fclose (f);
@@ -2357,7 +2316,7 @@ void InitOSVersionInfo () OSVERSIONINFOEX osEx;
osEx.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
- GetVersionEx ((LPOSVERSIONINFOA) &osEx);
+ GetVersionEx ((LPOSVERSIONINFOW) &osEx);
if (osEx.wProductType == VER_NT_SERVER || osEx.wProductType == VER_NT_DOMAIN_CONTROLLER)
nCurrentOS = WIN_SERVER_2003;
@@ -2369,7 +2328,7 @@ void InitOSVersionInfo () OSVERSIONINFOEX osEx;
osEx.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
- GetVersionEx ((LPOSVERSIONINFOA) &osEx);
+ GetVersionEx ((LPOSVERSIONINFOW) &osEx);
if (osEx.wProductType == VER_NT_SERVER || osEx.wProductType == VER_NT_DOMAIN_CONTROLLER)
nCurrentOS = WIN_SERVER_2008;
@@ -2395,11 +2354,11 @@ void InitOSVersionInfo () /* InitApp - initialize the application, this function is called once in the
applications WinMain function, but before the main dialog has been created */
-void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
+void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)
{
WNDCLASSW wc;
char langId[6];
- char dllPath[MAX_PATH];
+ wchar_t dllPath[MAX_PATH];
/* Save the instance handle for later */
hInst = hInstance;
@@ -2412,7 +2371,7 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine) #ifndef SETUP
// Application ID
typedef HRESULT (WINAPI *SetAppId_t) (PCWSTR appID);
- SetAppId_t setAppId = (SetAppId_t) GetProcAddress (GetModuleHandle ("shell32.dll"), "SetCurrentProcessExplicitAppUserModelID");
+ SetAppId_t setAppId = (SetAppId_t) GetProcAddress (GetModuleHandle (L"shell32.dll"), "SetCurrentProcessExplicitAppUserModelID");
if (setAppId)
setAppId (TC_APPLICATION_ID);
@@ -2446,11 +2405,11 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine) // A new instance of the application must be created with elevated privileges.
if (IsNonInstallMode () && !IsAdmin () && IsUacSupported ())
{
- char modPath[MAX_PATH], newCmdLine[4096];
+ wchar_t modPath[MAX_PATH], newCmdLine[4096];
WNDCLASSEXW wcex;
HWND hWnd;
- if (strstr (lpszCommandLine, "/q UAC ") == lpszCommandLine)
+ if (wcsstr (lpszCommandLine, L"/q UAC ") == lpszCommandLine)
{
Error ("UAC_INIT_ERROR", NULL);
exit (1);
@@ -2473,12 +2432,12 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine) SetLayeredWindowAttributes (hWnd, 0, 0, LWA_ALPHA);
ShowWindow (hWnd, SW_SHOWNORMAL);
- GetModuleFileName (NULL, modPath, sizeof (modPath));
+ GetModuleFileNameW (NULL, modPath, ARRAYSIZE (modPath));
- StringCbCopyA (newCmdLine, sizeof(newCmdLine), "/q UAC ");
- StringCbCatA (newCmdLine, sizeof (newCmdLine), lpszCommandLine);
+ StringCbCopyW (newCmdLine, sizeof(newCmdLine), L"/q UAC ");
+ StringCbCatW (newCmdLine, sizeof (newCmdLine), lpszCommandLine);
- if ((int)ShellExecute (hWnd, "runas", modPath, newCmdLine, NULL, SW_SHOWNORMAL) <= 32)
+ if ((int)ShellExecuteW (hWnd, L"runas", modPath, newCmdLine, NULL, SW_SHOWNORMAL) <= 32)
exit (1);
Sleep (2000);
@@ -2503,7 +2462,7 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine) // Service pack check & warnings about critical MS issues
osEx.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
- if (GetVersionEx ((LPOSVERSIONINFOA) &osEx) != 0)
+ if (GetVersionEx ((LPOSVERSIONINFOW) &osEx) != 0)
{
CurrentOSServicePack = osEx.wServicePackMajor;
switch (nCurrentOS)
@@ -2516,9 +2475,9 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine) DWORD val = 0, size = sizeof(val);
HKEY hkey;
- if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\Atapi\\Parameters", 0, KEY_READ, &hkey) == ERROR_SUCCESS)
+ if (RegOpenKeyExW (HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\Atapi\\Parameters", 0, KEY_READ, &hkey) == ERROR_SUCCESS)
{
- if (RegQueryValueEx (hkey, "EnableBigLba", 0, 0, (LPBYTE) &val, &size) != ERROR_SUCCESS
+ if (RegQueryValueExW (hkey, L"EnableBigLba", 0, 0, (LPBYTE) &val, &size) != ERROR_SUCCESS
|| val != 1)
{
Warning ("LARGE_IDE_WARNING_2K_REGISTRY", NULL);
@@ -2533,7 +2492,7 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine) {
HKEY k;
// PE environment does not report version of SP
- if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Control\\minint", 0, KEY_READ, &k) != ERROR_SUCCESS)
+ if (RegOpenKeyExW (HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Control\\minint", 0, KEY_READ, &k) != ERROR_SUCCESS)
Warning ("LARGE_IDE_WARNING_XP", NULL);
else
RegCloseKey (k);
@@ -2581,9 +2540,9 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine) }
if (GetSystemDirectory(dllPath, MAX_PATH))
- StringCbCatA(dllPath, sizeof(dllPath), "\\Riched20.dll");
+ StringCbCatW(dllPath, sizeof(dllPath), L"\\Riched20.dll");
else
- StringCbCopyA(dllPath, sizeof(dllPath), "c:\\Windows\\System32\\Riched20.dll");
+ StringCbCopyW(dllPath, sizeof(dllPath), L"c:\\Windows\\System32\\Riched20.dll");
// Required for RichEdit text fields to work
if ((hRichEditDll = LoadLibrary(dllPath)) == NULL)
{
@@ -2623,13 +2582,13 @@ void FinalizeApp (void) void InitHelpFileName (void)
{
- char *lpszTmp;
+ wchar_t *lpszTmp;
- GetModuleFileName (NULL, szHelpFile, sizeof (szHelpFile));
- lpszTmp = strrchr (szHelpFile, '\\');
+ GetModuleFileNameW (NULL, szHelpFile, ARRAYSIZE (szHelpFile));
+ lpszTmp = wcsrchr (szHelpFile, L'\\');
if (lpszTmp)
{
- char szTemp[TC_MAX_PATH];
+ wchar_t szTemp[TC_MAX_PATH];
++lpszTmp;
*lpszTmp = 0; // add null terminating character to prepare for append operations
@@ -2638,34 +2597,33 @@ void InitHelpFileName (void) if (strcmp (GetPreferredLangId(), "en") == 0
|| strlen(GetPreferredLangId()) == 0)
{
- StringCbCatA (szHelpFile, sizeof(szHelpFile), "VeraCrypt User Guide.pdf");
+ StringCbCatW (szHelpFile, sizeof(szHelpFile), L"VeraCrypt User Guide.pdf");
}
else
{
- StringCbPrintfA (szTemp, sizeof(szTemp), "VeraCrypt User Guide.%s.pdf", GetPreferredLangId());
- StringCbCatA (szHelpFile, sizeof(szHelpFile), szTemp);
+ StringCbPrintfW (szTemp, sizeof(szTemp), L"VeraCrypt User Guide.%S.pdf", GetPreferredLangId());
+ StringCbCatW (szHelpFile, sizeof(szHelpFile), szTemp);
}
// Secondary file name (used when localized documentation is not found).
- GetModuleFileName (NULL, szHelpFile2, sizeof (szHelpFile2));
- lpszTmp = strrchr (szHelpFile2, '\\');
+ GetModuleFileNameW (NULL, szHelpFile2, ARRAYSIZE (szHelpFile2));
+ lpszTmp = wcsrchr (szHelpFile2, L'\\');
if (lpszTmp)
{
++lpszTmp;
*lpszTmp = 0;
- StringCbCatA (szHelpFile2, sizeof(szHelpFile2), "VeraCrypt User Guide.pdf");
+ StringCbCatW (szHelpFile2, sizeof(szHelpFile2), L"VeraCrypt User Guide.pdf");
}
}
}
-BOOL OpenDevice (const char *lpszPath, OPEN_TEST_STRUCT *driver, BOOL detectFilesystem)
+BOOL OpenDevice (const wchar_t *lpszPath, OPEN_TEST_STRUCT *driver, BOOL detectFilesystem)
{
DWORD dwResult;
BOOL bResult;
wchar_t wszFileName[TC_MAX_PATH];
- StringCbCopyA ((char *) &wszFileName[0], sizeof(wszFileName), lpszPath);
- ToUNICODE ((char *) &wszFileName[0], sizeof(wszFileName));
+ StringCbCopyW (wszFileName, sizeof(wszFileName), lpszPath);
memset (driver, 0, sizeof (OPEN_TEST_STRUCT));
memcpy (driver->wszFileName, wszFileName, sizeof (wszFileName));
@@ -2743,13 +2701,13 @@ executions complete very fast. Returns TRUE if successful (otherwise FALSE). */ BOOL GetSysDevicePaths (HWND hwndDlg)
{
if (!bCachedSysDevicePathsValid
- || strlen (SysPartitionDevicePath) <= 1
- || strlen (SysDriveDevicePath) <= 1)
+ || wcslen (SysPartitionDevicePath) <= 1
+ || wcslen (SysDriveDevicePath) <= 1)
{
foreach (const HostDevice &device, GetAvailableHostDevices (false, true))
{
if (device.ContainsSystem)
- strcpy_s (device.IsPartition ? SysPartitionDevicePath : SysDriveDevicePath, TC_MAX_PATH, device.Path.c_str());
+ StringCchCopyW (device.IsPartition ? SysPartitionDevicePath : SysDriveDevicePath, TC_MAX_PATH, device.Path.c_str());
}
if (IsOSAtLeast (WIN_7))
@@ -2777,8 +2735,8 @@ BOOL GetSysDevicePaths (HWND hwndDlg) }
return (bCachedSysDevicePathsValid
- && strlen (SysPartitionDevicePath) > 1
- && strlen (SysDriveDevicePath) > 1);
+ && wcslen (SysPartitionDevicePath) > 1
+ && wcslen (SysDriveDevicePath) > 1);
}
/* Determines whether the device path is the path of the system partition or of the system drive (or neither).
@@ -2800,7 +2758,7 @@ Return codes: 3 - it is the extra boot partition path
0 - it's not the system partition/drive path
-1 - the result can't be determined, isn't reliable, or there was an error. */
-int IsSystemDevicePath (const char *path, HWND hwndDlg, BOOL bReliableRequired)
+int IsSystemDevicePath (const wchar_t *path, HWND hwndDlg, BOOL bReliableRequired)
{
if (!bCachedSysDevicePathsValid
&& bReliableRequired)
@@ -2809,15 +2767,15 @@ int IsSystemDevicePath (const char *path, HWND hwndDlg, BOOL bReliableRequired) return -1;
}
- if (strlen (SysPartitionDevicePath) <= 1 || strlen (SysDriveDevicePath) <= 1)
+ if (wcslen (SysPartitionDevicePath) <= 1 || wcslen (SysDriveDevicePath) <= 1)
return -1;
if (!path)
return -1;
- if (strncmp (path, SysPartitionDevicePath, max (strlen(path), strlen(SysPartitionDevicePath))) == 0)
+ if (wcsncmp (path, SysPartitionDevicePath, max (wcslen(path), wcslen(SysPartitionDevicePath))) == 0)
return 1;
- else if (strncmp (path, SysDriveDevicePath, max (strlen(path), strlen(SysDriveDevicePath))) == 0)
+ else if (wcsncmp (path, SysDriveDevicePath, max (wcslen(path), wcslen(SysDriveDevicePath))) == 0)
return 2;
else if (ExtraBootPartitionDevicePath == path)
return 3;
@@ -2833,42 +2791,43 @@ Return codes: 0 - it isn't a non-system partition on the system drive
1 - it's a non-system partition on the system drive
-1 - the result can't be determined, isn't reliable, or there was an error. */
-int IsNonSysPartitionOnSysDrive (const char *path)
+int IsNonSysPartitionOnSysDrive (const wchar_t *path)
{
- char tmpPath [TC_MAX_PATH + 1];
+ wchar_t tmpPath [TC_MAX_PATH + 1];
int pos;
if (!GetSysDevicePaths (MainDlg))
return -1;
- if (strlen (SysPartitionDevicePath) <= 1 || strlen (SysDriveDevicePath) <= 1)
+ if (wcslen (SysPartitionDevicePath) <= 1 || wcslen (SysDriveDevicePath) <= 1)
return -1;
- if (strncmp (path, SysPartitionDevicePath, max (strlen(path), strlen(SysPartitionDevicePath))) == 0
- || strncmp (path, SysDriveDevicePath, max (strlen(path), strlen(SysDriveDevicePath))) == 0)
+ if (wcsncmp (path, SysPartitionDevicePath, max (wcslen(path), wcslen(SysPartitionDevicePath))) == 0
+ || wcsncmp (path, SysDriveDevicePath, max (wcslen(path), wcslen(SysDriveDevicePath))) == 0)
{
// It is the system partition/drive path (it isn't a non-system partition)
return 0;
}
memset (tmpPath, 0, sizeof (tmpPath));
- strncpy (tmpPath, path, sizeof (tmpPath) - 1);
+ wcsncpy (tmpPath, path, ARRAYSIZE (tmpPath) - 1);
- pos = (int) FindString (tmpPath, "Partition", (int) strlen (tmpPath), (int) strlen ("Partition"), 0);
+ pos = (int) FindString ((const char*) tmpPath, (const char*) L"Partition", (int) wcslen (tmpPath) * 2, (int) wcslen (L"Partition") * 2, 0);
if (pos < 0)
return -1;
+ pos /= 2;
pos += (int) strlen ("Partition");
- if (pos + 1 > sizeof (tmpPath) - 1)
+ if (pos + 1 > ARRAYSIZE (tmpPath) - 1)
return -1;
- tmpPath [pos] = '0';
+ tmpPath [pos] = L'0';
tmpPath [pos + 1] = 0;
- if (strncmp (tmpPath, SysDriveDevicePath, max (strlen(tmpPath), strlen(SysDriveDevicePath))) == 0)
+ if (wcsncmp (tmpPath, SysDriveDevicePath, max (wcslen(tmpPath), wcslen(SysDriveDevicePath))) == 0)
{
// It is a non-system partition on the system drive
return 1;
@@ -3004,19 +2963,19 @@ BOOL CALLBACK TextInfoDialogBoxDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, L switch (nID)
{
case TC_TBXID_SYS_ENCRYPTION_PRETEST:
- PrintHardCopyTextUTF16 ((wchar_t *) GetSysEncryptionPretestInfo2String ().c_str(), "Pre-Boot Troubleshooting", GetSysEncryptionPretestInfo2String ().length () * 2);
+ PrintHardCopyTextUTF16 ((wchar_t *) GetSysEncryptionPretestInfo2String ().c_str(), L"Pre-Boot Troubleshooting", GetSysEncryptionPretestInfo2String ().length () * 2);
break;
case TC_TBXID_SYS_ENC_RESCUE_DISK:
- PrintHardCopyTextUTF16 ((wchar_t *) GetRescueDiskHelpString ().c_str(), "VeraCrypt Rescue Disk Help", GetRescueDiskHelpString ().length () * 2);
+ PrintHardCopyTextUTF16 ((wchar_t *) GetRescueDiskHelpString ().c_str(), L"VeraCrypt Rescue Disk Help", GetRescueDiskHelpString ().length () * 2);
break;
case TC_TBXID_DECOY_OS_INSTRUCTIONS:
- PrintHardCopyTextUTF16 ((wchar_t *) GetDecoyOsInstructionsString ().c_str(), "How to Create Decoy OS", GetDecoyOsInstructionsString ().length () * 2);
+ PrintHardCopyTextUTF16 ((wchar_t *) GetDecoyOsInstructionsString ().c_str(), L"How to Create Decoy OS", GetDecoyOsInstructionsString ().length () * 2);
break;
case TC_TBXID_EXTRA_BOOT_PARTITION_REMOVAL_INSTRUCTIONS:
- PrintHardCopyTextUTF16 (GetString ("EXTRA_BOOT_PARTITION_REMOVAL_INSTRUCTIONS"), "How to Remove Extra Boot Partition", wcslen (GetString ("EXTRA_BOOT_PARTITION_REMOVAL_INSTRUCTIONS")) * 2);
+ PrintHardCopyTextUTF16 (GetString ("EXTRA_BOOT_PARTITION_REMOVAL_INSTRUCTIONS"), L"How to Remove Extra Boot Partition", wcslen (GetString ("EXTRA_BOOT_PARTITION_REMOVAL_INSTRUCTIONS")) * 2);
break;
}
return 1;
@@ -3035,7 +2994,7 @@ BOOL CALLBACK TextInfoDialogBoxDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, L r = GetLegalNotices ();
if (r != NULL)
{
- SetWindowText (GetDlgItem (hwndDlg, IDC_INFO_BOX_TEXT), r);
+ SetWindowTextA (GetDlgItem (hwndDlg, IDC_INFO_BOX_TEXT), r);
free (r);
}
break;
@@ -3080,7 +3039,7 @@ char * GetLegalNotices () char *buf = NULL;
if (resource == NULL)
- resource = (char *) MapResource ("Text", IDR_LICENSE, &size);
+ resource = (char *) MapResource (L"Text", IDR_LICENSE, &size);
if (resource != NULL)
{
@@ -3098,7 +3057,7 @@ char * GetLegalNotices () BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- static char *lpszFileName; // This is actually a pointer to a GLOBAL array
+ static wchar_t *lpszFileName; // This is actually a pointer to a GLOBAL array
static vector <HostDevice> devices;
static map <int, HostDevice> itemToDeviceMap;
@@ -3171,9 +3130,9 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l if (device.ContainsSystem)
{
if (device.IsPartition)
- strcpy_s (SysPartitionDevicePath, sizeof (SysPartitionDevicePath), device.Path.c_str());
+ StringCbCopyW (SysPartitionDevicePath, sizeof (SysPartitionDevicePath), device.Path.c_str());
else
- strcpy_s (SysDriveDevicePath, sizeof (SysDriveDevicePath), device.Path.c_str());
+ StringCbCopyW (SysDriveDevicePath, sizeof (SysDriveDevicePath), device.Path.c_str());
}
// Path
@@ -3184,13 +3143,13 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l if (line > 1)
{
- ListItemAdd (hList, item.iItem, "");
+ ListItemAdd (hList, item.iItem, L"");
item.iItem = line++;
}
if (device.Floppy || device.DynamicVolume)
{
- ListItemAdd (hList, item.iItem, (char *) device.Path.c_str());
+ ListItemAdd (hList, item.iItem, (wchar_t *) device.Path.c_str());
}
else
{
@@ -3203,12 +3162,12 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l if (!device.Partitions.empty())
StringCbCatW (s, sizeof(s), L":");
- ListItemAddW (hList, item.iItem, s);
+ ListItemAdd (hList, item.iItem, s);
}
}
else
{
- ListItemAdd (hList, item.iItem, (char *) device.Path.c_str());
+ ListItemAdd (hList, item.iItem, (wchar_t *) device.Path.c_str());
}
itemToDeviceMap[item.iItem] = device;
@@ -3218,23 +3177,23 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l {
wchar_t size[100] = { 0 };
GetSizeString (device.Size, size, sizeof(size));
- ListSubItemSetW (hList, item.iItem, 2, size);
+ ListSubItemSet (hList, item.iItem, 2, size);
}
// Mount point
if (!device.MountPoint.empty())
- ListSubItemSet (hList, item.iItem, 1, (char *) device.MountPoint.c_str());
+ ListSubItemSet (hList, item.iItem, 1, (wchar_t *) device.MountPoint.c_str());
// Label
if (!device.Name.empty())
- ListSubItemSetW (hList, item.iItem, 3, (wchar_t *) device.Name.c_str());
+ ListSubItemSet (hList, item.iItem, 3, (wchar_t *) device.Name.c_str());
#ifdef TCMOUNT
else
{
bool useInExplorer = false;
wstring favoriteLabel = GetFavoriteVolumeLabel (device.Path, useInExplorer);
if (!favoriteLabel.empty())
- ListSubItemSetW (hList, item.iItem, 3, (wchar_t *) favoriteLabel.c_str());
+ ListSubItemSet (hList, item.iItem, 3, (wchar_t *) favoriteLabel.c_str());
}
#endif
@@ -3298,7 +3257,7 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l return 1; // non-device line selected
const HostDevice selectedDevice = itemToDeviceMap[selectedItem];
- strcpy_s (lpszFileName, TC_MAX_PATH, selectedDevice.Path.c_str());
+ StringCchCopyW (lpszFileName, TC_MAX_PATH, selectedDevice.Path.c_str());
#ifdef VOLFORMAT
if (selectedDevice.ContainsSystem && selectedDevice.IsPartition)
@@ -3470,9 +3429,9 @@ BOOL DoDriverInstall (HWND hwndDlg) StatusMessage (hwndDlg, "INSTALLING_DRIVER");
#endif
- hService = CreateService (hManager, "veracrypt", "veracrypt",
+ hService = CreateService (hManager, L"veracrypt", L"veracrypt",
SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_SYSTEM_START, SERVICE_ERROR_NORMAL,
- "System32\\drivers\\veracrypt.sys",
+ L"System32\\drivers\\veracrypt.sys",
NULL, NULL, NULL, NULL, NULL);
if (hService == NULL)
@@ -3480,7 +3439,7 @@ BOOL DoDriverInstall (HWND hwndDlg) else
CloseServiceHandle (hService);
- hService = OpenService (hManager, "veracrypt", SERVICE_ALL_ACCESS);
+ hService = OpenService (hManager, L"veracrypt", SERVICE_ALL_ACCESS);
if (hService == NULL)
goto error;
@@ -3519,25 +3478,25 @@ static int DriverLoad () HANDLE file;
WIN32_FIND_DATA find;
SC_HANDLE hManager, hService = NULL;
- char driverPath[TC_MAX_PATH*2];
+ wchar_t driverPath[TC_MAX_PATH*2];
BOOL res;
- char *tmp;
+ wchar_t *tmp;
DWORD startType;
- if (ReadLocalMachineRegistryDword ("SYSTEM\\CurrentControlSet\\Services\\veracrypt", "Start", &startType) && startType == SERVICE_BOOT_START)
+ if (ReadLocalMachineRegistryDword (L"SYSTEM\\CurrentControlSet\\Services\\veracrypt", L"Start", &startType) && startType == SERVICE_BOOT_START)
return ERR_PARAMETER_INCORRECT;
- GetModuleFileName (NULL, driverPath, sizeof (driverPath));
- tmp = strrchr (driverPath, '\\');
+ GetModuleFileName (NULL, driverPath, ARRAYSIZE (driverPath));
+ tmp = wcsrchr (driverPath, L'\\');
if (!tmp)
{
- driverPath[0] = '.';
+ driverPath[0] = L'.';
driverPath[1] = 0;
}
else
*tmp = 0;
- StringCbCatA (driverPath, sizeof(driverPath), !Is64BitOs () ? "\\veracrypt.sys" : "\\veracrypt-x64.sys");
+ StringCbCatW (driverPath, sizeof(driverPath), !Is64BitOs () ? L"\\veracrypt.sys" : L"\\veracrypt-x64.sys");
file = FindFirstFile (driverPath, &find);
@@ -3561,7 +3520,7 @@ static int DriverLoad () return ERR_OS_ERROR;
}
- hService = OpenService (hManager, "veracrypt", SERVICE_ALL_ACCESS);
+ hService = OpenService (hManager, L"veracrypt", SERVICE_ALL_ACCESS);
if (hService != NULL)
{
// Remove stale service (driver is not loaded but service exists)
@@ -3570,7 +3529,7 @@ static int DriverLoad () Sleep (500);
}
- hService = CreateService (hManager, "veracrypt", "veracrypt",
+ hService = CreateService (hManager, L"veracrypt", L"veracrypt",
SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
driverPath, NULL, NULL, NULL, NULL, NULL);
@@ -3647,7 +3606,7 @@ BOOL DriverUnload () if (hManager == NULL)
goto error;
- hService = OpenService (hManager, "veracrypt", SERVICE_ALL_ACCESS);
+ hService = OpenService (hManager, L"veracrypt", SERVICE_ALL_ACCESS);
if (hService == NULL)
goto error;
@@ -3821,30 +3780,29 @@ load: void ResetCurrentDirectory ()
{
- char p[MAX_PATH];
+ wchar_t p[MAX_PATH];
if (!IsNonInstallMode () && SHGetFolderPath (NULL, CSIDL_PROFILE, NULL, 0, p) == ERROR_SUCCESS)
{
SetCurrentDirectory (p);
}
else
{
- GetModPath (p, sizeof (p));
+ GetModPath (p, ARRAYSIZE (p));
SetCurrentDirectory (p);
}
}
-BOOL BrowseFiles (HWND hwndDlg, char *stringId, char *lpszFileName, BOOL keepHistory, BOOL saveMode, wchar_t *browseFilter)
+BOOL BrowseFiles (HWND hwndDlg, char *stringId, wchar_t *lpszFileName, BOOL keepHistory, BOOL saveMode, wchar_t *browseFilter)
{
return BrowseFilesInDir (hwndDlg, stringId, NULL, lpszFileName, keepHistory, saveMode, browseFilter);
}
-BOOL BrowseFilesInDir (HWND hwndDlg, char *stringId, char *initialDir, char *lpszFileName, BOOL keepHistory, BOOL saveMode, wchar_t *browseFilter, const wchar_t *initialFileName, const wchar_t *defaultExtension)
+BOOL BrowseFilesInDir (HWND hwndDlg, char *stringId, wchar_t *initialDir, wchar_t *lpszFileName, BOOL keepHistory, BOOL saveMode, wchar_t *browseFilter, const wchar_t *initialFileName, const wchar_t *defaultExtension)
{
OPENFILENAMEW ofn;
wchar_t file[TC_MAX_PATH] = { 0 };
- wchar_t wInitialDir[TC_MAX_PATH] = { 0 };
wchar_t filter[1024];
BOOL status = FALSE;
@@ -3855,12 +3813,11 @@ BOOL BrowseFilesInDir (HWND hwndDlg, char *stringId, char *initialDir, char *lps if (initialDir)
{
- swprintf_s (wInitialDir, sizeof (wInitialDir) / 2, L"%hs", initialDir);
- ofn.lpstrInitialDir = wInitialDir;
+ ofn.lpstrInitialDir = initialDir;
}
if (initialFileName)
- wcscpy_s (file, array_capacity (file), initialFileName);
+ StringCchCopyW (file, array_capacity (file), initialFileName);
ofn.lStructSize = sizeof (ofn);
ofn.hwndOwner = hwndDlg;
@@ -3897,7 +3854,7 @@ BOOL BrowseFilesInDir (HWND hwndDlg, char *stringId, char *initialDir, char *lps SystemFileSelectorCallPending = FALSE;
- WideCharToMultiByte (CP_ACP, 0, file, -1, lpszFileName, MAX_PATH, NULL, NULL);
+ StringCchCopyW (lpszFileName, MAX_PATH, file);
if (!keepHistory)
CleanLastVisitedMRU ();
@@ -3913,13 +3870,12 @@ ret: }
-static char SelectMultipleFilesPath[131072];
+static wchar_t SelectMultipleFilesPath[131072];
static int SelectMultipleFilesOffset;
-BOOL SelectMultipleFiles (HWND hwndDlg, const char *stringId, char *lpszFileName, size_t cbFileName,BOOL keepHistory)
+BOOL SelectMultipleFiles (HWND hwndDlg, const char *stringId, wchar_t *lpszFileName, size_t cbFileName,BOOL keepHistory)
{
OPENFILENAMEW ofn;
- wchar_t file[0xffff * 2] = { 0 }; // The size must not exceed 0xffff*2 due to a bug in Windows 2000 and XP SP1
wchar_t filter[1024];
BOOL status = FALSE;
@@ -3934,8 +3890,8 @@ BOOL SelectMultipleFiles (HWND hwndDlg, const char *stringId, char *lpszFileName GetString ("ALL_FILES"), 0, 0, GetString ("TC_VOLUMES"), 0, 0, 0);
ofn.lpstrFilter = filter;
ofn.nFilterIndex = 1;
- ofn.lpstrFile = file;
- ofn.nMaxFile = sizeof (file) / sizeof (file[0]);
+ ofn.lpstrFile = SelectMultipleFilesPath;
+ ofn.nMaxFile = 0xffff * 2; // The size must not exceed 0xffff*2 due to a bug in Windows 2000 and XP SP1
ofn.lpstrTitle = GetString (stringId);
ofn.Flags = OFN_HIDEREADONLY
| OFN_EXPLORER
@@ -3954,24 +3910,15 @@ BOOL SelectMultipleFiles (HWND hwndDlg, const char *stringId, char *lpszFileName SystemFileSelectorCallPending = FALSE;
- if (file[ofn.nFileOffset - 1] != 0)
+ if (SelectMultipleFilesPath[ofn.nFileOffset - 1] != 0)
{
// Single file selected
- WideCharToMultiByte (CP_ACP, 0, file, -1, lpszFileName, MAX_PATH, NULL, NULL);
+ StringCbCopyW (lpszFileName, cbFileName, SelectMultipleFilesPath);
SelectMultipleFilesOffset = 0;
}
else
{
// Multiple files selected
- int n;
- wchar_t *f = file;
- char *s = SelectMultipleFilesPath;
- while ((n = WideCharToMultiByte (CP_ACP, 0, f, -1, s, MAX_PATH, NULL, NULL)) > 1)
- {
- f += n;
- s += n;
- }
-
SelectMultipleFilesOffset = ofn.nFileOffset;
SelectMultipleFilesNext (lpszFileName, cbFileName);
}
@@ -3990,20 +3937,20 @@ ret: }
-BOOL SelectMultipleFilesNext (char *lpszFileName, size_t cbFileName)
+BOOL SelectMultipleFilesNext (wchar_t *lpszFileName, size_t cbFileName)
{
if (SelectMultipleFilesOffset == 0)
return FALSE;
- StringCbCopyA (lpszFileName, cbFileName,SelectMultipleFilesPath);
+ StringCbCopyW (lpszFileName, cbFileName,SelectMultipleFilesPath);
lpszFileName[TC_MAX_PATH - 1] = 0;
- if (lpszFileName[strlen (lpszFileName) - 1] != '\\')
- StringCbCatA (lpszFileName, cbFileName,"\\");
+ if (lpszFileName[wcslen (lpszFileName) - 1] != L'\\')
+ StringCbCatW (lpszFileName, cbFileName,L"\\");
- StringCbCatA (lpszFileName, cbFileName,SelectMultipleFilesPath + SelectMultipleFilesOffset);
+ StringCbCatW (lpszFileName, cbFileName,SelectMultipleFilesPath + SelectMultipleFilesOffset);
- SelectMultipleFilesOffset += (int) strlen (SelectMultipleFilesPath + SelectMultipleFilesOffset) + 1;
+ SelectMultipleFilesOffset += (int) wcslen (SelectMultipleFilesPath + SelectMultipleFilesOffset) + 1;
if (SelectMultipleFilesPath[SelectMultipleFilesOffset] == 0)
SelectMultipleFilesOffset = 0;
@@ -4018,13 +3965,13 @@ static int CALLBACK BrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lp, LPARAM pDa {
/* WParam is TRUE since we are passing a path.
It would be FALSE if we were passing a pidl. */
- SendMessage (hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)pData);
+ SendMessageW (hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)pData);
break;
}
case BFFM_SELCHANGED:
{
- char szDir[TC_MAX_PATH];
+ wchar_t szDir[TC_MAX_PATH];
/* Set the status window to the currently selected path. */
if (SHGetPathFromIDList((LPITEMIDLIST) lp ,szDir))
@@ -4042,7 +3989,7 @@ static int CALLBACK BrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lp, LPARAM pDa }
-BOOL BrowseDirectories (HWND hwndDlg, char *lpszTitle, char *dirName)
+BOOL BrowseDirectories (HWND hwndDlg, char *lpszTitle, wchar_t *dirName)
{
BROWSEINFOW bi;
LPITEMIDLIST pidl;
@@ -4090,8 +4037,8 @@ std::wstring GetWrongPasswordErrorMessage (HWND hwndDlg) StringCbCatW (szTmp, sizeof(szTmp), GetString ("PASSWORD_WRONG_CAPSLOCK_ON"));
#ifdef TCMOUNT
- char szDevicePath [TC_MAX_PATH+1] = {0};
- GetWindowText (GetDlgItem (MainDlg, IDC_VOLUME), szDevicePath, sizeof (szDevicePath));
+ wchar_t szDevicePath [TC_MAX_PATH+1] = {0};
+ GetWindowText (GetDlgItem (MainDlg, IDC_VOLUME), szDevicePath, ARRAYSIZE (szDevicePath));
if (TCBootLoaderOnInactiveSysEncDrive (szDevicePath))
{
@@ -4241,7 +4188,7 @@ void handleError (HWND hwndDlg, int code, const char* srcPos) }
-BOOL CheckFileStreamWriteErrors (HWND hwndDlg, FILE *file, const char *fileName)
+BOOL CheckFileStreamWriteErrors (HWND hwndDlg, FILE *file, const wchar_t *fileName)
{
if (ferror (file))
{
@@ -4300,15 +4247,15 @@ void LocalizeDialog (HWND hwnd, char *stringId) void OpenVolumeExplorerWindow (int driveNo)
{
- char dosName[5];
+ wchar_t dosName[5];
SHFILEINFO fInfo;
- StringCbPrintfA (dosName, sizeof(dosName), "%c:\\", (char) driveNo + 'A');
+ StringCbPrintfW (dosName, sizeof(dosName), L"%c:\\", (wchar_t) driveNo + L'A');
// Force explorer to discover the drive
SHGetFileInfo (dosName, 0, &fInfo, sizeof (fInfo), 0);
- ShellExecute (NULL, "open", dosName, NULL, NULL, SW_SHOWNORMAL);
+ ShellExecute (NULL, L"open", dosName, NULL, NULL, SW_SHOWNORMAL);
}
static BOOL explorerCloseSent;
@@ -4417,16 +4364,16 @@ BOOL UpdateDriveCustomLabel (int driveNo, wchar_t* effectiveLabel, BOOL bSetValu return (ERROR_SUCCESS == lStatus)? TRUE : FALSE;
}
-string GetUserFriendlyVersionString (int version)
+wstring GetUserFriendlyVersionString (int version)
{
- char szTmp [64];
- StringCbPrintfA (szTmp, sizeof(szTmp), "%x", version);
+ wchar_t szTmp [64];
+ StringCbPrintfW (szTmp, sizeof(szTmp), L"%x", version);
- string versionString (szTmp);
+ wstring versionString (szTmp);
- versionString.insert (version > 0xfff ? 2 : 1,".");
+ versionString.insert (version > 0xfff ? 2 : 1,L".");
- if (versionString[versionString.length()-1] == '0')
+ if (versionString[versionString.length()-1] == L'0')
versionString.erase (versionString.length()-1, 1);
return (versionString);
@@ -4808,7 +4755,7 @@ static BOOL PerformBenchmark(HWND hBenchDlg, HWND hwndDlg) benchmarkTable[benchmarkTotalItems].encSpeed = performanceCountEnd.QuadPart - performanceCountStart.QuadPart;
benchmarkTable[benchmarkTotalItems].id = thid;
- StringCbPrintfA (benchmarkTable[benchmarkTotalItems].name, sizeof(benchmarkTable[benchmarkTable[benchmarkTotalItems].name),"%s", get_pkcs5_prf_name (thid));
+ StringCbPrintfW (benchmarkTable[benchmarkTotalItems].name, sizeof(benchmarkTable[benchmarkTable[benchmarkTotalItems].name),L"%s", get_pkcs5_prf_name (thid));
benchmarkTotalItems++;
}
@@ -5113,7 +5060,7 @@ static BOOL CALLBACK RandomPoolEnrichementDlgProc (HWND hwndDlg, UINT msg, WPARA WORD hw = HIWORD (wParam);
static unsigned char randPool [RNG_POOL_SIZE];
static unsigned char lastRandPool [RNG_POOL_SIZE];
- static char outputDispBuffer [RNG_POOL_SIZE * 3 + RANDPOOL_DISPLAY_ROWS + 2];
+ static wchar_t outputDispBuffer [RNG_POOL_SIZE * 3 + RANDPOOL_DISPLAY_ROWS + 2];
static BOOL bDisplayPoolContents = TRUE;
static BOOL bRandPoolDispAscii = FALSE;
int hash_algo = RandGetHashFunction();
@@ -5135,7 +5082,7 @@ static BOOL CALLBACK RandomPoolEnrichementDlgProc (HWND hwndDlg, UINT msg, WPARA for (hid = FIRST_PRF_ID; hid <= LAST_PRF_ID; hid++)
{
if (!HashIsDeprecated (hid))
- AddComboPair (hComboBox, HashGetName(hid), hid);
+ AddComboPairW (hComboBox, HashGetName(hid), hid);
}
SelectAlgo (hComboBox, &hash_algo);
@@ -5148,7 +5095,7 @@ static BOOL CALLBACK RandomPoolEnrichementDlgProc (HWND hwndDlg, UINT msg, WPARA case WM_TIMER:
{
- char tmp[4];
+ wchar_t tmp[4];
unsigned char tmpByte;
int col, row;
@@ -5166,10 +5113,10 @@ static BOOL CALLBACK RandomPoolEnrichementDlgProc (HWND hwndDlg, UINT msg, WPARA {
tmpByte = randPool[row * RANDPOOL_DISPLAY_COLUMNS + col];
- StringCbPrintfA (tmp, sizeof(tmp), bRandPoolDispAscii ? ((tmpByte >= 32 && tmpByte < 255 && tmpByte != '&') ? " %c " : " . ") : "%02X ", tmpByte);
- StringCbCatA (outputDispBuffer, sizeof(outputDispBuffer), tmp);
+ StringCbPrintfW (tmp, sizeof(tmp), bRandPoolDispAscii ? ((tmpByte >= 32 && tmpByte < 255 && tmpByte != L'&') ? L" %c " : L" . ") : L"%02X ", tmpByte);
+ StringCbCatW (outputDispBuffer, sizeof(outputDispBuffer), tmp);
}
- StringCbCatA (outputDispBuffer, sizeof(outputDispBuffer), "\n");
+ StringCbCatW (outputDispBuffer, sizeof(outputDispBuffer), L"\n");
}
SetWindowText (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), outputDispBuffer);
@@ -5200,9 +5147,9 @@ static BOOL CALLBACK RandomPoolEnrichementDlgProc (HWND hwndDlg, UINT msg, WPARA {
if (!(bDisplayPoolContents = GetCheckBox (hwndDlg, IDC_DISPLAY_POOL_CONTENTS)))
{
- char tmp[RNG_POOL_SIZE+1];
+ wchar_t tmp[RNG_POOL_SIZE+1];
- memset (tmp, ' ', sizeof(tmp));
+ wmemset (tmp, L' ', ARRAYSIZE(tmp));
tmp [RNG_POOL_SIZE] = 0;
SetWindowText (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), tmp);
}
@@ -5214,7 +5161,7 @@ static BOOL CALLBACK RandomPoolEnrichementDlgProc (HWND hwndDlg, UINT msg, WPARA case WM_CLOSE:
{
- char tmp[RNG_POOL_SIZE+1];
+ wchar_t tmp[RNG_POOL_SIZE+1];
exit:
KillTimer (hwndDlg, 0xfd);
@@ -5223,7 +5170,7 @@ exit: burn (outputDispBuffer, sizeof(outputDispBuffer));
// Attempt to wipe the pool contents in the GUI text area
- memset (tmp, ' ', RNG_POOL_SIZE);
+ wmemset (tmp, L' ', RNG_POOL_SIZE);
tmp [RNG_POOL_SIZE] = 0;
SetWindowText (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), tmp);
@@ -5261,7 +5208,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP WORD hw = HIWORD (wParam);
static unsigned char randPool [RNG_POOL_SIZE];
static unsigned char lastRandPool [RNG_POOL_SIZE];
- static char outputDispBuffer [RNG_POOL_SIZE * 3 + RANDPOOL_DISPLAY_ROWS + 2];
+ static wchar_t outputDispBuffer [RNG_POOL_SIZE * 3 + RANDPOOL_DISPLAY_ROWS + 2];
static BOOL bDisplayPoolContents = TRUE;
static BOOL bRandPoolDispAscii = FALSE;
int hash_algo = RandGetHashFunction();
@@ -5283,7 +5230,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP for (hid = FIRST_PRF_ID; hid <= LAST_PRF_ID; hid++)
{
if (!HashIsDeprecated (hid))
- AddComboPair (hComboBox, HashGetName(hid), hid);
+ AddComboPairW (hComboBox, HashGetName(hid), hid);
}
SelectAlgo (hComboBox, &hash_algo);
@@ -5300,10 +5247,10 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP SendMessage (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), WM_SETFONT, (WPARAM) hFixedDigitFont, (LPARAM) TRUE);
// 9-digit limit for the number of keyfiles (more than enough!)
SendMessage (GetDlgItem (hwndDlg, IDC_NUMBER_KEYFILES), EM_SETLIMITTEXT, (WPARAM) 9, 0);
- SetWindowText(GetDlgItem (hwndDlg, IDC_NUMBER_KEYFILES), "1");
+ SetWindowText(GetDlgItem (hwndDlg, IDC_NUMBER_KEYFILES), L"1");
// maximum keyfile size is 1048576, so limit the edit control to 7 characters
SendMessage (GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE), EM_SETLIMITTEXT, (WPARAM) 7, 0);
- SetWindowText(GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE), "64");
+ SetWindowText(GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE), L"64");
// set the maximum length of the keyfile base name to (TC_MAX_PATH - 1)
SendMessage (GetDlgItem (hwndDlg, IDC_KEYFILES_BASE_NAME), EM_SETLIMITTEXT, (WPARAM) (TC_MAX_PATH - 1), 0);
return 1;
@@ -5311,7 +5258,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP case WM_TIMER:
{
- char tmp[4];
+ wchar_t tmp[4];
unsigned char tmpByte;
int col, row;
@@ -5329,10 +5276,10 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP {
tmpByte = randPool[row * RANDPOOL_DISPLAY_COLUMNS + col];
- StringCbPrintfA (tmp, sizeof(tmp), bRandPoolDispAscii ? ((tmpByte >= 32 && tmpByte < 255 && tmpByte != '&') ? " %c " : " . ") : "%02X ", tmpByte);
- StringCbCatA (outputDispBuffer, sizeof(outputDispBuffer), tmp);
+ StringCbPrintfW (tmp, sizeof(tmp), bRandPoolDispAscii ? ((tmpByte >= 32 && tmpByte < 255 && tmpByte != L'&') ? L" %c " : L" . ") : L"%02X ", tmpByte);
+ StringCbCatW (outputDispBuffer, sizeof(outputDispBuffer), tmp);
}
- StringCbCatA (outputDispBuffer, sizeof(outputDispBuffer), "\n");
+ StringCbCatW (outputDispBuffer, sizeof(outputDispBuffer), L"\n");
}
SetWindowText (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), outputDispBuffer);
@@ -5361,9 +5308,9 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP {
if (!(bDisplayPoolContents = GetCheckBox (hwndDlg, IDC_DISPLAY_POOL_CONTENTS)))
{
- char tmp[RNG_POOL_SIZE+1];
+ wchar_t tmp[RNG_POOL_SIZE+1];
- memset (tmp, ' ', sizeof(tmp));
+ wmemset (tmp, L' ', ARRAYSIZE(tmp));
tmp [RNG_POOL_SIZE] = 0;
SetWindowText (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), tmp);
}
@@ -5377,21 +5324,21 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP if (lw == IDC_GENERATE_AND_SAVE_KEYFILE)
{
- char szNumber[16] = {0};
- char szFileBaseName[TC_MAX_PATH];
- char szDirName[TC_MAX_PATH];
- char szFileName [2*TC_MAX_PATH + 16];
+ wchar_t szNumber[16] = {0};
+ wchar_t szFileBaseName[TC_MAX_PATH];
+ wchar_t szDirName[TC_MAX_PATH];
+ wchar_t szFileName [2*TC_MAX_PATH + 16];
unsigned char *keyfile = NULL;
int fhKeyfile = -1, status;
long keyfilesCount = 0, keyfilesSize = 0, i;
- char* fileExtensionPtr = 0;
- char szSuffix[32];
+ wchar_t* fileExtensionPtr = 0;
+ wchar_t szSuffix[32];
BOOL bRandomSize = GetCheckBox (hwndDlg, IDC_KEYFILES_RANDOM_SIZE);
- if (!GetWindowText(GetDlgItem (hwndDlg, IDC_NUMBER_KEYFILES), szNumber, sizeof(szNumber)))
+ if (!GetWindowText(GetDlgItem (hwndDlg, IDC_NUMBER_KEYFILES), szNumber, ARRAYSIZE(szNumber)))
szNumber[0] = 0;
- keyfilesCount = strtoul(szNumber, NULL, 0);
+ keyfilesCount = wcstoul(szNumber, NULL, 0);
if (keyfilesCount <= 0 || keyfilesCount == LONG_MAX)
{
Warning("KEYFILE_INCORRECT_NUMBER", hwndDlg);
@@ -5401,10 +5348,10 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP if (!bRandomSize)
{
- if (!GetWindowText(GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE), szNumber, sizeof(szNumber)))
+ if (!GetWindowText(GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE), szNumber, ARRAYSIZE(szNumber)))
szNumber[0] = 0;
- keyfilesSize = strtoul(szNumber, NULL, 0);
+ keyfilesSize = wcstoul(szNumber, NULL, 0);
if (keyfilesSize < 64 || keyfilesSize > 1024*1024)
{
Warning("KEYFILE_INCORRECT_SIZE", hwndDlg);
@@ -5431,14 +5378,14 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP return 1;
}
- fileExtensionPtr = strrchr(szFileBaseName, '.');
+ fileExtensionPtr = wcsrchr(szFileBaseName, L'.');
/* Select directory */
if (!BrowseDirectories (hwndDlg, "SELECT_KEYFILE_GENERATION_DIRECTORY", szDirName))
return 1;
- if (szDirName[strlen(szDirName) - 1] != '\\' && szDirName[strlen(szDirName) - 1] != '/')
- StringCbCat(szDirName, sizeof(szDirName), "\\");
+ if (szDirName[wcslen(szDirName) - 1] != L'\\' && szDirName[wcslen(szDirName) - 1] != L'/')
+ StringCbCat(szDirName, sizeof(szDirName), L"\\");
WaitCursor();
@@ -5446,15 +5393,15 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP for (i= 0; i < keyfilesCount; i++)
{
- StringCbCopy(szFileName, sizeof(szFileName), szDirName);
+ StringCbCopyW(szFileName, sizeof(szFileName), szDirName);
if (i > 0)
{
- StringCbPrintfA(szSuffix, sizeof(szSuffix), "_%d", i);
+ StringCbPrintfW(szSuffix, sizeof(szSuffix), L"_%d", i);
// Append the counter to the name
if (fileExtensionPtr)
{
- StringCbCatN(szFileName, sizeof(szFileName), szFileBaseName, (size_t) (fileExtensionPtr - szFileBaseName));
+ StringCchCatN(szFileName, ARRAYSIZE(szFileName), szFileBaseName, (size_t) (fileExtensionPtr - szFileBaseName));
StringCbCat(szFileName, sizeof(szFileName), szSuffix);
StringCbCat(szFileName, sizeof(szFileName), fileExtensionPtr);
}
@@ -5468,16 +5415,13 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP StringCbCat(szFileName, sizeof(szFileName), szFileBaseName);
// check if the file exists
- if ((fhKeyfile = _open(szFileName, _O_RDONLY|_O_BINARY, _S_IREAD|_S_IWRITE)) != -1)
+ if ((fhKeyfile = _wopen(szFileName, _O_RDONLY|_O_BINARY, _S_IREAD|_S_IWRITE)) != -1)
{
WCHAR s[4*TC_MAX_PATH] = {0};
- WCHAR wszFileName[3*TC_MAX_PATH] = {0};
_close (fhKeyfile);
- MultiByteToWideChar(CP_ACP, 0, szFileName, -1, wszFileName, sizeof(wszFileName) / sizeof(WCHAR));
-
- StringCbPrintfW (s, sizeof(s), GetString ("KEYFILE_ALREADY_EXISTS"), wszFileName);
+ StringCbPrintfW (s, sizeof(s), GetString ("KEYFILE_ALREADY_EXISTS"), szFileName);
status = AskWarnNoYesString (s, hwndDlg);
if (status == IDNO)
{
@@ -5488,7 +5432,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP }
/* Conceive the file */
- if ((fhKeyfile = _open(szFileName, _O_CREAT|_O_TRUNC|_O_WRONLY|_O_BINARY, _S_IREAD|_S_IWRITE)) == -1)
+ if ((fhKeyfile = _wopen(szFileName, _O_CREAT|_O_TRUNC|_O_WRONLY|_O_BINARY, _S_IREAD|_S_IWRITE)) == -1)
{
TCfree(keyfile);
NormalCursor();
@@ -5550,7 +5494,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP case WM_CLOSE:
{
- char tmp[RNG_POOL_SIZE+1];
+ wchar_t tmp[RNG_POOL_SIZE+1];
exit:
WaitCursor();
KillTimer (hwndDlg, 0xfd);
@@ -5565,7 +5509,7 @@ exit: burn (outputDispBuffer, sizeof(outputDispBuffer));
// Attempt to wipe the pool contents in the GUI text area
- memset (tmp, ' ', RNG_POOL_SIZE);
+ wmemset (tmp, L' ', RNG_POOL_SIZE);
tmp [RNG_POOL_SIZE] = 0;
SetWindowText (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), tmp);
@@ -5597,7 +5541,7 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_INITDIALOG:
{
int ea;
- char buf[100];
+ wchar_t buf[100];
LocalizeDialog (hwndDlg, "IDD_CIPHER_TEST_DLG");
@@ -5627,7 +5571,7 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) for (ea = EAGetFirst (); ea != 0; ea = EAGetNext (ea))
{
if (EAGetCipherCount (ea) == 1 && EAIsFormatEnabled (ea))
- AddComboPair (GetDlgItem (hwndDlg, IDC_CIPHER), EAGetName (buf, ea, 1), EAGetFirstCipher (ea));
+ AddComboPairW (GetDlgItem (hwndDlg, IDC_CIPHER), EAGetName (buf, ea, 1), EAGetFirstCipher (ea));
}
ResetCipherTest(hwndDlg, idTestCipher);
@@ -5695,7 +5639,8 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) if (lw == IDOK || lw == IDC_ENCRYPT || lw == IDC_DECRYPT)
{
- char key[128+1], inputtext[128+1], secondaryKey[64+1], dataUnitNo[16+1], szTmp[128+1];
+ char key[128+1], inputtext[128+1], secondaryKey[64+1], dataUnitNo[16+1];
+ wchar_t szTmp[128+1];
int ks, pt, n, tlen, blockNo = 0;
BOOL bEncrypt;
@@ -5710,7 +5655,7 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) memset(key,0,sizeof(key));
memset(szTmp,0,sizeof(szTmp));
- n = GetWindowText(GetDlgItem(hwndDlg, IDC_KEY), szTmp, sizeof(szTmp));
+ n = GetWindowText(GetDlgItem(hwndDlg, IDC_KEY), szTmp, ARRAYSIZE(szTmp));
if (n != ks * 2)
{
Warning ("TEST_KEY_SIZE", hwndDlg);
@@ -5719,14 +5664,14 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) for (n = 0; n < ks; n ++)
{
- char szTmp2[3], *ptr;
+ wchar_t szTmp2[3], *ptr;
long x;
szTmp2[2] = 0;
szTmp2[0] = szTmp[n * 2];
szTmp2[1] = szTmp[n * 2 + 1];
- x = strtol(szTmp2, &ptr, 16);
+ x = wcstol(szTmp2, &ptr, 16);
key[n] = (char) x;
}
@@ -5738,11 +5683,11 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) if (bEncrypt)
{
- n = GetWindowText(GetDlgItem(hwndDlg, IDC_PLAINTEXT), szTmp, sizeof(szTmp));
+ n = GetWindowText(GetDlgItem(hwndDlg, IDC_PLAINTEXT), szTmp, ARRAYSIZE(szTmp));
}
else
{
- n = GetWindowText(GetDlgItem(hwndDlg, IDC_CIPHERTEXT), szTmp, sizeof(szTmp));
+ n = GetWindowText(GetDlgItem(hwndDlg, IDC_CIPHERTEXT), szTmp, ARRAYSIZE(szTmp));
}
if (n != pt * 2)
@@ -5761,14 +5706,14 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) for (n = 0; n < pt; n ++)
{
- char szTmp2[3], *ptr;
+ wchar_t szTmp2[3], *ptr;
long x;
szTmp2[2] = 0;
szTmp2[0] = szTmp[n * 2];
szTmp2[1] = szTmp[n * 2 + 1];
- x = strtol(szTmp2, &ptr, 16);
+ x = wcstol(szTmp2, &ptr, 16);
inputtext[n] = (char) x;
}
@@ -5778,7 +5723,7 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
// Secondary key
- if (GetWindowText(GetDlgItem(hwndDlg, IDC_SECONDARY_KEY), szTmp, sizeof(szTmp)) != 64)
+ if (GetWindowText(GetDlgItem(hwndDlg, IDC_SECONDARY_KEY), szTmp, ARRAYSIZE(szTmp)) != 64)
{
Warning ("TEST_INCORRECT_SECONDARY_KEY_SIZE", hwndDlg);
return 1;
@@ -5786,21 +5731,21 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) for (n = 0; n < 64; n ++)
{
- char szTmp2[3], *ptr;
+ wchar_t szTmp2[3], *ptr;
long x;
szTmp2[2] = 0;
szTmp2[0] = szTmp[n * 2];
szTmp2[1] = szTmp[n * 2 + 1];
- x = strtol(szTmp2, &ptr, 16);
+ x = wcstol(szTmp2, &ptr, 16);
secondaryKey[n] = (char) x;
}
// Data unit number
- tlen = GetWindowText(GetDlgItem(hwndDlg, IDC_TEST_DATA_UNIT_NUMBER), szTmp, sizeof(szTmp));
+ tlen = GetWindowText(GetDlgItem(hwndDlg, IDC_TEST_DATA_UNIT_NUMBER), szTmp, ARRAYSIZE(szTmp));
if (tlen > 16 || tlen < 1)
{
@@ -5808,18 +5753,18 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) return 1;
}
- LeftPadString (szTmp, tlen, 16, '0');
+ LeftPadString (szTmp, tlen, 16, L'0');
for (n = 0; n < 16; n ++)
{
- char szTmp2[3], *ptr;
+ wchar_t szTmp2[3], *ptr;
long x;
szTmp2[2] = 0;
szTmp2[0] = szTmp[n * 2];
szTmp2[1] = szTmp[n * 2 + 1];
- x = strtol(szTmp2, &ptr, 16);
+ x = wcstol(szTmp2, &ptr, 16);
dataUnitNo[n] = (char) x;
}
@@ -5898,9 +5843,9 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) for (n = 0; n < pt; n ++)
{
- char szTmp2[3];
- StringCbPrintfA(szTmp2, sizeof(szTmp2), "%02x", (int)((unsigned char)tmp[n]));
- StringCbCatA(szTmp, sizeof(szTmp), szTmp2);
+ wchar_t szTmp2[3];
+ StringCbPrintfW(szTmp2, sizeof(szTmp2), L"%02x", (int)((unsigned char)tmp[n]));
+ StringCbCatW(szTmp, sizeof(szTmp), szTmp2);
}
if (bEncrypt)
@@ -5961,26 +5906,26 @@ ResetCipherTest(HWND hwndDlg, int idTestCipher) SendMessage(GetDlgItem(hwndDlg, IDC_TEST_BLOCK_NUMBER), CB_SETCURSEL, 0, 0);
- SetWindowText(GetDlgItem(hwndDlg, IDC_SECONDARY_KEY), "0000000000000000000000000000000000000000000000000000000000000000");
- SetWindowText(GetDlgItem(hwndDlg, IDC_TEST_DATA_UNIT_NUMBER), "0");
+ SetWindowText(GetDlgItem(hwndDlg, IDC_SECONDARY_KEY), L"0000000000000000000000000000000000000000000000000000000000000000");
+ SetWindowText(GetDlgItem(hwndDlg, IDC_TEST_DATA_UNIT_NUMBER), L"0");
- SetWindowText(GetDlgItem(hwndDlg, IDC_PLAINTEXT), "0000000000000000");
- SetWindowText(GetDlgItem(hwndDlg, IDC_CIPHERTEXT), "0000000000000000");
+ SetWindowText(GetDlgItem(hwndDlg, IDC_PLAINTEXT), L"0000000000000000");
+ SetWindowText(GetDlgItem(hwndDlg, IDC_CIPHERTEXT), L"0000000000000000");
if (idTestCipher == AES || idTestCipher == SERPENT || idTestCipher == TWOFISH)
{
- ndx = (int) SendMessage (GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_ADDSTRING, 0,(LPARAM) "256");
+ ndx = (int) SendMessage (GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_ADDSTRING, 0,(LPARAM) L"256");
SendMessage(GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_SETITEMDATA, ndx,(LPARAM) 32);
SendMessage(GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_SETCURSEL, ndx,0);
SendMessage (GetDlgItem(hwndDlg, IDC_PLAINTEXT_SIZE), CB_RESETCONTENT, 0,0);
- ndx = (int) SendMessage (GetDlgItem(hwndDlg, IDC_PLAINTEXT_SIZE), CB_ADDSTRING, 0,(LPARAM) "128");
+ ndx = (int) SendMessage (GetDlgItem(hwndDlg, IDC_PLAINTEXT_SIZE), CB_ADDSTRING, 0,(LPARAM) L"128");
SendMessage(GetDlgItem(hwndDlg, IDC_PLAINTEXT_SIZE), CB_SETITEMDATA, ndx,(LPARAM) 16);
SendMessage(GetDlgItem(hwndDlg, IDC_PLAINTEXT_SIZE), CB_SETCURSEL, ndx,0);
- SetWindowText(GetDlgItem(hwndDlg, IDC_KEY), "0000000000000000000000000000000000000000000000000000000000000000");
- SetWindowText(GetDlgItem(hwndDlg, IDC_PLAINTEXT), "00000000000000000000000000000000");
- SetWindowText(GetDlgItem(hwndDlg, IDC_CIPHERTEXT), "00000000000000000000000000000000");
+ SetWindowText(GetDlgItem(hwndDlg, IDC_KEY), L"0000000000000000000000000000000000000000000000000000000000000000");
+ SetWindowText(GetDlgItem(hwndDlg, IDC_PLAINTEXT), L"00000000000000000000000000000000");
+ SetWindowText(GetDlgItem(hwndDlg, IDC_CIPHERTEXT), L"00000000000000000000000000000000");
}
}
@@ -6228,48 +6173,48 @@ BOOL CheckCapsLock (HWND hwnd, BOOL quiet) // Checks whether the file extension is not used for executable files or similarly problematic, which often
// causes Windows and antivirus software to interfere with the container.
-BOOL CheckFileExtension (char *fileName)
+BOOL CheckFileExtension (wchar_t *fileName)
{
int i = 0;
- char *ext = strrchr (fileName, '.');
- static char *problemFileExt[] = {
+ wchar_t *ext = wcsrchr (fileName, L'.');
+ static wchar_t *problemFileExt[] = {
// These are protected by the Windows Resource Protection
- ".asa", ".asp", ".aspx", ".ax", ".bas", ".bat", ".bin", ".cer", ".chm", ".clb", ".cmd", ".cnt", ".cnv",
- ".com", ".cpl", ".cpx", ".crt", ".csh", ".dll", ".drv", ".dtd", ".exe", ".fxp", ".grp", ".h1s", ".hlp",
- ".hta", ".ime", ".inf", ".ins", ".isp", ".its", ".js", ".jse", ".ksh", ".lnk", ".mad", ".maf", ".mag",
- ".mam", ".man", ".maq", ".mar", ".mas", ".mat", ".mau", ".mav", ".maw", ".mda", ".mdb", ".mde", ".mdt",
- ".mdw", ".mdz", ".msc", ".msi", ".msp", ".mst", ".mui", ".nls", ".ocx", ".ops", ".pal", ".pcd", ".pif",
- ".prf", ".prg", ".pst", ".reg", ".scf", ".scr", ".sct", ".shb", ".shs", ".sys", ".tlb", ".tsp", ".url",
- ".vb", ".vbe", ".vbs", ".vsmacros", ".vss", ".vst", ".vsw", ".ws", ".wsc", ".wsf", ".wsh", ".xsd", ".xsl",
+ L".asa", L".asp", L".aspx", L".ax", L".bas", L".bat", L".bin", L".cer", L".chm", L".clb", L".cmd", L".cnt", L".cnv",
+ L".com", L".cpl", L".cpx", L".crt", L".csh", L".dll", L".drv", L".dtd", L".exe", L".fxp", L".grp", L".h1s", L".hlp",
+ L".hta", L".ime", L".inf", L".ins", L".isp", L".its", L".js", L".jse", L".ksh", L".lnk", L".mad", L".maf", L".mag",
+ L".mam", L".man", L".maq", L".mar", L".mas", L".mat", L".mau", L".mav", L".maw", L".mda", L".mdb", L".mde", L".mdt",
+ L".mdw", L".mdz", L".msc", L".msi", L".msp", L".mst", L".mui", L".nls", L".ocx", L".ops", L".pal", L".pcd", L".pif",
+ L".prf", L".prg", L".pst", L".reg", L".scf", L".scr", L".sct", L".shb", L".shs", L".sys", L".tlb", L".tsp", L".url",
+ L".vb", L".vbe", L".vbs", L".vsmacros", L".vss", L".vst", L".vsw", L".ws", L".wsc", L".wsf", L".wsh", L".xsd", L".xsl",
// These additional file extensions are usually watched by antivirus programs
- ".386", ".acm", ".ade", ".adp", ".ani", ".app", ".asd", ".asf", ".asx", ".awx", ".ax", ".boo", ".bz2", ".cdf",
- ".class", ".dhtm", ".dhtml",".dlo", ".emf", ".eml", ".flt", ".fot", ".gz", ".hlp", ".htm", ".html", ".ini",
- ".j2k", ".jar", ".jff", ".jif", ".jmh", ".jng", ".jp2", ".jpe", ".jpeg", ".jpg", ".lsp", ".mod", ".nws",
- ".obj", ".olb", ".osd", ".ov1", ".ov2", ".ov3", ".ovl", ".ovl", ".ovr", ".pdr", ".pgm", ".php", ".pkg",
- ".pl", ".png", ".pot", ".pps", ".ppt", ".ps1", ".ps1xml", ".psc1", ".rar", ".rpl", ".rtf", ".sbf", ".script", ".sh", ".sha", ".shtm",
- ".shtml", ".spl", ".swf", ".tar", ".tgz", ".tmp", ".ttf", ".vcs", ".vlm", ".vxd", ".vxo", ".wiz", ".wll", ".wmd",
- ".wmf", ".wms", ".wmz", ".wpc", ".wsc", ".wsh", ".wwk", ".xhtm", ".xhtml", ".xl", ".xml", ".zip", ".7z", 0};
+ L".386", L".acm", L".ade", L".adp", L".ani", L".app", L".asd", L".asf", L".asx", L".awx", L".ax", L".boo", L".bz2", L".cdf",
+ L".class", L".dhtm", L".dhtml",L".dlo", L".emf", L".eml", L".flt", L".fot", L".gz", L".hlp", L".htm", L".html", L".ini",
+ L".j2k", L".jar", L".jff", L".jif", L".jmh", L".jng", L".jp2", L".jpe", L".jpeg", L".jpg", L".lsp", L".mod", L".nws",
+ L".obj", L".olb", L".osd", L".ov1", L".ov2", L".ov3", L".ovl", L".ovl", L".ovr", L".pdr", L".pgm", L".php", L".pkg",
+ L".pl", L".png", L".pot", L".pps", L".ppt", L".ps1", L".ps1xml", L".psc1", L".rar", L".rpl", L".rtf", L".sbf", L".script", L".sh", L".sha", L".shtm",
+ L".shtml", L".spl", L".swf", L".tar", L".tgz", L".tmp", L".ttf", L".vcs", L".vlm", L".vxd", L".vxo", L".wiz", L".wll", L".wmd",
+ L".wmf", L".wms", L".wmz", L".wpc", L".wsc", L".wsh", L".wwk", L".xhtm", L".xhtml", L".xl", L".xml", L".zip", L".7z", 0};
if (!ext)
return FALSE;
while (problemFileExt[i])
{
- if (!_stricmp (ext, problemFileExt[i++]))
+ if (!_wcsicmp (ext, problemFileExt[i++]))
return TRUE;
}
return FALSE;
}
-void CorrectFileName (char* fileName)
+void CorrectFileName (wchar_t* fileName)
{
/* replace '/' by '\' */
- size_t i, len = strlen (fileName);
+ size_t i, len = wcslen (fileName);
for (i = 0; i < len; i++)
{
- if (fileName [i] == '/')
- fileName [i] = '\\';
+ if (fileName [i] == L'/')
+ fileName [i] = L'\\';
}
}
@@ -6327,7 +6272,7 @@ BOOL IsDriveAvailable (int driveNo) }
-BOOL IsDeviceMounted (char *deviceName)
+BOOL IsDeviceMounted (wchar_t *deviceName)
{
BOOL bResult = FALSE;
DWORD dwResult;
@@ -6392,7 +6337,7 @@ int DriverUnmountVolume (HWND hwndDlg, int nDosDriveNo, BOOL forced) wchar_t msg[4096];
VolumeNotificationsList.bHidVolDamagePrevReported [nDosDriveNo] = TRUE;
- StringCbPrintfW (msg, sizeof(msg), GetString ("DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"), nDosDriveNo + 'A');
+ StringCbPrintfW (msg, sizeof(msg), GetString ("DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"), nDosDriveNo + L'A');
SetForegroundWindow (hwndDlg);
MessageBoxW (hwndDlg, msg, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
}
@@ -6429,21 +6374,10 @@ void BroadcastDeviceChange (WPARAM message, int nDosDriveNo, DWORD driveMap) {
if (driveMap & (1 << i))
{
- char root[] = { (char) i + 'A', ':', '\\', 0 };
+ wchar_t root[] = { (wchar_t) i + L'A', L':', L'\\', 0 };
SHChangeNotify (eventId, SHCNF_PATH, root, NULL);
- if (nCurrentOS == WIN_2000 && RemoteSession)
- {
- char target[32];
- StringCbPrintfA (target, sizeof(target), "%ls%c", TC_MOUNT_PREFIX, i + 'A');
- root[2] = 0;
-
- if (message == DBT_DEVICEARRIVAL)
- DefineDosDevice (DDD_RAW_TARGET_PATH, root, target);
- else if (message == DBT_DEVICEREMOVECOMPLETE)
- DefineDosDevice (DDD_RAW_TARGET_PATH| DDD_REMOVE_DEFINITION
- | DDD_EXACT_MATCH_ON_REMOVE, root, target);
- }
+
}
}
}
@@ -6516,7 +6450,7 @@ BOOL GetPhysicalDriveAlignment(UINT nDriveNumber, STORAGE_ACCESS_ALIGNMENT_DESCR // implementation of the generic wait dialog mechanism
-static UINT g_wmWaitDlg = ::RegisterWindowMessage("VeraCryptWaitDlgMessage");
+static UINT g_wmWaitDlg = ::RegisterWindowMessage(L"VeraCryptWaitDlgMessage");
typedef struct
{
@@ -6700,7 +6634,7 @@ void CALLBACK MountWaitThreadProc(void* pArg, HWND ) int MountVolume (HWND hwndDlg,
int driveNo,
- char *volumePath,
+ wchar_t *volumePath,
Password *password,
int pkcs5,
int pim,
@@ -6714,7 +6648,7 @@ int MountVolume (HWND hwndDlg, MOUNT_STRUCT mount;
DWORD dwResult, dwLastError = ERROR_SUCCESS;
BOOL bResult, bDevice;
- char root[MAX_PATH];
+ wchar_t root[MAX_PATH];
int favoriteMountOnArrivalRetryCount = 0;
#ifdef TCMOUNT
@@ -6785,33 +6719,33 @@ retry: if (CurrentOSMajor == 5 && CurrentOSMinor == 0)
mount.bMountManager = FALSE;
- string path = volumePath;
- if (path.find ("\\\\?\\") == 0)
+ wstring path = volumePath;
+ if (path.find (L"\\\\?\\") == 0)
{
// Remove \\?\ prefix
path = path.substr (4);
- strcpy_s (volumePath, TC_MAX_PATH, path.c_str());
+ StringCchCopyW (volumePath, TC_MAX_PATH, path.c_str());
}
- if (path.find ("Volume{") == 0 && path.rfind ("}\\") == path.size() - 2)
+ if (path.find (L"Volume{") == 0 && path.rfind (L"}\\") == path.size() - 2)
{
- string resolvedPath = VolumeGuidPathToDevicePath (path);
+ wstring resolvedPath = VolumeGuidPathToDevicePath (path);
if (!resolvedPath.empty())
- strcpy_s (volumePath, TC_MAX_PATH, resolvedPath.c_str());
+ StringCchCopyW (volumePath, TC_MAX_PATH, resolvedPath.c_str());
}
- CreateFullVolumePath ((char *) mount.wszVolume, sizeof(mount.wszVolume), volumePath, &bDevice);
+ CreateFullVolumePath (mount.wszVolume, sizeof(mount.wszVolume), volumePath, &bDevice);
if (!bDevice)
{
// UNC path
- if (path.find ("\\\\") == 0)
+ if (path.find (L"\\\\") == 0)
{
- strcpy_s ((char *)mount.wszVolume, array_capacity (mount.wszVolume), ("UNC" + path.substr (1)).c_str());
+ StringCbCopyW (mount.wszVolume, sizeof (mount.wszVolume), (L"UNC" + path.substr (1)).c_str());
}
- if (GetVolumePathName (volumePath, root, sizeof (root) - 1))
+ if (GetVolumePathName (volumePath, root, ARRAYSIZE (root) - 1))
{
DWORD bps, flags, d;
if (GetDiskFreeSpace (root, &d, &bps, &d, &d))
@@ -6822,12 +6756,12 @@ retry: if (IsOSAtLeast (WIN_VISTA))
{
- if ( (strlen(root) >= 2)
- && (root[1] == ':')
- && (toupper(root[0]) >= 'A' && toupper(root[0]) <= 'Z')
+ if ( (wcslen(root) >= 2)
+ && (root[1] == L':')
+ && (towupper(root[0]) >= L'A' && towupper(root[0]) <= L'Z')
)
{
- string drivePath = "\\\\.\\X:";
+ wstring drivePath = L"\\\\.\\X:";
HANDLE dev = INVALID_HANDLE_VALUE;
VOLUME_DISK_EXTENTS extents = {0};
DWORD dwResult = 0;
@@ -6858,8 +6792,6 @@ retry: }
}
- ToUNICODE ((char *) mount.wszVolume, sizeof(mount.wszVolume));
-
if (mountOptions->PartitionInInactiveSysEncScope)
{
if (mount.wszVolume == NULL || swscanf_s ((const wchar_t *) mount.wszVolume,
@@ -6965,7 +6897,7 @@ retry: {
int driveNo;
- if (sscanf (volumePath, "\\Device\\Harddisk%d\\Partition", &driveNo) == 1)
+ if (swscanf (volumePath, L"\\Device\\Harddisk%d\\Partition", &driveNo) == 1)
{
OPEN_TEST_STRUCT openTestStruct;
memset (&openTestStruct, 0, sizeof (openTestStruct));
@@ -7040,7 +6972,7 @@ retry: if (mount.VolumeMountedReadOnlyAfterDeviceWriteProtected
&& !Silent
- && strstr (volumePath, "\\Device\\Harddisk") == volumePath)
+ && wcsstr (volumePath, L"\\Device\\Harddisk") == volumePath)
{
wchar_t msg[1024];
wchar_t mountPoint[] = { L'A' + (wchar_t) driveNo, L':', 0 };
@@ -7049,7 +6981,7 @@ retry: WarningDirect (msg, hwndDlg);
if (CurrentOSMajor >= 6
- && strstr (volumePath, "\\Device\\HarddiskVolume") != volumePath
+ && wcsstr (volumePath, L"\\Device\\HarddiskVolume") != volumePath
&& AskNoYes ("ASK_REMOVE_DEVICE_WRITE_PROTECTION", hwndDlg) == IDYES)
{
RemoveDeviceWriteProtection (hwndDlg, volumePath);
@@ -7143,7 +7075,7 @@ retry: if (IsOSAtLeast (WIN_7))
{
// Undo SHCNE_DRIVEREMOVED
- char root[] = { (char) nDosDriveNo + 'A', ':', '\\', 0 };
+ wchar_t root[] = { (wchar_t) nDosDriveNo + L'A', L':', L'\\', 0 };
SHChangeNotify (SHCNE_DRIVEADD, SHCNF_PATH, root, NULL);
}
@@ -7178,23 +7110,21 @@ BOOL IsPasswordCacheEmpty (void) }
-BOOL IsMountedVolume (const char *volname)
+BOOL IsMountedVolume (const wchar_t *volname)
{
MOUNT_LIST_STRUCT mlist;
DWORD dwResult;
int i;
- char volume[TC_MAX_PATH*2+16];
+ wchar_t volume[TC_MAX_PATH*2+16];
- StringCbCopyA (volume, sizeof(volume), volname);
+ StringCbCopyW (volume, sizeof(volume), volname);
- if (strstr (volname, "\\Device\\") != volname)
- StringCbPrintfA(volume, sizeof(volume), "\\??\\%s", volname);
+ if (wcsstr (volname, L"\\Device\\") != volname)
+ StringCbPrintfW(volume, sizeof(volume), L"\\??\\%s", volname);
- string resolvedPath = VolumeGuidPathToDevicePath (volname);
+ wstring resolvedPath = VolumeGuidPathToDevicePath (volname);
if (!resolvedPath.empty())
- StringCbCopyA (volume, sizeof (volume), resolvedPath.c_str());
-
- ToUNICODE (volume, sizeof(volume));
+ StringCbCopyW (volume, sizeof (volume), resolvedPath.c_str());
memset (&mlist, 0, sizeof (mlist));
DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, &mlist,
@@ -7202,33 +7132,31 @@ BOOL IsMountedVolume (const char *volname) NULL);
for (i=0 ; i<26; i++)
- if (0 == _wcsicmp ((wchar_t *) mlist.wszVolume[i], (WCHAR *)volume))
+ if (0 == _wcsicmp ((wchar_t *) mlist.wszVolume[i], volume))
return TRUE;
return FALSE;
}
-int GetMountedVolumeDriveNo (char *volname)
+int GetMountedVolumeDriveNo (wchar_t *volname)
{
MOUNT_LIST_STRUCT mlist;
DWORD dwResult;
int i;
- char volume[TC_MAX_PATH*2+16];
+ wchar_t volume[TC_MAX_PATH*2+16];
if (volname == NULL)
return -1;
- StringCbCopyA (volume, sizeof(volume), volname);
+ StringCbCopyW (volume, sizeof(volume), volname);
- if (strstr (volname, "\\Device\\") != volname)
- StringCbPrintfA (volume, sizeof(volume), "\\??\\%s", volname);
+ if (wcsstr (volname, L"\\Device\\") != volname)
+ StringCbPrintfW (volume, sizeof(volume), L"\\??\\%s", volname);
- string resolvedPath = VolumeGuidPathToDevicePath (volname);
+ wstring resolvedPath = VolumeGuidPathToDevicePath (volname);
if (!resolvedPath.empty())
- StringCbCopyA (volume, sizeof (volume), resolvedPath.c_str());
-
- ToUNICODE (volume, sizeof(volume));
+ StringCbCopyW (volume, sizeof (volume), resolvedPath.c_str());
memset (&mlist, 0, sizeof (mlist));
DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, &mlist,
@@ -7283,9 +7211,9 @@ BOOL IsUacSupported () if (!IsOSAtLeast (WIN_VISTA))
return FALSE;
- if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_READ, &hkey) == ERROR_SUCCESS)
+ if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_READ, &hkey) == ERROR_SUCCESS)
{
- if (RegQueryValueEx (hkey, "EnableLUA", 0, 0, (LPBYTE) &value, &size) != ERROR_SUCCESS)
+ if (RegQueryValueEx (hkey, L"EnableLUA", 0, 0, (LPBYTE) &value, &size) != ERROR_SUCCESS)
value = 1;
RegCloseKey (hkey);
@@ -7314,14 +7242,14 @@ BOOL ResolveSymbolicLink (const wchar_t *symLinkName, PWSTR targetName, size_t c }
-BOOL GetPartitionInfo (const char *deviceName, PPARTITION_INFORMATION rpartInfo)
+BOOL GetPartitionInfo (const wchar_t *deviceName, PPARTITION_INFORMATION rpartInfo)
{
BOOL bResult;
DWORD dwResult;
DISK_PARTITION_INFO_STRUCT dpi;
memset (&dpi, 0, sizeof(dpi));
- StringCbPrintfW ((PWSTR) &dpi.deviceName, sizeof(dpi.deviceName), L"%hs", deviceName);
+ StringCbCopyW ((PWSTR) &dpi.deviceName, sizeof(dpi.deviceName), deviceName);
bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_DRIVE_PARTITION_INFO, &dpi,
sizeof (dpi), &dpi, sizeof (dpi), &dwResult, NULL);
@@ -7331,25 +7259,25 @@ BOOL GetPartitionInfo (const char *deviceName, PPARTITION_INFORMATION rpartInfo) }
-BOOL GetDeviceInfo (const char *deviceName, DISK_PARTITION_INFO_STRUCT *info)
+BOOL GetDeviceInfo (const wchar_t *deviceName, DISK_PARTITION_INFO_STRUCT *info)
{
DWORD dwResult;
memset (info, 0, sizeof(*info));
- StringCbPrintfW ((PWSTR) &info->deviceName, sizeof(info->deviceName), L"%hs", deviceName);
+ StringCbCopyW ((PWSTR) &info->deviceName, sizeof(info->deviceName), deviceName);
return DeviceIoControl (hDriver, TC_IOCTL_GET_DRIVE_PARTITION_INFO, info, sizeof (*info), info, sizeof (*info), &dwResult, NULL);
}
-BOOL GetDriveGeometry (const char *deviceName, PDISK_GEOMETRY diskGeometry)
+BOOL GetDriveGeometry (const wchar_t *deviceName, PDISK_GEOMETRY diskGeometry)
{
BOOL bResult;
DWORD dwResult;
DISK_GEOMETRY_STRUCT dg;
memset (&dg, 0, sizeof(dg));
- StringCbPrintfW ((PWSTR) &dg.deviceName, sizeof(dg.deviceName), L"%hs", deviceName);
+ StringCbCopyW ((PWSTR) &dg.deviceName, sizeof(dg.deviceName), deviceName);
bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_DRIVE_GEOMETRY, &dg,
sizeof (dg), &dg, sizeof (dg), &dwResult, NULL);
@@ -7377,7 +7305,7 @@ int GetDiskDeviceDriveLetter (PWSTR deviceName) for (i = 0; i < 26; i++)
{
- WCHAR drive[] = { (WCHAR) i + 'A', ':', 0 };
+ WCHAR drive[] = { (WCHAR) i + L'A', L':', 0 };
StringCchCopyW (link, MAX_PATH, L"\\DosDevices\\");
StringCchCatW (link, MAX_PATH, drive);
@@ -7396,7 +7324,7 @@ int GetDiskDeviceDriveLetter (PWSTR deviceName) // WARNING: This function does NOT provide 100% reliable results -- do NOT use it for critical/dangerous operations!
// Return values: 0 - filesystem does not appear empty, 1 - filesystem appears empty, -1 - an error occurred
-int FileSystemAppearsEmpty (const char *devicePath)
+int FileSystemAppearsEmpty (const wchar_t *devicePath)
{
float percentFreeSpace = 0.0;
__int64 occupiedBytes = 0;
@@ -7420,20 +7348,19 @@ int FileSystemAppearsEmpty (const char *devicePath) // is not NULL, size of occupied space (in bytes) is written to the pointed location. In addition, if the
// 'percent' pointer is not NULL, % of free space is stored in the pointed location. If there's an error,
// returns -1.
-__int64 GetStatsFreeSpaceOnPartition (const char *devicePath, float *percentFree, __int64 *occupiedBytes, BOOL silent)
+__int64 GetStatsFreeSpaceOnPartition (const wchar_t *devicePath, float *percentFree, __int64 *occupiedBytes, BOOL silent)
{
WCHAR devPath [MAX_PATH];
int driveLetterNo = -1;
- char szRootPath[4] = {0, ':', '\\', 0};
+ wchar_t szRootPath[4] = {0, L':', L'\\', 0};
ULARGE_INTEGER freeSpaceSize;
ULARGE_INTEGER totalNumberOfBytes;
ULARGE_INTEGER totalNumberOfFreeBytes;
- StringCbCopyA ((char *) devPath, sizeof(devPath), devicePath);
- ToUNICODE ((char *) devPath, sizeof(devPath));
+ StringCbCopyW (devPath, sizeof(devPath), devicePath);
driveLetterNo = GetDiskDeviceDriveLetter (devPath);
- szRootPath[0] = (char) driveLetterNo + 'A';
+ szRootPath[0] = (wchar_t) driveLetterNo + L'A';
if (!GetDiskFreeSpaceEx (szRootPath, &freeSpaceSize, &totalNumberOfBytes, &totalNumberOfFreeBytes))
@@ -7476,7 +7403,7 @@ __int64 GetStatsFreeSpaceOnPartition (const char *devicePath, float *percentFree // Returns -1 if there's an error.
-__int64 GetDeviceSize (const char *devicePath)
+__int64 GetDeviceSize (const wchar_t *devicePath)
{
PARTITION_INFORMATION partitionInfo;
@@ -7487,7 +7414,7 @@ __int64 GetDeviceSize (const char *devicePath) }
-HANDLE DismountDrive (char *devName, char *devicePath)
+HANDLE DismountDrive (wchar_t *devName, wchar_t *devicePath)
{
DWORD dwResult;
HANDLE hVolume;
@@ -7496,8 +7423,7 @@ HANDLE DismountDrive (char *devName, char *devicePath) int driveLetterNo = -1;
WCHAR devPath [MAX_PATH];
- StringCbCopyA ((char *) devPath, sizeof(devPath), devicePath);
- ToUNICODE ((char *) devPath, sizeof(devPath));
+ StringCbCopyW (devPath, sizeof(devPath), devicePath);
driveLetterNo = GetDiskDeviceDriveLetter (devPath);
@@ -7563,32 +7489,32 @@ int64 FindString (const char *buf, const char *str, int64 bufLen, int64 strLen, }
// Returns TRUE if the file or directory exists (both may be enclosed in quotation marks).
-BOOL FileExists (const char *filePathPtr)
+BOOL FileExists (const wchar_t *filePathPtr)
{
- char filePath [TC_MAX_PATH * 2 + 1];
+ wchar_t filePath [TC_MAX_PATH * 2 + 1];
// Strip quotation marks (if any)
- if (filePathPtr [0] == '"')
+ if (filePathPtr [0] == L'"')
{
- StringCbCopyA (filePath, sizeof(filePath), filePathPtr + 1);
+ StringCbCopyW (filePath, sizeof(filePath), filePathPtr + 1);
}
else
{
- StringCbCopyA (filePath, sizeof(filePath), filePathPtr);
+ StringCbCopyW (filePath, sizeof(filePath), filePathPtr);
}
// Strip quotation marks (if any)
- if (filePath [strlen (filePath) - 1] == '"')
- filePath [strlen (filePath) - 1] = 0;
+ if (filePath [wcslen (filePath) - 1] == L'"')
+ filePath [wcslen (filePath) - 1] = 0;
- return (_access (filePath, 0) != -1);
+ return (_waccess (filePath, 0) != -1);
}
// Searches the file from its end for the LAST occurrence of the string str.
// The string may contain zeroes, which do NOT terminate the string.
// If the string is found, its offset from the start of the file is returned.
// If the string isn't found or if any error occurs, -1 is returned.
-__int64 FindStringInFile (const char *filePath, const char* str, int strLen)
+__int64 FindStringInFile (const wchar_t *filePath, const char* str, int strLen)
{
int bufSize = 64 * BYTES_PER_KB;
char *buffer = (char *) err_malloc (bufSize);
@@ -7706,31 +7632,7 @@ BOOL TCCopyFileBase (HANDLE src, HANDLE dst) return res != 0;
}
-BOOL TCCopyFile (char *sourceFileName, char *destinationFile)
-{
- HANDLE src, dst;
-
- src = CreateFile (sourceFileName,
- GENERIC_READ,
- FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
-
- if (src == INVALID_HANDLE_VALUE)
- return FALSE;
-
- dst = CreateFile (destinationFile,
- GENERIC_WRITE,
- 0, NULL, CREATE_ALWAYS, 0, NULL);
-
- if (dst == INVALID_HANDLE_VALUE)
- {
- CloseHandle (src);
- return FALSE;
- }
-
- return TCCopyFileBase (src, dst);
-}
-
-BOOL TCCopyFileW (wchar_t *sourceFileName, wchar_t *destinationFile)
+BOOL TCCopyFile (wchar_t *sourceFileName, wchar_t *destinationFile)
{
HANDLE src, dst;
@@ -7756,7 +7658,7 @@ BOOL TCCopyFileW (wchar_t *sourceFileName, wchar_t *destinationFile) // If bAppend is TRUE, the buffer is appended to an existing file. If bAppend is FALSE, any existing file
// is replaced. If an error occurs, the incomplete file is deleted (provided that bAppend is FALSE).
-BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWORD inputLength, BOOL bAppend, BOOL bRenameIfFailed)
+BOOL SaveBufferToFile (const char *inputBuffer, const wchar_t *destinationFile, DWORD inputLength, BOOL bAppend, BOOL bRenameIfFailed)
{
HANDLE dst;
DWORD bytesWritten;
@@ -7770,9 +7672,9 @@ BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWO dwLastError = GetLastError();
if (!bAppend && bRenameIfFailed && (dst == INVALID_HANDLE_VALUE) && (GetLastError () == ERROR_SHARING_VIOLATION))
{
- char renamedPath[TC_MAX_PATH + 1];
- StringCbCopyA (renamedPath, sizeof(renamedPath), destinationFile);
- StringCbCatA (renamedPath, sizeof(renamedPath), VC_FILENAME_RENAMED_SUFFIX);
+ wchar_t renamedPath[TC_MAX_PATH + 1];
+ StringCbCopyW (renamedPath, sizeof(renamedPath), destinationFile);
+ StringCbCatW (renamedPath, sizeof(renamedPath), VC_FILENAME_RENAMED_SUFFIX);
/* rename the locked file in order to be able to create a new one */
if (MoveFileEx (destinationFile, renamedPath, MOVEFILE_REPLACE_EXISTING))
@@ -7821,7 +7723,7 @@ BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWO CloseHandle (dst);
if (!res && !bAppend)
- remove (destinationFile);
+ _wremove (destinationFile);
return res;
}
@@ -7844,62 +7746,62 @@ BOOL TCFlushFile (FILE *f) // Prints a UTF-16 text (note that this involves a real printer, not a screen).
// textByteLen - length of the text in bytes
// title - printed as part of the page header and used as the filename for a temporary file
-BOOL PrintHardCopyTextUTF16 (wchar_t *text, char *title, size_t textByteLen)
+BOOL PrintHardCopyTextUTF16 (wchar_t *text, wchar_t *title, size_t textByteLen)
{
- char cl [MAX_PATH*3] = {"/p \""};
- char path [MAX_PATH * 2] = { 0 };
- char filename [MAX_PATH + 1] = { 0 };
+ wchar_t cl [MAX_PATH*3] = {L"/p \""};
+ wchar_t path [MAX_PATH * 2] = { 0 };
+ wchar_t filename [MAX_PATH + 1] = { 0 };
- StringCbCopyA (filename, sizeof(filename), title);
+ StringCbCopyW (filename, sizeof(filename), title);
//strcat (filename, ".txt");
- GetTempPath (sizeof (path), path);
+ GetTempPath (ARRAYSIZE (path), path);
if (!FileExists (path))
{
- StringCbCopyA (path, sizeof(path), GetConfigPath (filename));
+ StringCbCopyW (path, sizeof(path), GetConfigPath (filename));
- if (strlen(path) < 2)
+ if (wcslen(path) < 2)
return FALSE;
}
else
{
- StringCbCatA (path, sizeof(path), filename);
+ StringCbCatW (path, sizeof(path), filename);
}
// Write the Unicode signature
if (!SaveBufferToFile ("\xFF\xFE", path, 2, FALSE, FALSE))
{
- remove (path);
+ _wremove (path);
return FALSE;
}
// Write the actual text
if (!SaveBufferToFile ((char *) text, path, (DWORD) textByteLen, TRUE, FALSE))
{
- remove (path);
+ _wremove (path);
return FALSE;
}
- StringCbCatA (cl, sizeof(cl), path);
- StringCbCatA (cl, sizeof(cl), "\"");
+ StringCbCatW (cl, sizeof(cl), path);
+ StringCbCatW (cl, sizeof(cl), L"\"");
// Get the absolute path for notepad
if (GetWindowsDirectory(filename, MAX_PATH))
{
- if (filename[strlen (filename) - 1] != '\\')
- StringCbCatA (filename, sizeof(filename), "\\");
- StringCbCatA(filename, sizeof(filename), PRINT_TOOL);
+ if (filename[wcslen (filename) - 1] != L'\\')
+ StringCbCatW (filename, sizeof(filename), L"\\");
+ StringCbCatW(filename, sizeof(filename), PRINT_TOOL);
}
else
- StringCbCopyA(filename, sizeof(filename), "C:\\Windows\\" PRINT_TOOL);
+ StringCbCopyW(filename, sizeof(filename), L"C:\\Windows\\" PRINT_TOOL);
WaitCursor ();
- ShellExecute (NULL, "open", filename, cl, NULL, SW_HIDE);
+ ShellExecute (NULL, L"open", filename, cl, NULL, SW_HIDE);
Sleep (6000);
NormalCursor();
- remove (path);
+ _wremove (path);
return TRUE;
}
@@ -7937,13 +7839,13 @@ BOOL IsNonInstallMode () {
// The driver was not found in the system path
- char path[MAX_PATH * 2] = { 0 };
+ wchar_t path[MAX_PATH * 2] = { 0 };
// We can't use GetConfigPath() here because it would call us back (indirect recursion)
if (SUCCEEDED(SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, path)))
{
- StringCbCatA (path, MAX_PATH * 2, "\\VeraCrypt\\");
- StringCbCatA (path, MAX_PATH * 2, TC_APPD_FILENAME_SYSTEM_ENCRYPTION);
+ StringCbCatW (path, MAX_PATH * 2, L"\\VeraCrypt\\");
+ StringCbCatW (path, MAX_PATH * 2, TC_APPD_FILENAME_SYSTEM_ENCRYPTION);
if (FileExists (path))
{
@@ -7968,7 +7870,7 @@ BOOL IsNonInstallMode () // The following test may be unreliable in some cases (e.g. after the user selects restore "Last Known Good
// Configuration" from the Windows boot menu).
- if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\VeraCrypt", 0, KEY_READ | KEY_WOW64_32KEY, &hkey) == ERROR_SUCCESS)
+ if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\VeraCrypt", 0, KEY_READ | KEY_WOW64_32KEY, &hkey) == ERROR_SUCCESS)
{
RegCloseKey (hkey);
return FALSE;
@@ -8008,79 +7910,79 @@ void ManageStartupSeq (void) {
if (!IsNonInstallMode ())
{
- char regk [64];
+ wchar_t regk [64];
GetStartupRegKeyName (regk, sizeof(regk));
if (bStartOnLogon || bMountDevicesOnLogon || bMountFavoritesOnLogon)
{
- char exe[MAX_PATH * 2] = { '"' };
+ wchar_t exe[MAX_PATH * 2] = { L'"' };
- GetModuleFileName (NULL, exe + 1, sizeof (exe) - 1);
+ GetModuleFileName (NULL, exe + 1, ARRAYSIZE (exe) - 1);
#ifdef VOLFORMAT
{
- char *tmp = NULL;
+ wchar_t *tmp = NULL;
- if (tmp = strrchr (exe, '\\'))
+ if (tmp = wcsrchr (exe, L'\\'))
{
*tmp = 0;
- StringCbCatA (exe, MAX_PATH * 2, "\\VeraCrypt.exe");
+ StringCbCatW (exe, MAX_PATH * 2, L"\\VeraCrypt.exe");
}
}
#endif
- StringCbCatA (exe, MAX_PATH * 2, "\" /q preferences /a logon");
+ StringCbCatW (exe, MAX_PATH * 2, L"\" /q preferences /a logon");
- if (bMountDevicesOnLogon) StringCbCatA (exe, MAX_PATH * 2, " /a devices");
- if (bMountFavoritesOnLogon) StringCbCatA (exe, MAX_PATH * 2, " /a favorites");
+ if (bMountDevicesOnLogon) StringCbCatW (exe, MAX_PATH * 2, L" /a devices");
+ if (bMountFavoritesOnLogon) StringCbCatW (exe, MAX_PATH * 2, L" /a favorites");
- WriteRegistryString (regk, "VeraCrypt", exe);
+ WriteRegistryString (regk, L"VeraCrypt", exe);
}
else
- DeleteRegistryValue (regk, "VeraCrypt");
+ DeleteRegistryValue (regk, L"VeraCrypt");
}
}
// Adds or removes the VeraCrypt Volume Creation Wizard to/from the system startup sequence
-void ManageStartupSeqWiz (BOOL bRemove, const char *arg)
+void ManageStartupSeqWiz (BOOL bRemove, const wchar_t *arg)
{
- char regk [64];
+ wchar_t regk [64];
GetStartupRegKeyName (regk, sizeof(regk));
if (!bRemove)
{
- size_t exeSize = (MAX_PATH * 2) + 3 + 20 + strlen (arg); // enough room for all concatenation operations
- char* exe = (char*) calloc(1, exeSize);
- exe[0] = '"';
+ size_t exeSize = (MAX_PATH * 2) + 3 + 20 + wcslen (arg); // enough room for all concatenation operations
+ wchar_t* exe = (wchar_t*) calloc(1, exeSize * sizeof (wchar_t));
+ exe[0] = L'"';
GetModuleFileName (NULL, exe + 1, (DWORD) (exeSize - 1));
#ifndef VOLFORMAT
{
- char *tmp = NULL;
+ wchar_t *tmp = NULL;
- if (tmp = strrchr (exe, '\\'))
+ if (tmp = wcsrchr (exe, L'\\'))
{
*tmp = 0;
- StringCbCatA (exe, exeSize, "\\VeraCrypt Format.exe");
+ StringCchCatW (exe, exeSize, L"\\VeraCrypt Format.exe");
}
}
#endif
- if (strlen (arg) > 0)
+ if (wcslen (arg) > 0)
{
- StringCbCatA (exe, exeSize, "\" ");
- StringCbCatA (exe, exeSize, arg);
+ StringCchCatW (exe, exeSize, L"\" ");
+ StringCchCatW (exe, exeSize, arg);
}
- WriteRegistryString (regk, "VeraCrypt Format", exe);
+ WriteRegistryString (regk, L"VeraCrypt Format", exe);
free(exe);
}
else
- DeleteRegistryValue (regk, "VeraCrypt Format");
+ DeleteRegistryValue (regk, L"VeraCrypt Format");
}
@@ -8091,19 +7993,19 @@ void CleanLastVisitedMRU (void) WCHAR *strToMatch;
WCHAR strTmp[4096];
- char regPath[128];
- char key[64];
+ WCHAR regPath[128];
+ WCHAR key[64];
int id, len;
GetModuleFileNameW (NULL, exeFilename, sizeof (exeFilename) / sizeof(exeFilename[0]));
- strToMatch = wcsrchr (exeFilename, '\\') + 1;
+ strToMatch = wcsrchr (exeFilename, L'\\') + 1;
- StringCbPrintfA (regPath, sizeof(regPath), "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisited%sMRU", IsOSAtLeast (WIN_VISTA) ? "Pidl" : "");
+ StringCbPrintfW (regPath, sizeof(regPath), L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisited%sMRU", IsOSAtLeast (WIN_VISTA) ? L"Pidl" : L"");
- for (id = (IsOSAtLeast (WIN_VISTA) ? 0 : 'a'); id <= (IsOSAtLeast (WIN_VISTA) ? 1000 : 'z'); id++)
+ for (id = (IsOSAtLeast (WIN_VISTA) ? 0 : L'a'); id <= (IsOSAtLeast (WIN_VISTA) ? 1000 : L'z'); id++)
{
*strTmp = 0;
- StringCbPrintfA (key, sizeof(key), (IsOSAtLeast (WIN_VISTA) ? "%d" : "%c"), id);
+ StringCbPrintfW (key, sizeof(key), (IsOSAtLeast (WIN_VISTA) ? L"%d" : L"%c"), id);
if ((len = ReadRegistryBytes (regPath, key, (char *) strTmp, sizeof (strTmp))) > 0)
{
@@ -8125,7 +8027,7 @@ void CleanLastVisitedMRU (void) int *pout = (int *)bufout;
int l;
- l = len = ReadRegistryBytes ("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisitedPidlMRU", "MRUListEx", buf, sizeof (buf));
+ l = len = ReadRegistryBytes (L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisitedPidlMRU", L"MRUListEx", buf, sizeof (buf));
while (l > 0)
{
l -= sizeof (int);
@@ -8139,14 +8041,14 @@ void CleanLastVisitedMRU (void) *pout++ = *p++;
}
- WriteRegistryBytes ("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisitedPidlMRU", "MRUListEx", bufout, len);
+ WriteRegistryBytes (L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisitedPidlMRU", L"MRUListEx", bufout, len);
}
else
{
- char *p = buf;
- char *pout = bufout;
+ wchar_t *p = (wchar_t*) buf;
+ wchar_t *pout = (wchar_t*) bufout;
- ReadRegistryString ("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisitedMRU", "MRUList", "", buf, sizeof (buf));
+ ReadRegistryString (L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisitedMRU", L"MRUList", L"", (wchar_t*) buf, sizeof (buf));
while (*p)
{
if (*p == id)
@@ -8158,7 +8060,7 @@ void CleanLastVisitedMRU (void) }
*pout++ = 0;
- WriteRegistryString ("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisitedMRU", "MRUList", bufout);
+ WriteRegistryString (L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisitedMRU", L"MRUList", (wchar_t*) bufout);
}
break;
@@ -8183,58 +8085,32 @@ void ClearHistory (HWND hwndDlgItem) #endif // #ifndef SETUP
-LRESULT ListItemAdd (HWND list, int index, char *string)
+LRESULT ListItemAdd (HWND list, int index, const wchar_t *string)
{
LVITEM li;
memset (&li, 0, sizeof(li));
li.mask = LVIF_TEXT;
- li.pszText = string;
+ li.pszText = (wchar_t*) string;
li.iItem = index;
li.iSubItem = 0;
return ListView_InsertItem (list, &li);
}
-LRESULT ListItemAddW (HWND list, int index, wchar_t *string)
-{
- LVITEMW li;
- memset (&li, 0, sizeof(li));
-
- li.mask = LVIF_TEXT;
- li.pszText = string;
- li.iItem = index;
- li.iSubItem = 0;
- return SendMessageW (list, LVM_INSERTITEMW, 0, (LPARAM)(&li));
-}
-
-
-LRESULT ListSubItemSet (HWND list, int index, int subIndex, char *string)
+LRESULT ListSubItemSet (HWND list, int index, int subIndex, const wchar_t *string)
{
LVITEM li;
memset (&li, 0, sizeof(li));
li.mask = LVIF_TEXT;
- li.pszText = string;
+ li.pszText = (wchar_t*) string;
li.iItem = index;
li.iSubItem = subIndex;
return ListView_SetItem (list, &li);
}
-LRESULT ListSubItemSetW (HWND list, int index, int subIndex, wchar_t *string)
-{
- LVITEMW li;
- memset (&li, 0, sizeof(li));
-
- li.mask = LVIF_TEXT;
- li.pszText = string;
- li.iItem = index;
- li.iSubItem = subIndex;
- return SendMessageW (list, LVM_SETITEMW, 0, (LPARAM)(&li));
-}
-
-
BOOL GetMountList (MOUNT_LIST_STRUCT *list)
{
DWORD dwResult;
@@ -8263,7 +8139,7 @@ int GetDriverRefCount () // Loads a 32-bit integer from the file at the specified file offset. The saved value is assumed to have been
// processed by mputLong(). The result is stored in *result. Returns TRUE if successful (otherwise FALSE).
-BOOL LoadInt32 (char *filePath, unsigned __int32 *result, __int64 fileOffset)
+BOOL LoadInt32 (const wchar_t *filePath, unsigned __int32 *result, __int64 fileOffset)
{
DWORD bufSize = sizeof(__int32);
unsigned char *buffer = (unsigned char *) malloc (bufSize);
@@ -8307,7 +8183,7 @@ fsif_end: // Loads a 16-bit integer from the file at the specified file offset. The saved value is assumed to have been
// processed by mputWord(). The result is stored in *result. Returns TRUE if successful (otherwise FALSE).
-BOOL LoadInt16 (char *filePath, int *result, __int64 fileOffset)
+BOOL LoadInt16 (const wchar_t *filePath, int *result, __int64 fileOffset)
{
DWORD bufSize = sizeof(__int16);
unsigned char *buffer = (unsigned char *) malloc (bufSize);
@@ -8350,7 +8226,7 @@ fsif_end: }
// Returns NULL if there's any error. Although the buffer can contain binary data, it is always null-terminated.
-char *LoadFile (const char *fileName, DWORD *size)
+char *LoadFile (const wchar_t *fileName, DWORD *size)
{
char *buf;
DWORD fileSize = INVALID_FILE_SIZE;
@@ -8385,7 +8261,7 @@ char *LoadFile (const char *fileName, DWORD *size) // Returns NULL if there's any error.
-char *LoadFileBlock (char *fileName, __int64 fileOffset, DWORD count)
+char *LoadFileBlock (const wchar_t *fileName, __int64 fileOffset, DWORD count)
{
char *buf;
DWORD bytesRead = 0;
@@ -8427,7 +8303,7 @@ char *LoadFileBlock (char *fileName, __int64 fileOffset, DWORD count) // Returns -1 if there is an error, or the size of the file.
-__int64 GetFileSize64 (const char *path)
+__int64 GetFileSize64 (const wchar_t *path)
{
HANDLE h = CreateFile (path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
LARGE_INTEGER size;
@@ -8447,33 +8323,33 @@ __int64 GetFileSize64 (const char *path) }
-char *GetModPath (char *path, int maxSize)
+wchar_t *GetModPath (wchar_t *path, int maxSize)
{
GetModuleFileName (NULL, path, maxSize);
- char* ptr = strrchr (path, '\\');
+ wchar_t* ptr = wcsrchr (path, L'\\');
if (ptr)
ptr[1] = 0;
return path;
}
-char *GetConfigPath (char *fileName)
+wchar_t *GetConfigPath (wchar_t *fileName)
{
- static char path[MAX_PATH * 2] = { 0 };
+ static wchar_t path[MAX_PATH * 2] = { 0 };
if (IsNonInstallMode ())
{
- GetModPath (path, sizeof (path));
- StringCbCatA (path, (MAX_PATH * 2), fileName);
+ GetModPath (path, ARRAYSIZE (path));
+ StringCchCatW (path, (MAX_PATH * 2), fileName);
return path;
}
if (SUCCEEDED(SHGetFolderPath (NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path)))
{
- StringCbCatA (path, (MAX_PATH * 2), "\\VeraCrypt\\");
+ StringCchCatW (path, (MAX_PATH * 2), L"\\VeraCrypt\\");
CreateDirectory (path, NULL);
- StringCbCatA (path, (MAX_PATH * 2), fileName);
+ StringCchCatW (path, (MAX_PATH * 2), fileName);
}
else
path[0] = 0;
@@ -8482,15 +8358,15 @@ char *GetConfigPath (char *fileName) }
-char *GetProgramConfigPath (char *fileName)
+wchar_t *GetProgramConfigPath (wchar_t *fileName)
{
- static char path[MAX_PATH * 2] = { 0 };
+ static wchar_t path[MAX_PATH * 2] = { 0 };
if (SUCCEEDED (SHGetFolderPath (NULL, CSIDL_COMMON_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path)))
{
- StringCbCatA (path, (MAX_PATH * 2), "\\VeraCrypt\\");
+ StringCchCatW (path, (MAX_PATH * 2), L"\\VeraCrypt\\");
CreateDirectory (path, NULL);
- StringCbCatA (path, (MAX_PATH * 2), fileName);
+ StringCchCatW (path, (MAX_PATH * 2), fileName);
}
else
path[0] = 0;
@@ -8499,31 +8375,31 @@ char *GetProgramConfigPath (char *fileName) }
-std::string GetServiceConfigPath (const char *fileName, bool useLegacy)
+std::wstring GetServiceConfigPath (const wchar_t *fileName, bool useLegacy)
{
- char sysPath[TC_MAX_PATH];
+ wchar_t sysPath[TC_MAX_PATH];
if (Is64BitOs() && useLegacy)
{
- typedef UINT (WINAPI *GetSystemWow64Directory_t) (LPTSTR lpBuffer, UINT uSize);
+ typedef UINT (WINAPI *GetSystemWow64Directory_t) (LPWSTR lpBuffer, UINT uSize);
- GetSystemWow64Directory_t getSystemWow64Directory = (GetSystemWow64Directory_t) GetProcAddress (GetModuleHandle ("kernel32"), "GetSystemWow64DirectoryA");
- getSystemWow64Directory (sysPath, sizeof (sysPath));
+ GetSystemWow64Directory_t getSystemWow64Directory = (GetSystemWow64Directory_t) GetProcAddress (GetModuleHandle (L"kernel32"), "GetSystemWow64DirectoryW");
+ getSystemWow64Directory (sysPath, ARRAYSIZE (sysPath));
}
else
- GetSystemDirectory (sysPath, sizeof (sysPath));
+ GetSystemDirectory (sysPath, ARRAYSIZE (sysPath));
- return string (sysPath) + "\\" + fileName;
+ return wstring (sysPath) + L"\\" + fileName;
}
// Returns 0 if an error occurs or the drive letter (as an upper-case char) of the system partition (e.g. 'C');
-char GetSystemDriveLetter (void)
+wchar_t GetSystemDriveLetter (void)
{
- char systemDir [MAX_PATH];
+ wchar_t systemDir [MAX_PATH];
- if (GetSystemDirectory (systemDir, sizeof (systemDir)))
- return (char) (toupper (systemDir [0]));
+ if (GetSystemDirectory (systemDir, ARRAYSIZE (systemDir)))
+ return (wchar_t) (towupper (systemDir [0]));
else
return 0;
}
@@ -8826,7 +8702,7 @@ BOOL ConfigWriteBegin () if (ConfigBuffer == NULL)
ConfigBuffer = LoadFile (GetConfigPath (TC_APPD_FILENAME_CONFIGURATION), &size);
- ConfigFileHandle = fopen (GetConfigPath (TC_APPD_FILENAME_CONFIGURATION), "w");
+ ConfigFileHandle = _wfopen (GetConfigPath (TC_APPD_FILENAME_CONFIGURATION), L"w,ccs=UTF-8");
if (ConfigFileHandle == NULL)
{
free (ConfigBuffer);
@@ -8834,7 +8710,7 @@ BOOL ConfigWriteBegin () return FALSE;
}
XmlWriteHeader (ConfigFileHandle);
- fputs ("\n\t<configuration>", ConfigFileHandle);
+ fputws (L"\n\t<configuration>", ConfigFileHandle);
return TRUE;
}
@@ -8853,11 +8729,11 @@ BOOL ConfigWriteEnd (HWND hwnd) XmlGetAttributeText (xml, "key", key, sizeof (key));
XmlGetNodeText (xml, value, sizeof (value));
- fprintf (ConfigFileHandle, "\n\t\t<config key=\"%s\">%s</config>", key, value);
+ fwprintf (ConfigFileHandle, L"\n\t\t<config key=\"%hs\">%hs</config>", key, value);
xml++;
}
- fputs ("\n\t</configuration>", ConfigFileHandle);
+ fputws (L"\n\t</configuration>", ConfigFileHandle);
XmlWriteFooter (ConfigFileHandle);
TCFlushFile (ConfigFileHandle);
@@ -8892,11 +8768,29 @@ BOOL ConfigWriteString (char *configKey, char *configValue) c[1] = '!';
}
- return 0 != fprintf (
- ConfigFileHandle, "\n\t\t<config key=\"%s\">%s</config>",
+ return 0 != fwprintf (
+ ConfigFileHandle, L"\n\t\t<config key=\"%hs\">%hs</config>",
configKey, configValue);
}
+BOOL ConfigWriteStringW (char *configKey, wchar_t *configValue)
+{
+ char *c;
+ if (ConfigFileHandle == NULL)
+ return FALSE;
+
+ // Mark previous config value as updated
+ if (ConfigBuffer != NULL)
+ {
+ c = XmlFindElementByAttributeValue (ConfigBuffer, "config", "key", configKey);
+ if (c != NULL)
+ c[1] = '!';
+ }
+
+ return 0 != fwprintf (
+ ConfigFileHandle, L"\n\t\t<config key=\"%hs\">%ls</config>",
+ configKey, configValue);
+}
BOOL ConfigWriteInt (char *configKey, int configValue)
{
@@ -8992,12 +8886,12 @@ void ConfigReadCompareString (char *configKey, char *defaultValue, char *str, in void OpenPageHelp (HWND hwndDlg, int nPage)
{
- int r = (int)ShellExecute (NULL, "open", szHelpFile, NULL, NULL, SW_SHOWNORMAL);
+ int r = (int)ShellExecuteW (NULL, L"open", szHelpFile, NULL, NULL, SW_SHOWNORMAL);
if (r == ERROR_FILE_NOT_FOUND)
{
// Try the secondary help file
- r = (int)ShellExecute (NULL, "open", szHelpFile2, NULL, NULL, SW_SHOWNORMAL);
+ r = (int)ShellExecuteW (NULL, L"open", szHelpFile2, NULL, NULL, SW_SHOWNORMAL);
if (r == ERROR_FILE_NOT_FOUND)
{
@@ -9053,8 +8947,13 @@ BOOL LoadDefaultKeyFilesParam (void) kf = (KeyFile *) malloc (sizeof (KeyFile));
if (kf)
{
- if (XmlGetNodeText (xml, kf->FileName, sizeof (kf->FileName)) != NULL)
+ char fileName [MAX_PATH + 1];
+ if (XmlGetNodeText (xml, fileName, sizeof (fileName)) != NULL)
+ {
+ std::wstring wszFileName = Utf8StringToWide(fileName);
+ StringCbCopyW (kf->FileName, sizeof (kf->FileName), wszFileName.c_str ());
defaultKeyFilesParam.FirstKeyFile = KeyFileAdd (defaultKeyFilesParam.FirstKeyFile, kf);
+ }
else
free (kf);
}
@@ -9087,7 +8986,7 @@ void Debug (char *format, ...) StringCbVPrintfA (buf, sizeof (buf), format, val);
va_end(val);
- OutputDebugString (buf);
+ OutputDebugStringA (buf);
}
@@ -9100,7 +8999,7 @@ void DebugMsgBox (char *format, ...) StringCbVPrintfA (buf, sizeof (buf), format, val);
va_end(val);
- MessageBox (MainDlg, buf, "VeraCrypt debug", 0);
+ MessageBoxA (MainDlg, buf, "VeraCrypt debug", 0);
}
@@ -9154,7 +9053,7 @@ BOOL Is64BitOs () if (valid)
return isWow64;
- fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle("kernel32"), "IsWow64Process");
+ fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle(L"kernel32"), "IsWow64Process");
if (fnIsWow64Process != NULL)
if (!fnIsWow64Process (GetCurrentProcess(), &isWow64))
@@ -9204,7 +9103,7 @@ BOOL IsHiddenOSRunning (void) BOOL EnableWow64FsRedirection (BOOL enable)
{
typedef BOOLEAN (__stdcall *Wow64EnableWow64FsRedirection_t) (BOOL enable);
- Wow64EnableWow64FsRedirection_t wow64EnableWow64FsRedirection = (Wow64EnableWow64FsRedirection_t) GetProcAddress (GetModuleHandle ("kernel32"), "Wow64EnableWow64FsRedirection");
+ Wow64EnableWow64FsRedirection_t wow64EnableWow64FsRedirection = (Wow64EnableWow64FsRedirection_t) GetProcAddress (GetModuleHandle (L"kernel32"), "Wow64EnableWow64FsRedirection");
if (!wow64EnableWow64FsRedirection)
return FALSE;
@@ -9246,23 +9145,23 @@ BOOL RestartComputer (void) }
-std::string GetWindowsEdition ()
+std::wstring GetWindowsEdition ()
{
- string osname = "win";
+ wstring osname = L"win";
- OSVERSIONINFOEXA osVer;
+ OSVERSIONINFOEXW osVer;
osVer.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEXA);
- GetVersionExA ((LPOSVERSIONINFOA) &osVer);
+ GetVersionExW ((LPOSVERSIONINFOW) &osVer);
BOOL home = (osVer.wSuiteMask & VER_SUITE_PERSONAL);
BOOL server = (osVer.wProductType == VER_NT_SERVER || osVer.wProductType == VER_NT_DOMAIN_CONTROLLER);
HKEY hkey;
- char productName[300] = {0};
+ wchar_t productName[300] = {0};
DWORD productNameSize = sizeof (productName);
- if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS)
+ if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS)
{
- if (RegQueryValueEx (hkey, "ProductName", 0, 0, (LPBYTE) &productName, &productNameSize) != ERROR_SUCCESS || productNameSize < 1)
+ if (RegQueryValueEx (hkey, L"ProductName", 0, 0, (LPBYTE) &productName, &productNameSize) != ERROR_SUCCESS || productNameSize < 1)
productName[0] = 0;
RegCloseKey (hkey);
@@ -9271,75 +9170,75 @@ std::string GetWindowsEdition () switch (nCurrentOS)
{
case WIN_2000:
- osname += "2000";
+ osname += L"2000";
break;
case WIN_XP:
case WIN_XP64:
- osname += "xp";
- osname += home ? "-home" : "-pro";
+ osname += L"xp";
+ osname += home ? L"-home" : L"-pro";
break;
case WIN_SERVER_2003:
- osname += "2003";
+ osname += L"2003";
break;
case WIN_VISTA:
- osname += "vista";
+ osname += L"vista";
break;
case WIN_SERVER_2008:
- osname += "2008";
+ osname += L"2008";
break;
case WIN_7:
- osname += "7";
+ osname += L"7";
break;
case WIN_SERVER_2008_R2:
- osname += "2008r2";
+ osname += L"2008r2";
break;
default:
- stringstream s;
- s << CurrentOSMajor << "." << CurrentOSMinor;
+ wstringstream s;
+ s << CurrentOSMajor << L"." << CurrentOSMinor;
osname += s.str();
break;
}
if (server)
- osname += "-server";
+ osname += L"-server";
if (IsOSAtLeast (WIN_VISTA))
{
if (home)
- osname += "-home";
- else if (strstr (productName, "Standard") != 0)
- osname += "-standard";
- else if (strstr (productName, "Professional") != 0)
- osname += "-pro";
- else if (strstr (productName, "Business") != 0)
- osname += "-business";
- else if (strstr (productName, "Enterprise") != 0)
- osname += "-enterprise";
- else if (strstr (productName, "Datacenter") != 0)
- osname += "-datacenter";
- else if (strstr (productName, "Ultimate") != 0)
- osname += "-ultimate";
+ osname += L"-home";
+ else if (wcsstr (productName, L"Standard") != 0)
+ osname += L"-standard";
+ else if (wcsstr (productName, L"Professional") != 0)
+ osname += L"-pro";
+ else if (wcsstr (productName, L"Business") != 0)
+ osname += L"-business";
+ else if (wcsstr (productName, L"Enterprise") != 0)
+ osname += L"-enterprise";
+ else if (wcsstr (productName, L"Datacenter") != 0)
+ osname += L"-datacenter";
+ else if (wcsstr (productName, L"Ultimate") != 0)
+ osname += L"-ultimate";
}
if (GetSystemMetrics (SM_STARTER))
- osname += "-starter";
- else if (strstr (productName, "Basic") != 0)
- osname += "-basic";
+ osname += L"-starter";
+ else if (wcsstr (productName, L"Basic") != 0)
+ osname += L"-basic";
if (Is64BitOs())
- osname += "-x64";
+ osname += L"-x64";
if (CurrentOSServicePack > 0)
{
- stringstream s;
- s << "-sp" << CurrentOSServicePack;
+ wstringstream s;
+ s << L"-sp" << CurrentOSServicePack;
osname += s.str();
}
@@ -9470,27 +9369,27 @@ void Applink (char *dest, BOOL bSendOS, char *extraOutput) {
StringCbCopyA (url, sizeof (url),TC_APPLINK);
}
- ShellExecute (NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
+ ShellExecuteA (NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
Sleep (200);
NormalCursor ();
}
-char *RelativePath2Absolute (char *szFileName)
+wchar_t *RelativePath2Absolute (wchar_t *szFileName)
{
- if (szFileName[0] != '\\'
- && strchr (szFileName, ':') == 0
- && strstr (szFileName, "Volume{") != szFileName)
+ if (szFileName[0] != L'\\'
+ && wcschr (szFileName, L':') == 0
+ && wcsstr (szFileName, L"Volume{") != szFileName)
{
- char path[MAX_PATH*2];
+ wchar_t path[MAX_PATH*2];
GetCurrentDirectory (MAX_PATH, path);
- if (path[strlen (path) - 1] != '\\')
- StringCbCatA (path, (MAX_PATH * 2), "\\");
+ if (path[wcslen (path) - 1] != L'\\')
+ StringCbCatW (path, (MAX_PATH * 2), L"\\");
- StringCbCatA (path, (MAX_PATH * 2), szFileName);
- StringCbCopyA (szFileName, MAX_PATH + 1, path); // szFileName size is always at least (MAX_PATH + 1)
+ StringCbCatW (path, (MAX_PATH * 2), szFileName);
+ StringCbCopyW (szFileName, MAX_PATH + 1, path); // szFileName size is always at least (MAX_PATH + 1)
}
return szFileName;
@@ -9502,11 +9401,11 @@ void HandleDriveNotReadyError (HWND hwnd) HKEY hkey = 0;
DWORD value = 0, size = sizeof (DWORD);
- if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\MountMgr",
+ if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\MountMgr",
0, KEY_READ, &hkey) != ERROR_SUCCESS)
return;
- if (RegQueryValueEx (hkey, "NoAutoMount", 0, 0, (LPBYTE) &value, &size) == ERROR_SUCCESS
+ if (RegQueryValueEx (hkey, L"NoAutoMount", 0, 0, (LPBYTE) &value, &size) == ERROR_SUCCESS
&& value != 0)
{
Warning ("SYS_AUTOMOUNT_DISABLED", hwnd);
@@ -9525,9 +9424,9 @@ BOOL CALLBACK CloseTCWindowsEnum (HWND hwnd, LPARAM lParam) LONG_PTR userDataVal = GetWindowLongPtrW (hwnd, GWLP_USERDATA);
if ((userDataVal == (LONG_PTR) 'VERA') || (userDataVal == (LONG_PTR) 'TRUE')) // Prior to 1.0e, 'TRUE' was used for VeraCrypt dialogs
{
- char name[1024] = { 0 };
- GetWindowText (hwnd, name, sizeof (name) - 1);
- if (hwnd != MainDlg && strstr (name, "VeraCrypt"))
+ wchar_t name[1024] = { 0 };
+ GetWindowText (hwnd, name, ARRAYSIZE (name) - 1);
+ if (hwnd != MainDlg && wcsstr (name, L"VeraCrypt"))
{
PostMessage (hwnd, TC_APPMSG_CLOSE_BKG_TASK, 0, 0);
@@ -9548,9 +9447,9 @@ BOOL CALLBACK FindTCWindowEnum (HWND hwnd, LPARAM lParam) LONG_PTR userDataVal = GetWindowLongPtrW (hwnd, GWLP_USERDATA);
if ((userDataVal == (LONG_PTR) 'VERA') || (userDataVal == (LONG_PTR) 'TRUE')) // Prior to 1.0e, 'TRUE' was used for VeraCrypt dialogs
{
- char name[32] = { 0 };
- GetWindowText (hwnd, name, sizeof (name) - 1);
- if (hwnd != MainDlg && strcmp (name, "VeraCrypt") == 0)
+ wchar_t name[32] = { 0 };
+ GetWindowText (hwnd, name, ARRAYSIZE (name) - 1);
+ if (hwnd != MainDlg && wcscmp (name, L"VeraCrypt") == 0)
{
if (lParam != 0)
*((HWND *)lParam) = hwnd;
@@ -9560,7 +9459,7 @@ BOOL CALLBACK FindTCWindowEnum (HWND hwnd, LPARAM lParam) }
-BYTE *MapResource (char *resourceType, int resourceId, PDWORD size)
+BYTE *MapResource (wchar_t *resourceType, int resourceId, PDWORD size)
{
HGLOBAL hResL;
HRSRC hRes;
@@ -9595,12 +9494,12 @@ void ReportUnexpectedState (char *techInfo) #ifndef SETUP
-int OpenVolume (OpenVolumeContext *context, const char *volumePath, Password *password, int pkcs5_prf, int pim, BOOL truecryptMode, BOOL write, BOOL preserveTimestamps, BOOL useBackupHeader)
+int OpenVolume (OpenVolumeContext *context, const wchar_t *volumePath, Password *password, int pkcs5_prf, int pim, BOOL truecryptMode, BOOL write, BOOL preserveTimestamps, BOOL useBackupHeader)
{
int status = ERR_PARAMETER_INCORRECT;
int volumeType;
- char szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
- char szDosDevice[TC_MAX_PATH];
+ wchar_t szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
+ wchar_t szDosDevice[TC_MAX_PATH];
char buffer[TC_VOLUME_HEADER_EFFECTIVE_SIZE];
LARGE_INTEGER headerOffset;
DWORD dwResult;
@@ -9628,7 +9527,7 @@ int OpenVolume (OpenVolumeContext *context, const char *volumePath, Password *pa }
}
else
- StringCbCopyA (szCFDevice, sizeof(szCFDevice), szDiskFile);
+ StringCbCopyW (szCFDevice, sizeof(szCFDevice), szDiskFile);
if (preserveTimestamps)
write = TRUE;
@@ -9837,29 +9736,29 @@ BOOL IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly) {
// GlobalMemoryStatusEx() cannot be used to determine if a paging file is active
- char data[65536];
+ wchar_t data[65536];
DWORD size = sizeof (data);
if (IsPagingFileWildcardActive())
return TRUE;
- if (ReadLocalMachineRegistryMultiString ("System\\CurrentControlSet\\Control\\Session Manager\\Memory Management", "PagingFiles", data, &size)
- && size > 12 && !checkNonWindowsPartitionsOnly)
+ if (ReadLocalMachineRegistryMultiString (L"System\\CurrentControlSet\\Control\\Session Manager\\Memory Management", L"PagingFiles", data, &size)
+ && size > 24 && !checkNonWindowsPartitionsOnly)
return TRUE;
if (!IsAdmin())
AbortProcess ("UAC_INIT_ERROR");
- for (char drive = 'C'; drive <= 'Z'; ++drive)
+ for (wchar_t drive = L'C'; drive <= L'Z'; ++drive)
{
// Query geometry of the drive first to prevent "no medium" pop-ups
- string drivePath = "\\\\.\\X:";
+ wstring drivePath = L"\\\\.\\X:";
drivePath[4] = drive;
if (checkNonWindowsPartitionsOnly)
{
- char sysDir[MAX_PATH];
- if (GetSystemDirectory (sysDir, sizeof (sysDir)) != 0 && toupper (sysDir[0]) == drive)
+ wchar_t sysDir[MAX_PATH];
+ if (GetSystemDirectory (sysDir, ARRAYSIZE (sysDir)) != 0 && towupper (sysDir[0]) == drive)
continue;
}
@@ -9880,7 +9779,7 @@ BOOL IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly) CloseHandle (handle);
// Test if a paging file exists and is locked by another process
- string path = "X:\\pagefile.sys";
+ wstring path = L"X:\\pagefile.sys";
path[0] = drive;
handle = CreateFile (path.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
@@ -9897,25 +9796,25 @@ BOOL IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly) BOOL IsPagingFileWildcardActive ()
{
- char pagingFiles[65536];
+ wchar_t pagingFiles[65536];
DWORD size = sizeof (pagingFiles);
- char *mmKey = "System\\CurrentControlSet\\Control\\Session Manager\\Memory Management";
+ wchar_t *mmKey = L"System\\CurrentControlSet\\Control\\Session Manager\\Memory Management";
- if (!ReadLocalMachineRegistryString (mmKey, "PagingFiles", pagingFiles, &size))
+ if (!ReadLocalMachineRegistryString (mmKey, L"PagingFiles", pagingFiles, &size))
{
size = sizeof (pagingFiles);
- if (!ReadLocalMachineRegistryMultiString (mmKey, "PagingFiles", pagingFiles, &size))
+ if (!ReadLocalMachineRegistryMultiString (mmKey, L"PagingFiles", pagingFiles, &size))
size = 0;
}
- return size > 0 && strstr (pagingFiles, "?:\\") == pagingFiles;
+ return size > 0 && wcsstr (pagingFiles, L"?:\\") == pagingFiles;
}
BOOL DisablePagingFile ()
{
- char empty[] = { 0, 0 };
- return WriteLocalMachineRegistryMultiString ("System\\CurrentControlSet\\Control\\Session Manager\\Memory Management", "PagingFiles", empty, sizeof (empty));
+ wchar_t empty[] = { 0, 0 };
+ return WriteLocalMachineRegistryMultiString (L"System\\CurrentControlSet\\Control\\Session Manager\\Memory Management", L"PagingFiles", empty, sizeof (empty));
}
@@ -10035,8 +9934,8 @@ BOOL CALLBACK SecurityTokenPasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wPara }
// Attempt to wipe password stored in the input field buffer
- char tmp[SecurityToken::MaxPasswordLength+1];
- memset (tmp, 'X', SecurityToken::MaxPasswordLength);
+ wchar_t tmp[SecurityToken::MaxPasswordLength+1];
+ wmemset (tmp, 'X', SecurityToken::MaxPasswordLength);
tmp[SecurityToken::MaxPasswordLength] = 0;
SetWindowText (GetDlgItem (hwndDlg, IDC_TOKEN_PASSWORD), tmp);
@@ -10162,12 +10061,12 @@ static void SecurityTokenKeyfileDlgFillList (HWND hwndDlg, const vector <Securit lvItem.mask = LVIF_TEXT;
lvItem.iItem = line++;
- stringstream s;
+ wstringstream s;
s << keyfile.SlotId;
- ListItemAdd (tokenListControl, lvItem.iItem, (char *) s.str().c_str());
- ListSubItemSetW (tokenListControl, lvItem.iItem, 1, (wchar_t *) keyfile.Token.Label.c_str());
- ListSubItemSetW (tokenListControl, lvItem.iItem, 2, (wchar_t *) keyfile.Id.c_str());
+ ListItemAdd (tokenListControl, lvItem.iItem, (wchar_t *) s.str().c_str());
+ ListSubItemSet (tokenListControl, lvItem.iItem, 1, (wchar_t *) keyfile.Token.Label.c_str());
+ ListSubItemSet (tokenListControl, lvItem.iItem, 2, (wchar_t *) keyfile.Id.c_str());
}
BOOL selected = (ListView_GetNextItem (GetDlgItem (hwndDlg, IDC_TOKEN_FILE_LIST), -1, LVIS_SELECTED) != -1);
@@ -10293,7 +10192,7 @@ BOOL CALLBACK SecurityTokenKeyfileDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam case IDC_IMPORT_KEYFILE:
{
- char keyfilePath[TC_MAX_PATH];
+ wchar_t keyfilePath[TC_MAX_PATH];
if (BrowseFiles (hwndDlg, "SELECT_KEYFILE", keyfilePath, bHistory, FALSE, NULL))
{
@@ -10308,7 +10207,7 @@ BOOL CALLBACK SecurityTokenKeyfileDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam if (keyfileSize != 0)
{
NewSecurityTokenKeyfileDlgProcParams newParams;
- newParams.Name = WideToUtf8String (SingleStringToWide (keyfilePath));
+ newParams.Name = WideToUtf8String (keyfilePath);
size_t lastBackSlash = newParams.Name.find_last_of ('\\');
if (lastBackSlash != string::npos)
@@ -10356,7 +10255,7 @@ BOOL CALLBACK SecurityTokenKeyfileDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam {
foreach (const SecurityTokenKeyfile &keyfile, SecurityTokenKeyfileDlgGetSelected (hwndDlg, keyfiles))
{
- char keyfilePath[TC_MAX_PATH];
+ wchar_t keyfilePath[TC_MAX_PATH];
if (!BrowseFiles (hwndDlg, "OPEN_TITLE", keyfilePath, bHistory, TRUE, NULL))
break;
@@ -10489,10 +10388,10 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool {
for (int partNumber = 0; partNumber < MAX_HOST_PARTITION_NUMBER; partNumber++)
{
- stringstream strm;
- strm << "\\Device\\Harddisk" << devNumber << "\\Partition" << partNumber;
- string devPathStr (strm.str());
- const char *devPath = devPathStr.c_str();
+ wstringstream strm;
+ strm << L"\\Device\\Harddisk" << devNumber << L"\\Partition" << partNumber;
+ wstring devPathStr (strm.str());
+ const wchar_t *devPath = devPathStr.c_str();
OPEN_TEST_STRUCT openTest = {0};
if (!OpenDevice (devPath, &openTest, detectUnencryptedFilesystems && partNumber != 0))
@@ -10521,20 +10420,18 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool {
DISK_GEOMETRY geometry;
- wstringstream ws;
- ws << devPathStr.c_str();
- int driveNumber = GetDiskDeviceDriveLetter ((wchar_t *) ws.str().c_str());
+ int driveNumber = GetDiskDeviceDriveLetter ((wchar_t *) devPathStr.c_str());
if (driveNumber >= 0)
{
- device.MountPoint += (char) (driveNumber + 'A');
- device.MountPoint += ":";
+ device.MountPoint += (wchar_t) (driveNumber + L'A');
+ device.MountPoint += L":";
wchar_t name[64];
if (GetDriveLabel (driveNumber, name, sizeof (name)))
device.Name = name;
- if (GetSystemDriveLetter() == 'A' + driveNumber)
+ if (GetSystemDriveLetter() == L'A' + driveNumber)
device.ContainsSystem = true;
}
@@ -10584,10 +10481,10 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool {
for (int devNumber = 0; devNumber < 256; devNumber++)
{
- stringstream strm;
- strm << "\\Device\\HarddiskVolume" << devNumber;
- string devPathStr (strm.str());
- const char *devPath = devPathStr.c_str();
+ wstringstream strm;
+ strm << L"\\Device\\HarddiskVolume" << devNumber;
+ wstring devPathStr (strm.str());
+ const wchar_t *devPath = devPathStr.c_str();
OPEN_TEST_STRUCT openTest = {0};
if (!OpenDevice (devPath, &openTest, detectUnencryptedFilesystems))
@@ -10606,20 +10503,18 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool if (!noDeviceProperties)
{
- wstringstream ws;
- ws << devPathStr.c_str();
- int driveNumber = GetDiskDeviceDriveLetter ((wchar_t *) ws.str().c_str());
+ int driveNumber = GetDiskDeviceDriveLetter ((wchar_t *) devPathStr.c_str());
if (driveNumber >= 0)
{
- device.MountPoint += (char) (driveNumber + 'A');
- device.MountPoint += ":";
+ device.MountPoint += (wchar_t) (driveNumber + L'A');
+ device.MountPoint += L":";
wchar_t name[64];
if (GetDriveLabel (driveNumber, name, sizeof (name)))
device.Name = name;
- if (GetSystemDriveLetter() == 'A' + driveNumber)
+ if (GetSystemDriveLetter() == L'A' + driveNumber)
device.ContainsSystem = true;
}
}
@@ -10633,17 +10528,17 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool }
-BOOL FileHasReadOnlyAttribute (const char *path)
+BOOL FileHasReadOnlyAttribute (const wchar_t *path)
{
DWORD attributes = GetFileAttributes (path);
return attributes != INVALID_FILE_ATTRIBUTES && (attributes & FILE_ATTRIBUTE_READONLY) != 0;
}
-BOOL IsFileOnReadOnlyFilesystem (const char *path)
+BOOL IsFileOnReadOnlyFilesystem (const wchar_t *path)
{
- char root[MAX_PATH];
- if (!GetVolumePathName (path, root, sizeof (root)))
+ wchar_t root[MAX_PATH];
+ if (!GetVolumePathName (path, root, ARRAYSIZE (root)))
return FALSE;
DWORD flags, d;
@@ -10657,13 +10552,13 @@ BOOL IsFileOnReadOnlyFilesystem (const char *path) void CheckFilesystem (HWND hwndDlg, int driveNo, BOOL fixErrors)
{
wchar_t msg[1024], param[1024], cmdPath[MAX_PATH];
- char driveRoot[] = { 'A' + (char) driveNo, ':', 0 };
+ wchar_t driveRoot[] = { L'A' + (wchar_t) driveNo, L':', 0 };
if (fixErrors && AskWarnYesNo ("FILESYS_REPAIR_CONFIRM_BACKUP", hwndDlg) == IDNO)
return;
StringCbPrintfW (msg, sizeof(msg), GetString (fixErrors ? "REPAIRING_FS" : "CHECKING_FS"), driveRoot);
- StringCbPrintfW (param, sizeof(param), fixErrors ? L"/C echo %s & chkdsk %hs /F /X & pause" : L"/C echo %s & chkdsk %hs & pause", msg, driveRoot);
+ StringCbPrintfW (param, sizeof(param), fixErrors ? L"/C echo %s & chkdsk %s /F /X & pause" : L"/C echo %s & chkdsk %s & pause", msg, driveRoot);
if (GetSystemDirectoryW(cmdPath, MAX_PATH))
{
@@ -10741,37 +10636,37 @@ int AskNonSysInPlaceEncryptionResume (HWND hwndDlg, BOOL *pbDecrypt) #endif // !SETUP
-BOOL RemoveDeviceWriteProtection (HWND hwndDlg, char *devicePath)
+BOOL RemoveDeviceWriteProtection (HWND hwndDlg, wchar_t *devicePath)
{
int driveNumber;
int partitionNumber;
- char temp[MAX_PATH*2];
- char cmdBatch[MAX_PATH*2];
- char diskpartScript[MAX_PATH*2];
+ wchar_t temp[MAX_PATH*2];
+ wchar_t cmdBatch[MAX_PATH*2];
+ wchar_t diskpartScript[MAX_PATH*2];
- if (sscanf (devicePath, "\\Device\\Harddisk%d\\Partition%d", &driveNumber, &partitionNumber) != 2)
+ if (swscanf (devicePath, L"\\Device\\Harddisk%d\\Partition%d", &driveNumber, &partitionNumber) != 2)
return FALSE;
- if (GetTempPath (sizeof (temp), temp) == 0)
+ if (GetTempPath (ARRAYSIZE (temp), temp) == 0)
return FALSE;
- StringCbPrintfA (cmdBatch, sizeof (cmdBatch), "%s\\VeraCrypt_Write_Protection_Removal.cmd", temp);
- StringCbPrintfA (diskpartScript, sizeof (diskpartScript), "%s\\VeraCrypt_Write_Protection_Removal.diskpart", temp);
+ StringCbPrintfW (cmdBatch, sizeof (cmdBatch), L"%s\\VeraCrypt_Write_Protection_Removal.cmd", temp);
+ StringCbPrintfW (diskpartScript, sizeof (diskpartScript), L"%s\\VeraCrypt_Write_Protection_Removal.diskpart", temp);
- FILE *f = fopen (cmdBatch, "w");
+ FILE *f = _wfopen (cmdBatch, L"w");
if (!f)
{
handleWin32Error (hwndDlg, SRC_POS);
return FALSE;
}
- fprintf (f, "@diskpart /s \"%s\"\n@pause\n@del \"%s\" \"%s\"", diskpartScript, diskpartScript, cmdBatch);
+ fwprintf (f, L"@diskpart /s \"%s\"\n@pause\n@del \"%s\" \"%s\"", diskpartScript, diskpartScript, cmdBatch);
CheckFileStreamWriteErrors (hwndDlg, f, cmdBatch);
fclose (f);
- f = fopen (diskpartScript, "w");
+ f = _wfopen (diskpartScript, L"w");
if (!f)
{
handleWin32Error (hwndDlg, SRC_POS);
@@ -10779,17 +10674,17 @@ BOOL RemoveDeviceWriteProtection (HWND hwndDlg, char *devicePath) return FALSE;
}
- fprintf (f, "select disk %d\nattributes disk clear readonly\n", driveNumber);
+ fwprintf (f, L"select disk %d\nattributes disk clear readonly\n", driveNumber);
if (partitionNumber != 0)
- fprintf (f, "select partition %d\nattributes volume clear readonly\n", partitionNumber);
+ fwprintf (f, L"select partition %d\nattributes volume clear readonly\n", partitionNumber);
- fprintf (f, "exit\n");
+ fwprintf (f, L"exit\n");
CheckFileStreamWriteErrors (hwndDlg, f, diskpartScript);
fclose (f);
- ShellExecute (NULL, (!IsAdmin() && IsUacSupported()) ? "runas" : "open", cmdBatch, NULL, NULL, SW_SHOW);
+ ShellExecute (NULL, (!IsAdmin() && IsUacSupported()) ? L"runas" : L"open", cmdBatch, NULL, NULL, SW_SHOW);
return TRUE;
}
@@ -10846,25 +10741,25 @@ BOOL DisableFileCompression (HANDLE file) }
-BOOL VolumePathExists (const char *volumePath)
+BOOL VolumePathExists (const wchar_t *volumePath)
{
OPEN_TEST_STRUCT openTest = {0};
- char upperCasePath[TC_MAX_PATH + 1];
+ wchar_t upperCasePath[TC_MAX_PATH + 1];
UpperCaseCopy (upperCasePath, sizeof(upperCasePath), volumePath);
- if (strstr (upperCasePath, "\\DEVICE\\") == upperCasePath)
+ if (wcsstr (upperCasePath, L"\\DEVICE\\") == upperCasePath)
return OpenDevice (volumePath, &openTest, FALSE);
- string path = volumePath;
- if (path.find ("\\\\?\\Volume{") == 0 && path.rfind ("}\\") == path.size() - 2)
+ wstring path = volumePath;
+ if (path.find (L"\\\\?\\Volume{") == 0 && path.rfind (L"}\\") == path.size() - 2)
{
- char devicePath[TC_MAX_PATH];
+ wchar_t devicePath[TC_MAX_PATH];
if (QueryDosDevice (path.substr (4, path.size() - 5).c_str(), devicePath, TC_MAX_PATH) != 0)
return TRUE;
}
- if (_access (volumePath, 0) == 0)
+ if (_waccess (volumePath, 0) == 0)
return TRUE;
else
{
@@ -10879,7 +10774,7 @@ BOOL VolumePathExists (const char *volumePath) BOOL IsWindowsIsoBurnerAvailable ()
{
- char path[MAX_PATH*2] = { 0 };
+ wchar_t path[MAX_PATH*2] = { 0 };
if (!IsOSAtLeast (WIN_7))
{
@@ -10888,7 +10783,7 @@ BOOL IsWindowsIsoBurnerAvailable () if (SUCCEEDED(SHGetFolderPath (NULL, CSIDL_SYSTEM, NULL, 0, path)))
{
- StringCbCatA (path, MAX_PATH*2, "\\" ISO_BURNER_TOOL);
+ StringCbCatW (path, MAX_PATH*2, L"\\" ISO_BURNER_TOOL);
return (FileExists (path));
}
@@ -10897,17 +10792,17 @@ BOOL IsWindowsIsoBurnerAvailable () }
-BOOL LaunchWindowsIsoBurner (HWND hwnd, const char *isoPath)
+BOOL LaunchWindowsIsoBurner (HWND hwnd, const wchar_t *isoPath)
{
- char path[MAX_PATH*2] = { 0 };
+ wchar_t path[MAX_PATH*2] = { 0 };
int r;
if (SUCCEEDED(SHGetFolderPath (NULL, CSIDL_SYSTEM, NULL, 0, path)))
- StringCbCatA (path, MAX_PATH*2, "\\" ISO_BURNER_TOOL);
+ StringCbCatW (path, MAX_PATH*2, L"\\" ISO_BURNER_TOOL);
else
- StringCbCopyA (path, MAX_PATH*2, "C:\\Windows\\System32\\" ISO_BURNER_TOOL);
+ StringCbCopyW (path, MAX_PATH*2, L"C:\\Windows\\System32\\" ISO_BURNER_TOOL);
- r = (int) ShellExecute (hwnd, "open", path, (string ("\"") + isoPath + "\"").c_str(), NULL, SW_SHOWNORMAL);
+ r = (int) ShellExecute (hwnd, L"open", path, (wstring (L"\"") + isoPath + L"\"").c_str(), NULL, SW_SHOWNORMAL);
if (r <= 32)
{
@@ -10921,53 +10816,51 @@ BOOL LaunchWindowsIsoBurner (HWND hwnd, const char *isoPath) }
-std::string VolumeGuidPathToDevicePath (std::string volumeGuidPath)
+std::wstring VolumeGuidPathToDevicePath (std::wstring volumeGuidPath)
{
- if (volumeGuidPath.find ("\\\\?\\") == 0)
+ if (volumeGuidPath.find (L"\\\\?\\") == 0)
volumeGuidPath = volumeGuidPath.substr (4);
- if (volumeGuidPath.find ("Volume{") != 0 || volumeGuidPath.rfind ("}\\") != volumeGuidPath.size() - 2)
- return string();
+ if (volumeGuidPath.find (L"Volume{") != 0 || volumeGuidPath.rfind (L"}\\") != volumeGuidPath.size() - 2)
+ return wstring();
- char volDevPath[TC_MAX_PATH];
+ wchar_t volDevPath[TC_MAX_PATH];
if (QueryDosDevice (volumeGuidPath.substr (0, volumeGuidPath.size() - 1).c_str(), volDevPath, TC_MAX_PATH) == 0)
- return string();
+ return wstring();
- string partitionPath = HarddiskVolumePathToPartitionPath (volDevPath);
+ wstring partitionPath = HarddiskVolumePathToPartitionPath (volDevPath);
return partitionPath.empty() ? volDevPath : partitionPath;
}
-std::string HarddiskVolumePathToPartitionPath (const std::string &harddiskVolumePath)
+std::wstring HarddiskVolumePathToPartitionPath (const std::wstring &harddiskVolumePath)
{
- wstring volPath = SingleStringToWide (harddiskVolumePath);
-
for (int driveNumber = 0; driveNumber < MAX_HOST_DRIVE_NUMBER; driveNumber++)
{
for (int partNumber = 0; partNumber < MAX_HOST_PARTITION_NUMBER; partNumber++)
{
wchar_t partitionPath[TC_MAX_PATH];
- swprintf_s (partitionPath, ARRAYSIZE (partitionPath), L"\\Device\\Harddisk%d\\Partition%d", driveNumber, partNumber);
+ StringCchPrintfW (partitionPath, ARRAYSIZE (partitionPath), L"\\Device\\Harddisk%d\\Partition%d", driveNumber, partNumber);
wchar_t resolvedPath[TC_MAX_PATH];
if (ResolveSymbolicLink (partitionPath, resolvedPath, sizeof(resolvedPath)))
{
- if (volPath == resolvedPath)
- return WideToSingleString (partitionPath);
+ if (harddiskVolumePath == resolvedPath)
+ return partitionPath;
}
else if (partNumber == 0)
break;
}
}
- return string();
+ return wstring();
}
-BOOL IsApplicationInstalled (const char *appName, BOOL b32bitApp)
+BOOL IsApplicationInstalled (const wchar_t *appName, BOOL b32bitApp)
{
- const char *uninstallRegName = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
+ const wchar_t *uninstallRegName = L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
BOOL installed = FALSE;
HKEY unistallKey;
LONG res = RegOpenKeyEx (HKEY_LOCAL_MACHINE, uninstallRegName, 0, KEY_READ | b32bitApp? KEY_WOW64_32KEY: KEY_WOW64_64KEY, &unistallKey);
@@ -10977,19 +10870,19 @@ BOOL IsApplicationInstalled (const char *appName, BOOL b32bitApp) return FALSE;
}
- char regName[1024];
+ wchar_t regName[1024];
DWORD regNameSize = sizeof (regName);
DWORD index = 0;
while (RegEnumKeyEx (unistallKey, index++, regName, ®NameSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
{
- if (strstr (regName, "{") == regName)
+ if (wcsstr (regName, L"{") == regName)
{
regNameSize = sizeof (regName);
- if (!ReadLocalMachineRegistryStringNonReflected ((string (uninstallRegName) + "\\" + regName).c_str(), "DisplayName", regName, ®NameSize, b32bitApp))
+ if (!ReadLocalMachineRegistryStringNonReflected ((wstring (uninstallRegName) + L"\\" + regName).c_str(), L"DisplayName", regName, ®NameSize, b32bitApp))
regName[0] = 0;
}
- if (_stricmp (regName, appName) == 0)
+ if (_wcsicmp (regName, appName) == 0)
{
installed = TRUE;
break;
@@ -11003,19 +10896,19 @@ BOOL IsApplicationInstalled (const char *appName, BOOL b32bitApp) }
-std::string FindLatestFileOrDirectory (const std::string &directory, const char *namePattern, bool findDirectory, bool findFile)
+std::wstring FindLatestFileOrDirectory (const std::wstring &directory, const wchar_t *namePattern, bool findDirectory, bool findFile)
{
- string name;
+ wstring name;
ULARGE_INTEGER latestTime;
latestTime.QuadPart = 0;
WIN32_FIND_DATA findData;
- HANDLE find = FindFirstFile ((directory + "\\" + namePattern).c_str(), &findData);
+ HANDLE find = FindFirstFile ((directory + L"\\" + namePattern).c_str(), &findData);
if (find != INVALID_HANDLE_VALUE)
{
do
{
- if (strcmp (findData.cFileName, ".") == 0 || strcmp (findData.cFileName, "..") == 0)
+ if (wcscmp (findData.cFileName, L".") == 0 || wcscmp (findData.cFileName, L"..") == 0)
continue;
ULARGE_INTEGER writeTime;
@@ -11040,7 +10933,7 @@ std::string FindLatestFileOrDirectory (const std::string &directory, const char if (name.empty())
return name;
- return string (directory) + "\\" + name;
+ return wstring (directory) + L"\\" + name;
}
int GetPim (HWND hwndDlg, UINT ctrlId)
@@ -11049,12 +10942,12 @@ int GetPim (HWND hwndDlg, UINT ctrlId) HWND hCtrl = GetDlgItem (hwndDlg, ctrlId);
if (IsWindowEnabled (hCtrl) && IsWindowVisible (hCtrl))
{
- char szTmp[MAX_PIM + 1] = {0};
+ wchar_t szTmp[MAX_PIM + 1] = {0};
if (GetDlgItemText (hwndDlg, ctrlId, szTmp, MAX_PIM + 1) > 0)
{
- char* endPtr = NULL;
- pim = strtol(szTmp, &endPtr, 10);
- if (pim < 0 || endPtr == szTmp || !endPtr || *endPtr != '\0')
+ wchar_t* endPtr = NULL;
+ pim = wcstol(szTmp, &endPtr, 10);
+ if (pim < 0 || endPtr == szTmp || !endPtr || *endPtr != L'\0')
pim = 0;
}
}
@@ -11065,12 +10958,49 @@ void SetPim (HWND hwndDlg, UINT ctrlId, int pim) {
if (pim > 0)
{
- char szTmp[MAX_PIM + 1];
- StringCbPrintfA (szTmp, sizeof(szTmp), "%d", pim);
+ wchar_t szTmp[MAX_PIM + 1];
+ StringCbPrintfW (szTmp, sizeof(szTmp), L"%d", pim);
SetDlgItemText (hwndDlg, ctrlId, szTmp);
}
else
- SetDlgItemText (hwndDlg, ctrlId, "");
+ SetDlgItemText (hwndDlg, ctrlId, L"");
+}
+
+BOOL GetPassword (HWND hwndDlg, UINT ctrlID, char* passValue, int bufSize, BOOL bShowError)
+{
+ wchar_t tmp [MAX_PASSWORD + 1];
+ int utf8Len;
+ BOOL bRet = FALSE;
+
+ GetWindowText (GetDlgItem (hwndDlg, ctrlID), tmp, ARRAYSIZE (tmp));
+ utf8Len = WideCharToMultiByte (CP_UTF8, 0, tmp, -1, passValue, bufSize, NULL, NULL);
+ burn (tmp, sizeof (tmp));
+ if (utf8Len > 0)
+ {
+ bRet = TRUE;
+ }
+ else
+ {
+ passValue [0] = 0;
+ if (bShowError)
+ {
+ SetFocus (GetDlgItem(hwndDlg, ctrlID));
+ if (GetLastError () == ERROR_INSUFFICIENT_BUFFER)
+ Error ("PASSWORD_UTF8_TOO_LONG", hwndDlg);
+ else
+ Error ("PASSWORD_UTF8_INVALID", hwndDlg);
+ }
+ }
+
+ return bRet;
+}
+
+void SetPassword (HWND hwndDlg, UINT ctrlID, char* passValue)
+{
+ wchar_t tmp [MAX_PASSWORD + 1] = {0};
+ MultiByteToWideChar (CP_UTF8, 0, passValue, -1, tmp, MAX_PASSWORD + 1);
+ SetWindowText ( GetDlgItem (hwndDlg, ctrlID), tmp);
+ burn (tmp, sizeof (tmp));
}
void HandleShowPasswordFieldAction (HWND hwndDlg, UINT checkBoxId, UINT edit1Id, UINT edit2Id)
|