diff --git a/src/Common/SCard.cpp b/src/Common/SCard.cpp index edd315f6ea..9f8d11458a 100644 --- a/src/Common/SCard.cpp +++ b/src/Common/SCard.cpp @@ -6,7 +6,7 @@ namespace VeraCrypt { SCardManager SCard::manager; - SCard::SCard() + SCard::SCard() : m_reader(NULL) { } diff --git a/src/Common/SCardLoader.cpp b/src/Common/SCardLoader.cpp index 244860027a..16026e62e5 100644 --- a/src/Common/SCardLoader.cpp +++ b/src/Common/SCardLoader.cpp @@ -320,7 +320,7 @@ namespace VeraCrypt return scardStatus(hCard, mszReaderNames, pcchReaderLen, pdwState, pdwProtocol, pbAtr, pcbAtrLen); } - LONG SCardLoader::SCardGetStatusChange(SCARDCONTEXT hContext, DWORD dwTimeout, SCARD_READERSTATE* rgReaderStates, DWORD cReaders) + LONG SCardLoader::SCardGetStatusChange(SCARDCONTEXT hContext, DWORD dwTimeout, LPSCARD_READERSTATE rgReaderStates, DWORD cReaders) { Initialize(); @@ -399,4 +399,4 @@ namespace VeraCrypt return scardSetAttrib(hCard, dwAttrId, pbAttr, cbAttrLen); } -} +} \ No newline at end of file diff --git a/src/Common/SCardLoader.h b/src/Common/SCardLoader.h index af0758ed86..a7243d826a 100644 --- a/src/Common/SCardLoader.h +++ b/src/Common/SCardLoader.h @@ -13,6 +13,8 @@ #include #include #include "reader.h" +typedef LPSCARD_READERSTATE_A LPSCARD_READERSTATE; +using VeraCrypt::uint8; #define BOOL int #else #undef BOOL @@ -20,6 +22,7 @@ #include #include #include +using VeraCrypt::uint8; #define BOOL int #endif #endif @@ -45,7 +48,7 @@ namespace VeraCrypt typedef LONG (SCARD_CALL_SPEC *SCardBeginTransactionPtr)(SCARDHANDLE hCard); typedef LONG (SCARD_CALL_SPEC *SCardEndTransactionPtr)(SCARDHANDLE hCard, DWORD dwDisposition); typedef LONG (SCARD_CALL_SPEC *SCardStatusPtr)(SCARDHANDLE hCard, LPTSTR mszReaderNames, LPDWORD pcchReaderLen, LPDWORD pdwState, LPDWORD pdwProtocol, BYTE* pbAtr, LPDWORD pcbAtrLen); - typedef LONG (SCARD_CALL_SPEC *SCardGetStatusChangePtr)(SCARDCONTEXT hContext, DWORD dwTimeout, SCARD_READERSTATE* rgReaderStates, DWORD cReaders); + typedef LONG (SCARD_CALL_SPEC *SCardGetStatusChangePtr)(SCARDCONTEXT hContext, DWORD dwTimeout, LPSCARD_READERSTATE rgReaderStates, DWORD cReaders); typedef LONG (SCARD_CALL_SPEC *SCardControlPtr)(SCARDHANDLE hCard, DWORD dwControlCode, LPCVOID pbSendBuffer, DWORD cbSendLength, LPVOID pbRecvBuffer, DWORD cbRecvLength, LPDWORD lpBytesReturned); typedef LONG (SCARD_CALL_SPEC *SCardTransmitPtr)(SCARDHANDLE hCard, LPCSCARD_IO_REQUEST pioSendPci, const BYTE* pbSendBuffer, DWORD cbSendLength, LPSCARD_IO_REQUEST pioRecvPci, BYTE* pbRecvBuffer, LPDWORD pcbRecvLength); typedef LONG (SCARD_CALL_SPEC *SCardListReaderGroupsPtr)(SCARDCONTEXT hContext, LPTSTR mszGroups, LPDWORD pcchGroups); @@ -108,7 +111,7 @@ namespace VeraCrypt static LONG SCardBeginTransaction(SCARDHANDLE hCard); static LONG SCardEndTransaction(SCARDHANDLE hCard, DWORD dwDisposition); static LONG SCardStatus(SCARDHANDLE hCard, LPTSTR mszReaderNames, LPDWORD pcchReaderLen, LPDWORD pdwState, LPDWORD pdwProtocol, BYTE* pbAtr, LPDWORD pcbAtrLen); - static LONG SCardGetStatusChange(SCARDCONTEXT hContext, DWORD dwTimeout, SCARD_READERSTATE* rgReaderStates, DWORD cReaders); + static LONG SCardGetStatusChange(SCARDCONTEXT hContext, DWORD dwTimeout, LPSCARD_READERSTATE rgReaderStates, DWORD cReaders); static LONG SCardControl(SCARDHANDLE hCard, DWORD dwControlCode, LPCVOID pbSendBuffer, DWORD cbSendLength, LPVOID pbRecvBuffer, DWORD cbRecvLength, LPDWORD lpBytesReturned); static LONG SCardTransmit(SCARDHANDLE hCard, LPCSCARD_IO_REQUEST pioSendPci, const BYTE* pbSendBuffer, DWORD cbSendLength, LPSCARD_IO_REQUEST pioRecvPci, BYTE* pbRecvBuffer, LPDWORD pcbRecvLength); static LONG SCardListReaderGroups(SCARDCONTEXT hContext, LPTSTR mszGroups, LPDWORD pcchGroups); @@ -119,4 +122,4 @@ namespace VeraCrypt }; }; -#endif // TC_HEADER_Common_SCardLoader +#endif // TC_HEADER_Common_SCardLoader \ No newline at end of file diff --git a/src/Common/SCardReader.cpp b/src/Common/SCardReader.cpp index 6c5f654ac2..de269ce601 100644 --- a/src/Common/SCardReader.cpp +++ b/src/Common/SCardReader.cpp @@ -17,7 +17,7 @@ namespace VeraCrypt } else { - m_scardLoader.reset(); + m_scardLoader = NULL; m_hSCReaderContext = 0; } m_hCard = hCard; @@ -84,7 +84,7 @@ namespace VeraCrypt void SCardReader::Clear(void) { m_szSCReaderName = L""; - m_scardLoader.reset(); + m_scardLoader = NULL; m_hSCReaderContext = 0; m_hCard = 0; m_dwProtocol = 0; diff --git a/src/Common/TLVParser.cpp b/src/Common/TLVParser.cpp index 5ddf37e520..1e51739caa 100644 --- a/src/Common/TLVParser.cpp +++ b/src/Common/TLVParser.cpp @@ -169,7 +169,7 @@ namespace VeraCrypt shared_ptr TLVParser::TLV_Find(shared_ptr node, uint16 tag) { size_t i = 0; - shared_ptr tmpnode; + shared_ptr tmpnode = NULL; if (node->Tag == tag) { return node; @@ -177,11 +177,11 @@ namespace VeraCrypt for (i = 0; i < node->Subs->size(); i++) { tmpnode = TLV_Find(node->Subs->at(i),tag); - if (tmpnode) + if (tmpnode != NULL) { return tmpnode; } } - return shared_ptr(); + return NULL; } -} +} \ No newline at end of file diff --git a/src/Main/Forms/PreferencesDialog.cpp b/src/Main/Forms/PreferencesDialog.cpp index afc2871fd1..c4d5140f51 100644 --- a/src/Main/Forms/PreferencesDialog.cpp +++ b/src/Main/Forms/PreferencesDialog.cpp @@ -82,51 +82,6 @@ namespace VeraCrypt LanguageListBox->Append("System default"); LanguageListBox->Append("English"); - langEntries = { - {"system", L"System default"}, - {"ar", L"العربية"}, - {"be", L"Беларуская"}, - {"bg", L"Български"}, - {"ca", L"Català"}, - {"co", L"Corsu"}, - {"cs", L"Čeština"}, - {"da", L"Dansk"}, - {"de", L"Deutsch"}, - {"el", L"Ελληνικά"}, - {"en", L"English"}, - {"es", L"Español"}, - {"et", L"Eesti"}, - {"eu", L"Euskara"}, - {"fa", L"فارسي"}, - {"fi", L"Suomi"}, - {"fr", L"Français"}, - {"he", L"עברית"}, - {"hu", L"Magyar"}, - {"id", L"Bahasa Indonesia"}, - {"it", L"Italiano"}, - {"ja", L"日本語"}, - {"ka", L"ქართული"}, - {"ko", L"한국어"}, - {"lv", L"Latviešu"}, - {"nl", L"Nederlands"}, - {"nn", L"Norsk Nynorsk"}, - {"pl", L"Polski"}, - {"ro", L"Română"}, - {"ru", L"Русский"}, - {"pt-br", L"Português-Brasil"}, - {"sk", L"Slovenčina"}, - {"sl", L"Slovenščina"}, - {"sv", L"Svenska"}, - {"th", L"ภาษาไทย"}, - {"tr", L"Türkçe"}, - {"uk", L"Українська"}, - {"uz", L"Ўзбекча"}, - {"vi", L"Tiếng Việt"}, - {"zh-cn", L"简体中文"}, - {"zh-hk", L"繁體中文(香港)"}, - {"zh-tw", L"繁體中文"} - }; - if (wxDir::Exists(languagesFolder.GetName())) { size_t langCount; langCount = wxDir::GetAllFiles(languagesFolder.GetName(), &langArray, wxEmptyString, wxDIR_FILES); @@ -480,11 +435,11 @@ namespace VeraCrypt if (LanguageListBox->GetSelection() != wxNOT_FOUND) { wxString langToFind = LanguageListBox->GetString(LanguageListBox->GetSelection()); - for (map::const_iterator each = langEntries.begin(); each != langEntries.end(); ++each) { - if (each->second == langToFind) { - Preferences.Language = each->first; + for (const auto &each: langEntries) { + if (each.second == langToFind) { + Preferences.Language = each.first; #ifdef DEBUG - cout << "Lang set to: " << each->first << endl; + cout << "Lang set to: " << each.first << endl; #endif } } diff --git a/src/Main/Forms/PreferencesDialog.h b/src/Main/Forms/PreferencesDialog.h index 5e7f7e71c3..50e8489efc 100644 --- a/src/Main/Forms/PreferencesDialog.h +++ b/src/Main/Forms/PreferencesDialog.h @@ -60,7 +60,50 @@ namespace VeraCrypt UserPreferences Preferences; bool RestoreValidatorBell; HotkeyList UnregisteredHotkeys; - map langEntries; + map langEntries = { + {"system", L"System default"}, + {"ar", L"العربية"}, + {"be", L"Беларуская"}, + {"bg", L"Български"}, + {"ca", L"Català"}, + {"co", L"Corsu"}, + {"cs", L"Čeština"}, + {"da", L"Dansk"}, + {"de", L"Deutsch"}, + {"el", L"Ελληνικά"}, + {"en", L"English"}, + {"es", L"Español"}, + {"et", L"Eesti"}, + {"eu", L"Euskara"}, + {"fa", L"فارسي"}, + {"fi", L"Suomi"}, + {"fr", L"Français"}, + {"he", L"עברית"}, + {"hu", L"Magyar"}, + {"id", L"Bahasa Indonesia"}, + {"it", L"Italiano"}, + {"ja", L"日本語"}, + {"ka", L"ქართული"}, + {"ko", L"한국어"}, + {"lv", L"Latviešu"}, + {"nl", L"Nederlands"}, + {"nn", L"Norsk Nynorsk"}, + {"pl", L"Polski"}, + {"ro", L"Română"}, + {"ru", L"Русский"}, + {"pt-br", L"Português-Brasil"}, + {"sk", L"Slovenčina"}, + {"sl", L"Slovenščina"}, + {"sv", L"Svenska"}, + {"th", L"ภาษาไทย"}, + {"tr", L"Türkçe"}, + {"uk", L"Українська"}, + {"uz", L"Ўзбекча"}, + {"vi", L"Tiếng Việt"}, + {"zh-cn", L"简体中文"}, + {"zh-hk", L"繁體中文(香港)"}, + {"zh-tw", L"繁體中文"} + }; }; } diff --git a/src/Main/Forms/VolumeCreationWizard.cpp b/src/Main/Forms/VolumeCreationWizard.cpp index 311738ca67..3f09e39f3d 100644 --- a/src/Main/Forms/VolumeCreationWizard.cpp +++ b/src/Main/Forms/VolumeCreationWizard.cpp @@ -37,19 +37,6 @@ namespace VeraCrypt { - class OpenOuterVolumeFunctor : public Functor - { - public: - OpenOuterVolumeFunctor (const DirectoryPath &outerVolumeMountPoint) : OuterVolumeMountPoint (outerVolumeMountPoint) { } - - virtual void operator() () - { - Gui->OpenExplorerWindow (OuterVolumeMountPoint); - } - - DirectoryPath OuterVolumeMountPoint; - }; - #ifdef TC_MACOSX bool VolumeCreationWizard::ProcessEvent(wxEvent& event) @@ -351,6 +338,18 @@ namespace VeraCrypt return new InfoWizardPage (GetPageParent()); } + struct OpenOuterVolumeFunctor : public Functor + { + OpenOuterVolumeFunctor (const DirectoryPath &outerVolumeMountPoint) : OuterVolumeMountPoint (outerVolumeMountPoint) { } + + virtual void operator() () + { + Gui->OpenExplorerWindow (OuterVolumeMountPoint); + } + + DirectoryPath OuterVolumeMountPoint; + }; + InfoWizardPage *page = new InfoWizardPage (GetPageParent(), LangString["LINUX_OPEN_OUTER_VOL"], shared_ptr (new OpenOuterVolumeFunctor (MountedOuterVolume->MountPoint))); diff --git a/src/Main/GraphicUserInterface.cpp b/src/Main/GraphicUserInterface.cpp index 0fd756a36d..af2db2176b 100644 --- a/src/Main/GraphicUserInterface.cpp +++ b/src/Main/GraphicUserInterface.cpp @@ -37,33 +37,6 @@ namespace VeraCrypt { - class AdminPasswordRequestHandler : public GetStringFunctor - { - public: - virtual void operator() (string &passwordStr) - { - - wxString sValue; - if (Gui->GetWaitDialog()) - { - Gui->GetWaitDialog()->RequestAdminPassword(sValue); - if (sValue.IsEmpty()) - throw UserAbort (SRC_POS); - } - else - { - wxPasswordEntryDialog dialog (Gui->GetActiveWindow(), LangString["LINUX_ADMIN_PW_QUERY"], LangString["LINUX_ADMIN_PW_QUERY_TITLE"]); - if (dialog.ShowModal() != wxID_OK) - throw UserAbort (SRC_POS); - sValue = dialog.GetValue(); - } - wstring wPassword (sValue); // A copy of the password is created here by wxWidgets, which cannot be erased - finally_do_arg (wstring *, &wPassword, { StringConverter::Erase (*finally_arg); }); - - StringConverter::ToSingle (wPassword, passwordStr); - } - }; - #ifdef TC_MACOSX int GraphicUserInterface::g_customIdCmdV = 0; int GraphicUserInterface::g_customIdCmdA = 0; @@ -479,6 +452,32 @@ namespace VeraCrypt shared_ptr GraphicUserInterface::GetAdminPasswordRequestHandler () { + struct AdminPasswordRequestHandler : public GetStringFunctor + { + virtual void operator() (string &passwordStr) + { + + wxString sValue; + if (Gui->GetWaitDialog()) + { + Gui->GetWaitDialog()->RequestAdminPassword(sValue); + if (sValue.IsEmpty()) + throw UserAbort (SRC_POS); + } + else + { + wxPasswordEntryDialog dialog (Gui->GetActiveWindow(), LangString["LINUX_ADMIN_PW_QUERY"], LangString["LINUX_ADMIN_PW_QUERY_TITLE"]); + if (dialog.ShowModal() != wxID_OK) + throw UserAbort (SRC_POS); + sValue = dialog.GetValue(); + } + wstring wPassword (sValue); // A copy of the password is created here by wxWidgets, which cannot be erased + finally_do_arg (wstring *, &wPassword, { StringConverter::Erase (*finally_arg); }); + + StringConverter::ToSingle (wPassword, passwordStr); + } + }; + return shared_ptr (new AdminPasswordRequestHandler); } diff --git a/src/Main/StringFormatter.h b/src/Main/StringFormatter.h index d7f64dd032..97c39ae22b 100644 --- a/src/Main/StringFormatter.h +++ b/src/Main/StringFormatter.h @@ -52,10 +52,7 @@ namespace VeraCrypt StringFormatter (const wxString &format, StringFormatterArg arg0 = StringFormatterArg(), StringFormatterArg arg1 = StringFormatterArg(), StringFormatterArg arg2 = StringFormatterArg(), StringFormatterArg arg3 = StringFormatterArg(), StringFormatterArg arg4 = StringFormatterArg(), StringFormatterArg arg5 = StringFormatterArg(), StringFormatterArg arg6 = StringFormatterArg(), StringFormatterArg arg7 = StringFormatterArg(), StringFormatterArg arg8 = StringFormatterArg(), StringFormatterArg arg9 = StringFormatterArg()); virtual ~StringFormatter (); -#if (__cplusplus >= 201103L) - explicit -#endif - operator wstring () const { return wstring (FormattedString); } + explicit operator wstring () const { return wstring (FormattedString); } operator wxString () const { return FormattedString; } operator StringFormatterArg () const { return FormattedString; } diff --git a/src/Main/TextUserInterface.cpp b/src/Main/TextUserInterface.cpp index 46559dfaf5..3346ee3ef9 100644 --- a/src/Main/TextUserInterface.cpp +++ b/src/Main/TextUserInterface.cpp @@ -30,27 +30,6 @@ namespace VeraCrypt { - class AdminPasswordRequestHandler : public GetStringFunctor - { - public: - AdminPasswordRequestHandler (TextUserInterface *userInterface) : UI (userInterface) { } - virtual void operator() (string &passwordStr) - { - UI->ShowString (_("Enter your user password or administrator password: ")); - - TextUserInterface::SetTerminalEcho (false); - finally_do ({ TextUserInterface::SetTerminalEcho (true); }); - - wstring wPassword (UI->ReadInputStreamLine()); - finally_do_arg (wstring *, &wPassword, { StringConverter::Erase (*finally_arg); }); - - UI->ShowString (L"\n"); - - StringConverter::ToSingle (wPassword, passwordStr); - } - TextUserInterface *UI; - }; - TextUserInterface::TextUserInterface () { #ifdef TC_UNIX @@ -1116,6 +1095,26 @@ namespace VeraCrypt shared_ptr TextUserInterface::GetAdminPasswordRequestHandler () { + struct AdminPasswordRequestHandler : public GetStringFunctor + { + AdminPasswordRequestHandler (TextUserInterface *userInterface) : UI (userInterface) { } + virtual void operator() (string &passwordStr) + { + UI->ShowString (_("Enter your user password or administrator password: ")); + + TextUserInterface::SetTerminalEcho (false); + finally_do ({ TextUserInterface::SetTerminalEcho (true); }); + + wstring wPassword (UI->ReadInputStreamLine()); + finally_do_arg (wstring *, &wPassword, { StringConverter::Erase (*finally_arg); }); + + UI->ShowString (L"\n"); + + StringConverter::ToSingle (wPassword, passwordStr); + } + TextUserInterface *UI; + }; + return shared_ptr (new AdminPasswordRequestHandler (this)); } diff --git a/src/Main/TextUserInterface.h b/src/Main/TextUserInterface.h index 44494f32b4..becb1d5986 100644 --- a/src/Main/TextUserInterface.h +++ b/src/Main/TextUserInterface.h @@ -19,11 +19,9 @@ namespace VeraCrypt { - class AdminPasswordRequestHandler; class TextUserInterface : public UserInterface { public: - friend class AdminPasswordRequestHandler; TextUserInterface (); virtual ~TextUserInterface (); diff --git a/src/Main/UserInterface.cpp b/src/Main/UserInterface.cpp index 0f11ec0bf2..09b1fcddb3 100644 --- a/src/Main/UserInterface.cpp +++ b/src/Main/UserInterface.cpp @@ -32,15 +32,6 @@ namespace VeraCrypt { - class AdminPasswordRequestHandler : public GetStringFunctor - { - public: - virtual void operator() (string &str) - { - throw ElevationFailed (SRC_POS, "sudo", 1, ""); - } - }; - UserInterface::UserInterface () { } @@ -567,6 +558,14 @@ namespace VeraCrypt } else { + struct AdminPasswordRequestHandler : public GetStringFunctor + { + virtual void operator() (string &str) + { + throw ElevationFailed (SRC_POS, "sudo", 1, ""); + } + }; + Core->SetAdminPasswordCallback (shared_ptr (new AdminPasswordRequestHandler)); }