Skip to content

Commit

Permalink
Windows: Fix failure to create Traveler Disk when VeraCrypt is instal…
Browse files Browse the repository at this point in the history
…led using MSI
  • Loading branch information
idrassi committed Feb 2, 2022
1 parent 06841f6 commit ebb6749
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 59 deletions.
188 changes: 129 additions & 59 deletions src/Mount/Mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -4791,85 +4791,155 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
{
int fileNo = 0;
// get file from the Setup binary after checking its signature and its version
StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\VeraCrypt Setup.exe", appDir);

FreeAllFileBuffers ();

if (!VerifyPackageIntegrity (srcPath) || !SelfExtractInMemory (srcPath))
{
MessageBoxW (hwndDlg, GetString ("DIST_PACKAGE_CORRUPTED"), lpszTitle, MB_ICONEXCLAMATION);
goto stop;
}

for (fileNo = 0; fileNo < NBR_COMPRESSED_FILES; fileNo++)
StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\VeraCrypt COMReg.exe", appDir); // MSI installation case
if (FileExists(srcPath))
{
wchar_t fileName [TC_MAX_PATH] = {0};
// we copy only our binaries since we don't have those of the other platforms

// Filename
StringCchCopyNW (fileName, ARRAYSIZE(fileName), Decompressed_Files[fileNo].fileName, Decompressed_Files[fileNo].fileNameLength);

if (wcscmp (fileName, L"VeraCrypt.exe") == 0)
{
StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCrypt.exe", dstDir);
}
else if (wcscmp (fileName, L"VeraCrypt-x64.exe") == 0)
{
StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCrypt-x64.exe", dstDir);
}
else if (wcscmp(fileName, L"VeraCrypt-arm64.exe") == 0)
{
StringCbPrintfW(dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCrypt-arm64.exe", dstDir);
}
else if (wcscmp (fileName, L"veracrypt.sys") == 0)
{
StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\veracrypt.sys", dstDir);
}
else if (wcscmp (fileName, L"veracrypt-x64.sys") == 0)
// Main app
StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\VeraCrypt.exe", appDir);
StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCrypt.exe", dstDir);
if (!VerifyModuleSignature (srcPath))
{
StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\veracrypt-x64.sys", dstDir);
Error ("DIST_PACKAGE_CORRUPTED", hwndDlg);
goto stop;
}
else if (wcscmp(fileName, L"veracrypt-arm64.sys") == 0)
else if (!TCCopyFile (srcPath, dstPath))
{
StringCbPrintfW(dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\veracrypt-arm64.sys", dstDir);
handleWin32Error (hwndDlg, SRC_POS);
goto stop;
}
else if (copyWizard && (wcscmp (fileName, L"VeraCrypt Format.exe") == 0))

// Wizard
if (copyWizard)
{
StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\VeraCrypt Format.exe", appDir);
StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCrypt Format.exe", dstDir);
if (!VerifyModuleSignature (srcPath))
{
Error ("DIST_PACKAGE_CORRUPTED", hwndDlg);
goto stop;
}
else if (!TCCopyFile (srcPath, dstPath))
{
handleWin32Error (hwndDlg, SRC_POS);
goto stop;
}
}
else if (copyWizard && (wcscmp (fileName, L"VeraCrypt Format-x64.exe") == 0))
{
StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCrypt Format-x64.exe", dstDir);
}
else if (copyWizard && (wcscmp(fileName, L"VeraCrypt Format-arm64.exe") == 0))

// Expander
if (copyExpander)
{
StringCbPrintfW(dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCrypt Format-arm64.exe", dstDir);
StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\VeraCryptExpander.exe", appDir);
StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCryptExpander.exe", dstDir);
if (!VerifyModuleSignature (srcPath))
{
Error ("DIST_PACKAGE_CORRUPTED", hwndDlg);
goto stop;
}
else if (!TCCopyFile (srcPath, dstPath))
{
handleWin32Error (hwndDlg, SRC_POS);
goto stop;
}
}
else if (copyExpander && (wcscmp (fileName, L"VeraCryptExpander.exe") == 0))

// Driver
StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\veracrypt.sys", appDir);
StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\veracrypt.sys", dstDir);
if (!VerifyModuleSignature (srcPath))
{
StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCryptExpander.exe", dstDir);
Error ("DIST_PACKAGE_CORRUPTED", hwndDlg);
goto stop;
}
else if (copyExpander && (wcscmp (fileName, L"VeraCryptExpander-x64.exe") == 0))
else if (!TCCopyFile (srcPath, dstPath))
{
StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCryptExpander-x64.exe", dstDir);
handleWin32Error (hwndDlg, SRC_POS);
goto stop;
}
else if (copyExpander && (wcscmp(fileName, L"VeraCryptExpander-arm64.exe") == 0))
}
else
{
StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\VeraCrypt Setup.exe", appDir); // EXE installation case

FreeAllFileBuffers ();

if (!VerifyPackageIntegrity (srcPath) || !SelfExtractInMemory (srcPath))
{
StringCbPrintfW(dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCryptExpander-arm64.exe", dstDir);
MessageBoxW (hwndDlg, GetString ("DIST_PACKAGE_CORRUPTED"), lpszTitle, MB_ICONEXCLAMATION);
goto stop;
}
else
continue;

if (!SaveBufferToFile (
(char *) Decompressed_Files[fileNo].fileContent,
dstPath,
Decompressed_Files[fileNo].fileLength,
FALSE, FALSE))
for (fileNo = 0; fileNo < NBR_COMPRESSED_FILES; fileNo++)
{
wchar_t szTmp[512];
wchar_t fileName [TC_MAX_PATH] = {0};

StringCbPrintfW (szTmp, sizeof (szTmp), GetString ("CANNOT_WRITE_FILE_X"), dstPath);
MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST);
goto stop;
// Filename
StringCchCopyNW (fileName, ARRAYSIZE(fileName), Decompressed_Files[fileNo].fileName, Decompressed_Files[fileNo].fileNameLength);

if (wcscmp (fileName, L"VeraCrypt.exe") == 0)
{
StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCrypt.exe", dstDir);
}
else if (wcscmp (fileName, L"VeraCrypt-x64.exe") == 0)
{
StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCrypt-x64.exe", dstDir);
}
else if (wcscmp(fileName, L"VeraCrypt-arm64.exe") == 0)
{
StringCbPrintfW(dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCrypt-arm64.exe", dstDir);
}
else if (wcscmp (fileName, L"veracrypt.sys") == 0)
{
StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\veracrypt.sys", dstDir);
}
else if (wcscmp (fileName, L"veracrypt-x64.sys") == 0)
{
StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\veracrypt-x64.sys", dstDir);
}
else if (wcscmp(fileName, L"veracrypt-arm64.sys") == 0)
{
StringCbPrintfW(dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\veracrypt-arm64.sys", dstDir);
}
else if (copyWizard && (wcscmp (fileName, L"VeraCrypt Format.exe") == 0))
{
StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCrypt Format.exe", dstDir);
}
else if (copyWizard && (wcscmp (fileName, L"VeraCrypt Format-x64.exe") == 0))
{
StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCrypt Format-x64.exe", dstDir);
}
else if (copyWizard && (wcscmp(fileName, L"VeraCrypt Format-arm64.exe") == 0))
{
StringCbPrintfW(dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCrypt Format-arm64.exe", dstDir);
}
else if (copyExpander && (wcscmp (fileName, L"VeraCryptExpander.exe") == 0))
{
StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCryptExpander.exe", dstDir);
}
else if (copyExpander && (wcscmp (fileName, L"VeraCryptExpander-x64.exe") == 0))
{
StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCryptExpander-x64.exe", dstDir);
}
else if (copyExpander && (wcscmp(fileName, L"VeraCryptExpander-arm64.exe") == 0))
{
StringCbPrintfW(dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\VeraCryptExpander-arm64.exe", dstDir);
}
else
continue;

if (!SaveBufferToFile (
(char *) Decompressed_Files[fileNo].fileContent,
dstPath,
Decompressed_Files[fileNo].fileLength,
FALSE, FALSE))
{
wchar_t szTmp[512];

StringCbPrintfW (szTmp, sizeof (szTmp), GetString ("CANNOT_WRITE_FILE_X"), dstPath);
MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST);
goto stop;
}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/SetupDLL/Setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -2743,6 +2743,13 @@ EXTERN_C UINT STDAPICALLTYPE VC_CustomAction_PostInstall(MSIHANDLE hInstaller)
HANDLE h;
wchar_t szTmp[TC_MAX_PATH];

// delete "VeraCrypt Setup.exe" if it exists
StringCbPrintfW (szTmp, sizeof(szTmp), L"%s%s", szInstallDir.c_str(), L"VeraCrypt Setup.exe");
if (FileExists(szTmp))
{
ForceDeleteFile(szTmp);
}

StringCbPrintfW (szTmp, sizeof(szTmp), L"%s%s", szInstallDir.c_str(), L"VeraCrypt.exe");

if (Is64BitOs ())
Expand Down

0 comments on commit ebb6749

Please sign in to comment.