From 0c9fc5c08ab31acd9a1ae3e0588a4324cccf19f1 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Tue, 10 Sep 2019 18:53:55 -0400 Subject: [PATCH] small fixes --- extensions/googletranslate.cpp | 12 ++++++------ include/common.h | 5 ++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/extensions/googletranslate.cpp b/extensions/googletranslate.cpp index dda1a1a..5ed9f4c 100644 --- a/extensions/googletranslate.cpp +++ b/extensions/googletranslate.cpp @@ -73,14 +73,16 @@ QStringList languages "Zulu: zu" }; -std::wstring GetTranslationUri(const std::wstring& text, unsigned TKK) +unsigned TKK = 0; + +std::wstring GetTranslationUri(const std::wstring& text) { // If no TKK available, use this uri. Can't use too much or google will detect unauthorized access if (!TKK) return FormatString(L"/translate_a/single?client=gtx&dt=ld&dt=rm&dt=t&tl=%s&q=%s", translateTo->c_str(), text); // Artikash 8/19/2018: reverse engineered from translate.google.com std::wstring escapedText; - unsigned a = _time64(NULL) / 3600, b = a; // <- the first part of TKK + unsigned a = time(NULL) / 3600, b = a; // the first part of TKK for (unsigned char ch : WideStringToString(text)) { escapedText += FormatString(L"%%%02X", (int)ch); @@ -93,9 +95,8 @@ std::wstring GetTranslationUri(const std::wstring& text, unsigned TKK) a += a << 15; a ^= TKK; a %= 1000000; - b ^= a; - return FormatString(L"/translate_a/single?client=webapp&dt=ld&dt=rm&dt=t&sl=auto&tl=%s&tk=%u.%u&q=%s", translateTo->c_str(), a, b, escapedText); + return FormatString(L"/translate_a/single?client=webapp&dt=ld&dt=rm&dt=t&sl=auto&tl=%s&tk=%u.%u&q=%s", translateTo->c_str(), a, a ^ b, escapedText); } bool IsHash(const std::wstring& result) @@ -105,13 +106,12 @@ bool IsHash(const std::wstring& result) std::pair Translate(const std::wstring& text) { - static unsigned TKK = 0; if (!TKK) if (HttpRequest httpRequest{ L"Mozilla/5.0 Textractor", L"translate.google.com", L"GET", L"/" }) if (std::wsmatch results; std::regex_search(httpRequest.response, results, std::wregex(L"(\\d{7,})'"))) _InterlockedCompareExchange(&TKK, stoll(results[1]), 0); - if (HttpRequest httpRequest{ L"Mozilla/5.0 Textractor", L"translate.google.com", L"GET", GetTranslationUri(text, TKK).c_str() }) + if (HttpRequest httpRequest{ L"Mozilla/5.0 Textractor", L"translate.googleapis.com", L"GET", GetTranslationUri(text).c_str() }) { // Response formatted as JSON: starts with "[[[" and translation is enclosed in quotes followed by a comma if (httpRequest.response[0] == L'[') diff --git a/include/common.h b/include/common.h index fddfd9f..4804e5f 100644 --- a/include/common.h +++ b/include/common.h @@ -26,9 +26,6 @@ constexpr bool x64 = true; constexpr bool x64 = false; #endif -#define MESSAGE(text) MessageBoxW(NULL, text, L"Textractor", MB_OK) -#define CRITIAL_SECTION static std::mutex m; std::scoped_lock l(m) - template using Array = T[]; template using Functor = std::integral_constant, F>; @@ -111,6 +108,8 @@ inline std::wstring FormatString(const wchar_t* format, const Args&... args) } #pragma warning(pop) +#define MESSAGE(text) MessageBoxW(NULL, FormatArg(text), L"Textractor", MB_OK) + #ifdef _DEBUG #define TEST(...) static auto _ = CreateThread(nullptr, 0, [](auto) { __VA_ARGS__; return 0UL; }, NULL, 0, nullptr); #else