diff --git a/src/Core/Unix/CoreService.cpp b/src/Core/Unix/CoreService.cpp index 0641644c..177ffbda 100644 --- a/src/Core/Unix/CoreService.cpp +++ b/src/Core/Unix/CoreService.cpp @@ -432,28 +432,14 @@ namespace VeraCrypt #if defined(TC_LINUX) // AppImage specific handling: - // If running from an AppImage, and appPath is inside the AppImage's mount point (APPDIR), - // and APPDIR has the expected prefix, then use the AppImage file path (APPIMAGE) for sudo. + // If running from an AppImage, use the path to the AppImage file itself for sudo. const char* appImageEnv = getenv("APPIMAGE"); - const char* appDirEnv = getenv("APPDIR"); - if (appImageEnv && appDirEnv) - { - string appDirString = appDirEnv; - string appImageFileString = appImageEnv; - const string appImageMountPrefix = "/tmp/.mount_Veracr"; // Based on observed "/tmp/.mount_VeracrXXXXXX" - - // Check: APPDIR is not empty, - // appPath starts with APPDIR, - // and APPDIR itself starts with the expected AppImage mount prefix - if (!appDirString.empty() && - appPath.rfind(appDirString, 0) == 0 && - appDirString.rfind(appImageMountPrefix, 0) == 0) - { - // All conditions met, this is the AppImage scenario. - // Use the path to the AppImage file itself for sudo. - appPath = appImageFileString; - } + if (Process::IsRunningUnderAppImage(appPath) && appImageEnv != NULL) + { + // The path to the AppImage file is stored in the APPIMAGE environment variable. + // We need to use this path for sudo to work correctly. + appPath = appImageEnv; } #endif throw_sys_if (dup2 (inPipe->GetReadFD(), STDIN_FILENO) == -1); diff --git a/src/Main/GraphicUserInterface.cpp b/src/Main/GraphicUserInterface.cpp index ab028e73..14771b23 100644 --- a/src/Main/GraphicUserInterface.cpp +++ b/src/Main/GraphicUserInterface.cpp @@ -1354,6 +1354,21 @@ namespace VeraCrypt htmlPath += L"/../Resources/doc/HTML/"; #elif defined (TC_UNIX) htmlPath = L"/usr/share/doc/veracrypt/HTML/"; +#if defined(TC_LINUX) + // AppImage specific handling: + // if we are running from an AppImage, we need to use the path inside the AppImage + // instead of the path on the host system + std::string appPath= StringConverter::ToSingle (wstring(Application::GetExecutablePath())); + if (Process::IsRunningUnderAppImage(appPath)) + { + const char* appDirEnv = getenv("APPDIR"); + if (appDirEnv) + { + htmlPath = wxString::FromUTF8(appDirEnv); + htmlPath += "/usr/share/doc/veracrypt/HTML/"; + } + } +#endif #else localFile = false; #endif diff --git a/src/Platform/Unix/Process.cpp b/src/Platform/Unix/Process.cpp index 395d4bc9..bedd8599 100644 --- a/src/Platform/Unix/Process.cpp +++ b/src/Platform/Unix/Process.cpp @@ -263,4 +263,36 @@ namespace VeraCrypt return strOutput; } + +#if defined(TC_LINUX) + bool Process::IsRunningUnderAppImage (const string &executablePath) + { + if (executablePath.empty()) + return false; + + // AppImage detection logic: + // Check that APPIMAGE and APPDIR environment variables are set + // Check that the executable path starts with APPDIR + // Check that APPDIR itself starts with the expected AppImage mount prefix + const char* appImageEnv = getenv("APPIMAGE"); + const char* appDirEnv = getenv("APPDIR"); + + if (appImageEnv && appDirEnv) + { + string appDirString = appDirEnv; + string appImageFileString = appImageEnv; + const string appImageMountPrefix1 = "/tmp/.mount_Veracr"; + const string appImageMountPrefix2 = "/tmp/.mount_VeraCr"; + + if (!appDirString.empty() && + executablePath.rfind(appDirString, 0) == 0 && + (appDirString.rfind(appImageMountPrefix1, 0) == 0 || appDirString.rfind(appImageMountPrefix2, 0) == 0)) + { + // All conditions met, this is the AppImage scenario. + return true; + } + } + return false; + } +#endif } diff --git a/src/Platform/Unix/Process.h b/src/Platform/Unix/Process.h index 83215956..7c08d326 100644 --- a/src/Platform/Unix/Process.h +++ b/src/Platform/Unix/Process.h @@ -34,6 +34,9 @@ namespace VeraCrypt static bool IsExecutable(const std::string& path); static std::string FindSystemBinary(const char* name, std::string& errorMsg); static string Execute (const string &processName, const list &arguments, int timeOut = -1, ProcessExecFunctor *execFunctor = nullptr, const Buffer *inputData = nullptr); +#if defined(TC_LINUX) + static bool IsRunningUnderAppImage (const string &executablePath); +#endif protected: