From 453054fc4911fab4a626ba2232af6f08903926f1 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Fri, 25 Feb 2022 20:29:21 -0500 Subject: [PATCH] Move encrypted argument methods into their own header --- include/encryptedarg.h | 57 ++++++++++++++++++++++++++++++++++++++++++ src/launchercore.cpp | 53 +-------------------------------------- 2 files changed, 58 insertions(+), 52 deletions(-) create mode 100644 include/encryptedarg.h diff --git a/include/encryptedarg.h b/include/encryptedarg.h new file mode 100644 index 0000000..0e12037 --- /dev/null +++ b/include/encryptedarg.h @@ -0,0 +1,57 @@ +#pragma once + +#include +#include "blowfish.h" + +// from xivdev +char ChecksumTable[] = { + 'f', 'X', '1', 'p', 'G', 't', 'd', 'S', + '5', 'C', 'A', 'P', '4', '_', 'V', 'L' +}; + +char GetChecksum(unsigned int key) { + auto value = key & 0x000F0000; + return ChecksumTable[value >> 16]; +} + +#if defined(Q_OS_MAC) +// this is pretty much what wine does :-0 +inline uint32_t TickCount() { + struct mach_timebase_info convfact; + mach_timebase_info(&convfact); + + return (mach_absolute_time() * convfact.numer) / (convfact.denom * 1000000); +} +#endif + +#if defined(Q_OS_LINUX) +inline uint32_t TickCount() { + struct timespec ts; + + clock_gettime(CLOCK_MONOTONIC, &ts); + + return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000); +} +#endif + +#if defined(Q_OS_WIN) +inline uint32_t TickCount() { + return GetTickCount(); +} +#endif + +inline QString encryptGameArg(QString arg) { + unsigned int rawTicks = TickCount(); + unsigned int ticks = rawTicks & 0xFFFFFFFFu; + unsigned int key = ticks & 0xFFFF0000u; + + char buffer[9] = {}; + sprintf(buffer, "%08x", key); + + Blowfish session(QByteArray(buffer, 8)); + QByteArray encryptedArg = session.Encrypt((QString(" /T =%1").arg(ticks) + arg).toUtf8()); + QString base64 = encryptedArg.toBase64(QByteArray::Base64Option::Base64UrlEncoding | QByteArray::Base64Option::OmitTrailingEquals); + char checksum = GetChecksum(key); + + return QString("//**sqex0003%1%2**//").arg(base64, QString(checksum)); +} \ No newline at end of file diff --git a/src/launchercore.cpp b/src/launchercore.cpp index 3eaca83..ea8bef1 100755 --- a/src/launchercore.cpp +++ b/src/launchercore.cpp @@ -34,6 +34,7 @@ #include "settingswindow.h" #include "blowfish.h" #include "assetupdater.h" +#include "encryptedarg.h" #ifdef ENABLE_WATCHDOG #include "watchdog.h" @@ -57,58 +58,6 @@ void LauncherCore::buildRequest(QNetworkRequest& request) { request.setRawHeader("Accept-Language", "en-us"); } -// from xivdev -char ChecksumTable[] = { - 'f', 'X', '1', 'p', 'G', 't', 'd', 'S', - '5', 'C', 'A', 'P', '4', '_', 'V', 'L' -}; - -char GetChecksum(unsigned int key) { - auto value = key & 0x000F0000; - return ChecksumTable[value >> 16]; -} - -#if defined(Q_OS_MAC) -// this is pretty much what wine does :-0 -uint32_t TickCount() { - struct mach_timebase_info convfact; - mach_timebase_info(&convfact); - - return (mach_absolute_time() * convfact.numer) / (convfact.denom * 1000000); -} -#endif - -#if defined(Q_OS_LINUX) -uint32_t TickCount() { - struct timespec ts; - - clock_gettime(CLOCK_MONOTONIC, &ts); - - return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000); -} -#endif - -#if defined(Q_OS_WIN) -uint32_t TickCount() { - return GetTickCount(); -} -#endif - -QString encryptGameArg(QString arg) { - unsigned int rawTicks = TickCount(); - unsigned int ticks = rawTicks & 0xFFFFFFFFu; - unsigned int key = ticks & 0xFFFF0000u; - - char buffer[9] = {}; - sprintf(buffer, "%08x", key); - - Blowfish session(QByteArray(buffer, 8)); - QByteArray encryptedArg = session.Encrypt((QString(" /T =%1").arg(ticks) + arg).toUtf8()); - QString base64 = encryptedArg.toBase64(QByteArray::Base64Option::Base64UrlEncoding | QByteArray::Base64Option::OmitTrailingEquals); - char checksum = GetChecksum(key); - - return QString("//**sqex0003%1%2**//").arg(base64, QString(checksum)); -} void LauncherCore::launchGame(const ProfileSettings& profile, const LoginAuth auth) { QList arguments;