diff options
Diffstat (limited to 'src/Main/CommandLineInterface.cpp')
-rw-r--r-- | src/Main/CommandLineInterface.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/Main/CommandLineInterface.cpp b/src/Main/CommandLineInterface.cpp index 2bbc73ea..735cbeef 100644 --- a/src/Main/CommandLineInterface.cpp +++ b/src/Main/CommandLineInterface.cpp @@ -2,72 +2,76 @@ Derived from source code of TrueCrypt 7.1a, which is Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed by the TrueCrypt License 3.0. Modifications and additions to the original source code (contained in this file) and all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ #include "System.h" #include <wx/cmdline.h> #include <wx/tokenzr.h> #include "Core/Core.h" #include "Application.h" #include "CommandLineInterface.h" #include "LanguageStrings.h" #include "UserInterfaceException.h" namespace VeraCrypt { CommandLineInterface::CommandLineInterface (int argc, wchar_t** argv, UserInterfaceType::Enum interfaceType) : ArgCommand (CommandId::None), ArgFilesystem (VolumeCreationOptions::FilesystemType::Unknown), ArgNewPim (-1), ArgNoHiddenVolumeProtection (false), ArgPim (-1), ArgSize (0), ArgVolumeType (VolumeType::Unknown), + ArgAllowScreencapture (false), ArgDisableFileSizeCheck (false), ArgUseLegacyPassword (false), #if defined(TC_LINUX ) || defined (TC_FREEBSD) ArgUseDummySudoPassword (false), #endif StartBackgroundTask (false) { wxCmdLineParser parser; parser.SetCmdLine (argc, argv); parser.SetSwitchChars (L"-"); +#if defined(TC_WINDOWS) || defined(TC_MACOSX) + parser.AddSwitch (L"", L"allow-screencapture", _("Allow window to be included in screenshots and screen captures (Windows/MacOS)")); +#endif parser.AddOption (L"", L"auto-mount", _("Auto mount device-hosted/favorite volumes")); parser.AddSwitch (L"", L"backup-headers", _("Backup volume headers")); parser.AddSwitch (L"", L"background-task", _("Start Background Task")); #ifdef TC_WINDOWS parser.AddSwitch (L"", L"cache", _("Cache passwords and keyfiles")); #endif parser.AddSwitch (L"C", L"change", _("Change password or keyfiles")); parser.AddSwitch (L"c", L"create", _("Create new volume")); parser.AddSwitch (L"", L"create-keyfile", _("Create new keyfile")); parser.AddSwitch (L"", L"delete-token-keyfiles", _("Delete security token keyfiles")); parser.AddSwitch (L"d", L"dismount", _("Dismount volume")); parser.AddSwitch (L"", L"display-password", _("Display password while typing")); parser.AddOption (L"", L"encryption", _("Encryption algorithm")); parser.AddSwitch (L"", L"explore", _("Open explorer window for mounted volume")); parser.AddSwitch (L"", L"export-token-keyfile",_("Export keyfile from token")); parser.AddOption (L"", L"filesystem", _("Filesystem type")); parser.AddSwitch (L"f", L"force", _("Force mount/dismount/overwrite")); #if !defined(TC_WINDOWS) && !defined(TC_MACOSX) parser.AddOption (L"", L"fs-options", _("Filesystem mount options")); #endif parser.AddOption (L"", L"hash", _("Hash algorithm")); parser.AddSwitch (L"h", L"help", _("Display detailed command line help"), wxCMD_LINE_OPTION_HELP); parser.AddSwitch (L"", L"import-token-keyfiles", _("Import keyfiles to security token")); parser.AddOption (L"k", L"keyfiles", _("Keyfiles")); parser.AddSwitch (L"l", L"list", _("List mounted volumes")); parser.AddSwitch (L"", L"list-token-keyfiles", _("List token keyfiles")); parser.AddSwitch (L"", L"list-securitytoken-keyfiles", _("List security token keyfiles")); parser.AddSwitch (L"", L"list-emvtoken-keyfiles", _("List EMV token keyfiles")); parser.AddSwitch (L"", L"load-preferences", _("Load user preferences")); parser.AddSwitch (L"", L"mount", _("Mount volume interactively")); @@ -115,60 +119,65 @@ namespace VeraCrypt if (parser.Parse () > 0) throw_err (_("Incorrect command line specified.")); if (parser.Found (L"help")) { ArgCommand = CommandId::Help; return; } if (parser.Found (L"text") && interfaceType != UserInterfaceType::Text) { wstring msg = wstring (_("Option -t or --text must be specified as the first argument.")); wcerr << msg << endl; throw_err (msg); } if (parser.Found (L"version")) { ArgCommand = CommandId::DisplayVersion; return; } // Preferences if (parser.Found (L"load-preferences")) { // Load preferences first to allow command line options to override them Preferences.Load(); ArgMountOptions = Preferences.DefaultMountOptions; } +#if defined(TC_WINDOWS) || defined(TC_MACOSX) + ArgAllowScreencapture = parser.Found (L"allow-screencapture"); +#else + ArgAllowScreencapture = true; // Protection against screenshots is supported only on Windows and MacOS +#endif // Commands if (parser.Found (L"auto-mount", &str)) { CheckCommandSingle(); wxStringTokenizer tokenizer (str, L","); while (tokenizer.HasMoreTokens()) { wxString token = tokenizer.GetNextToken(); if (token == L"devices") { if (ArgCommand == CommandId::AutoMountFavorites) ArgCommand = CommandId::AutoMountDevicesFavorites; else ArgCommand = CommandId::AutoMountDevices; param1IsMountPoint = true; } else if (token == L"favorites") { if (ArgCommand == CommandId::AutoMountDevices) ArgCommand = CommandId::AutoMountDevicesFavorites; else ArgCommand = CommandId::AutoMountFavorites; } else { throw_err (LangString["UNKNOWN_OPTION"] + L": " + token); } @@ -320,60 +329,70 @@ namespace VeraCrypt #ifdef TC_LINUX else if (str.IsSameAs (L"Ext2", false)) ArgFilesystem = VolumeCreationOptions::FilesystemType::Ext2; else if (str.IsSameAs (L"Ext3", false)) ArgFilesystem = VolumeCreationOptions::FilesystemType::Ext3; else if (str.IsSameAs (L"Ext4", false)) ArgFilesystem = VolumeCreationOptions::FilesystemType::Ext4; else if (str.IsSameAs (L"NTFS", false)) ArgFilesystem = VolumeCreationOptions::FilesystemType::NTFS; else if (str.IsSameAs (L"exFAT", false)) ArgFilesystem = VolumeCreationOptions::FilesystemType::exFAT; else if (str.IsSameAs (L"Btrfs", false)) ArgFilesystem = VolumeCreationOptions::FilesystemType::Btrfs; #elif defined (TC_MACOSX) else if ( str.IsSameAs (L"HFS", false) || str.IsSameAs (L"HFS+", false) || str.IsSameAs (L"MacOsExt", false) ) { ArgFilesystem = VolumeCreationOptions::FilesystemType::MacOsExt; } else if (str.IsSameAs (L"exFAT", false)) ArgFilesystem = VolumeCreationOptions::FilesystemType::exFAT; else if (str.IsSameAs (L"Btrfs", false)) ArgFilesystem = VolumeCreationOptions::FilesystemType::Btrfs; else if (str.IsSameAs (L"APFS", false)) ArgFilesystem = VolumeCreationOptions::FilesystemType::APFS; #elif defined (TC_FREEBSD) || defined (TC_SOLARIS) else if (str.IsSameAs (L"UFS", false)) ArgFilesystem = VolumeCreationOptions::FilesystemType::UFS; + else if (str.IsSameAs (L"Ext2", false)) + ArgFilesystem = VolumeCreationOptions::FilesystemType::Ext2; + else if (str.IsSameAs (L"Ext3", false)) + ArgFilesystem = VolumeCreationOptions::FilesystemType::Ext3; + else if (str.IsSameAs (L"Ext4", false)) + ArgFilesystem = VolumeCreationOptions::FilesystemType::Ext4; + else if (str.IsSameAs (L"NTFS", false)) + ArgFilesystem = VolumeCreationOptions::FilesystemType::NTFS; + else if (str.IsSameAs (L"exFAT", false)) + ArgFilesystem = VolumeCreationOptions::FilesystemType::exFAT; #endif else throw_err (LangString["UNKNOWN_OPTION"] + L": " + str); } } ArgForce = parser.Found (L"force"); ArgDisableFileSizeCheck = parser.Found (L"no-size-check"); ArgUseLegacyPassword = parser.Found (L"legacy-password-maxlength"); #if defined(TC_LINUX ) || defined (TC_FREEBSD) ArgUseDummySudoPassword = parser.Found (L"use-dummy-sudo-password"); #endif #if !defined(TC_WINDOWS) && !defined(TC_MACOSX) if (parser.Found (L"fs-options", &str)) ArgMountOptions.FilesystemOptions = str; #endif if (parser.Found (L"hash", &str)) { ArgHash.reset(); foreach (shared_ptr <Hash> hash, Hash::GetAvailableAlgorithms()) { wxString hashName (hash->GetName()); wxString hashAltName (hash->GetAltName()); if (hashName.IsSameAs (str, false) || hashAltName.IsSameAs (str, false)) ArgHash = hash; } @@ -797,50 +816,50 @@ namespace VeraCrypt if (!mountedVolumeSpec.IsEmpty() && filteredVolumes.size() < 1) throw_err (_("No such volume is mounted.")); return filteredVolumes; } shared_ptr<VolumePassword> ToUTF8Password (const wchar_t* str, size_t charCount, size_t maxUtf8Len) { if (charCount > 0) { shared_ptr<SecureBuffer> utf8Buffer = ToUTF8Buffer (str, charCount, maxUtf8Len); return shared_ptr<VolumePassword>(new VolumePassword (*utf8Buffer)); } else return shared_ptr<VolumePassword>(new VolumePassword ()); } shared_ptr<SecureBuffer> ToUTF8Buffer (const wchar_t* str, size_t charCount, size_t maxUtf8Len) { if (charCount == (size_t) -1) charCount = wcslen (str); if (charCount > 0) { wxMBConvUTF8 utf8; size_t ulen = utf8.FromWChar (NULL, 0, str, charCount); if (wxCONV_FAILED == ulen) throw PasswordUTF8Invalid (SRC_POS); SecureBuffer passwordBuf(ulen); - ulen = utf8.FromWChar ((char*) (byte*) passwordBuf, ulen, str, charCount); + ulen = utf8.FromWChar ((char*) (uint8*) passwordBuf, ulen, str, charCount); if (wxCONV_FAILED == ulen) throw PasswordUTF8Invalid (SRC_POS); if (ulen > maxUtf8Len) { if (maxUtf8Len == VolumePassword::MaxLegacySize) throw PasswordLegacyUTF8TooLong (SRC_POS); else throw PasswordUTF8TooLong (SRC_POS); } - ConstBufferPtr utf8Buffer ((byte*) passwordBuf, ulen); + ConstBufferPtr utf8Buffer ((uint8*) passwordBuf, ulen); return shared_ptr<SecureBuffer>(new SecureBuffer (utf8Buffer)); } else return shared_ptr<SecureBuffer>(new SecureBuffer ()); } unique_ptr <CommandLineInterface> CmdLine; } |