diff options
| -rw-r--r-- | src/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/modinforegular.h | 2 | ||||
| -rw-r--r-- | src/settings.cpp | 48 | ||||
| -rw-r--r-- | src/settings.h | 4 |
4 files changed, 40 insertions, 16 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a518ccd4..cc7d7a78 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -331,7 +331,7 @@ TARGET_LINK_LIBRARIES(ModOrganizer zlibstatic uibase esptk bsatk githubpp ${usvfs_name} - Dbghelp advapi32 Version Shlwapi liblz4) + Dbghelp advapi32 Version Shlwapi liblz4 Crypt32) IF (MSVC) SET_TARGET_PROPERTIES(ModOrganizer PROPERTIES COMPILE_FLAGS "/std:c++latest") diff --git a/src/modinforegular.h b/src/modinforegular.h index 13ce7e42..6ad51e5f 100644 --- a/src/modinforegular.h +++ b/src/modinforegular.h @@ -415,7 +415,7 @@ private: bool m_IsAlternate; bool m_Converted; bool m_Validated; - bool m_NexusFileStatus; + int m_NexusFileStatus; MOBase::VersionInfo m_NewestVersion; MOBase::VersionInfo m_IgnoredVersion; diff --git a/src/settings.cpp b/src/settings.cpp index fdc767bf..1d5da376 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -57,6 +57,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include <QtDebug> // for qDebug, qWarning #include <Windows.h> // For ShellExecuteW, HINSTANCE, etc +#include <wincrypt.h> // For storage #include <algorithm> // for sort #include <memory> @@ -175,26 +176,49 @@ void Settings::registerPlugin(IPlugin *plugin) } } -QString Settings::obfuscate(const QString &password) +QString Settings::obfuscate(const QString &info) { - QByteArray temp = password.toUtf8(); + QString result; + DATA_BLOB input; + DATA_BLOB output; + BYTE *pbInput = (unsigned char *)malloc(info.size() + 1); + memcpy(pbInput, info.constData(), info.size() + 1); + DWORD cbInput = info.size() + 1; + input.pbData = pbInput; + input.cbData = cbInput; - QByteArray buffer; - for (int i = 0; i < temp.length(); ++i) { - buffer.append(temp.at(i) ^ Key2[i % 20]); + if (CryptProtectData(&input, NULL, NULL, NULL, NULL, 0, &output)) { + QByteArray buffer = QByteArray::fromRawData((const char *)output.pbData, output.cbData); + result = buffer.toBase64(); + } else { + qCritical() << "Failed to encrypt the data!"; } - return buffer.toBase64(); + LocalFree(input.pbData); + LocalFree(output.pbData); + return result; } -QString Settings::deObfuscate(const QString &password) +QString Settings::deObfuscate(const QString &info) { - QByteArray temp(QByteArray::fromBase64(password.toUtf8())); + QString result; + QByteArray realInfo = QByteArray::fromBase64(info.toUtf8()); + DATA_BLOB input; + DATA_BLOB output; + BYTE *pbInput = (unsigned char *)malloc(realInfo.size() + 1); + memcpy(pbInput, realInfo.constData(), realInfo.size() + 1); + DWORD cbInput = realInfo.size() + 1; + input.pbData = pbInput; + input.cbData = cbInput; - QByteArray buffer; - for (int i = 0; i < temp.length(); ++i) { - buffer.append(temp.at(i) ^ Key2[i % 20]); + if (CryptUnprotectData(&input, NULL, NULL, NULL, NULL, 0, &output)) { + QByteArray buffer = QByteArray::fromRawData((const char *)output.pbData, output.cbData); + result = buffer; + } else { + qCritical() << "Failed to decrypt data!"; } - return QString::fromUtf8(buffer.constData()); + LocalFree(input.pbData); + LocalFree(output.pbData); + return result; } QColor Settings::getIdealTextColor(const QColor& rBackgroundColor) diff --git a/src/settings.h b/src/settings.h index d692497e..83838d5c 100644 --- a/src/settings.h +++ b/src/settings.h @@ -393,8 +393,8 @@ public: static QColor getIdealTextColor(const QColor& rBackgroundColor); private: - static QString obfuscate(const QString &password); - static QString deObfuscate(const QString &password); + static QString obfuscate(const QString &info); + static QString deObfuscate(const QString &info); void addLanguages(QComboBox *languageBox); void addStyles(QComboBox *styleBox); |
