diff --git a/auth.cpp b/auth.cpp index 5a71e8f..cff34a3 100644 --- a/auth.cpp +++ b/auth.cpp @@ -10,7 +10,7 @@ #define WIN32_LEAN_AND_MEAN #endif -#include +#include "auth.hpp" #include #include #include @@ -21,7 +21,7 @@ #include #include -#include +#include "xorstr.hpp" #include #include #include @@ -50,6 +50,7 @@ #include #include "Security.hpp" +#include "stringEncrypt.hpp" #define SHA256_HASH_SIZE 32 @@ -69,7 +70,7 @@ void KeyAuth::api::init() if (ownerid.length() != 10 || secret.length() != 64) { - MessageBoxA(0, XorStr("Application Not Setup Correctly. Please Watch Video Linked in main.cpp").c_str(), NULL, MB_ICONERROR); + MessageBoxA(0, OBFUSCATE_STR("Application Not Setup Correctly. Please Watch Video Linked in main.cpp"), NULL, MB_ICONERROR); exit(0); } @@ -88,24 +89,24 @@ void KeyAuth::api::init() std::string hash = checksum(); CURL* curl = curl_easy_init(); - auto data = + std::string data = XorStr("type=init") + XorStr("&ver=") + version + - XorStr("&hash=") + hash + - XorStr("&enckey=") + sentKey + - XorStr("&name=") + curl_easy_escape(curl, name.c_str(), 0) + - XorStr("&ownerid=") + ownerid; + OBFUSCATE_STR("&hash=") + hash + + OBFUSCATE_STR("&enckey=") + sentKey + + OBFUSCATE_STR("&name=") + curl_easy_escape(curl, name.c_str(), 0) + + OBFUSCATE_STR("&ownerid=") + ownerid; curl_easy_cleanup(curl); auto response = req(data, url); - if (response == XorStr("KeyAuth_Invalid")) { - MessageBoxA(0, XorStr("Application not found. Please copy strings directly from dashboard.").c_str(), NULL, MB_ICONERROR); + if (response == OBFUSCATE_STR("KeyAuth_Invalid")) { + MessageBoxA(0, OBFUSCATE_STR("Application not found. Please copy strings directly from dashboard."), NULL, MB_ICONERROR); exit(0); } auto json = response_decoder.parse(response); - std::string message = json[(XorStr("message"))]; + std::string message = json[(OBFUSCATE_STR("message"))]; // from https://github.com/h5p9sl/hmac_sha256 std::stringstream ss_result; @@ -127,21 +128,21 @@ void KeyAuth::api::init() load_response_data(json); - if (json[(XorStr("success"))]) + if (json[(OBFUSCATE_STR("success"))]) { - if (json[(XorStr("newSession"))]) { + if (json[(OBFUSCATE_STR("newSession"))]) { Sleep(100); } - sessionid = json[(XorStr("sessionid"))]; + sessionid = json[(OBFUSCATE_STR("sessionid"))]; initalized = true; - load_app_data(json[(XorStr("appinfo"))]); + load_app_data(json[(OBFUSCATE_STR("appinfo"))]); } - else if (json[(XorStr("message"))] == XorStr("invalidver")) + else if (json[(OBFUSCATE_STR("message"))] == OBFUSCATE_STR("invalidver")) { - std::string dl = json[(XorStr("download"))]; + std::string dl = json[(OBFUSCATE_STR("download"))]; if (dl == "") { - MessageBoxA(0, XorStr("Version in the loader does match the one on the dashboard, and the download link on dashboard is blank.\n\nTo fix this, either fix the loader so it matches the version on the dashboard. Or if you intended for it to have different versions, update the download link on dashboard so it will auto-update correctly.").c_str(), NULL, MB_ICONERROR); + MessageBoxA(0, OBFUSCATE_STR("Version in the loader does match the one on the dashboard, and the download link on dashboard is blank.\n\nTo fix this, either fix the loader so it matches the version on the dashboard. Or if you intended for it to have different versions, update the download link on dashboard so it will auto-update correctly."), NULL, MB_ICONERROR); } else { @@ -174,17 +175,17 @@ void KeyAuth::api::login(std::string username, std::string password) checkInit(); std::string hwid = utils::get_hwid(); - auto data = + std::string data = XorStr("type=login") + XorStr("&username=") + username + - XorStr("&pass=") + password + - XorStr("&hwid=") + hwid + - XorStr("&sessionid=") + sessionid + - XorStr("&name=") + name + - XorStr("&ownerid=") + ownerid; + OBFUSCATE_STR("&pass=") + password + + OBFUSCATE_STR("&hwid=") + hwid + + OBFUSCATE_STR("&sessionid=") + sessionid + + OBFUSCATE_STR("&name=") + name + + OBFUSCATE_STR("&ownerid=") + ownerid; auto response = req(data, url); auto json = response_decoder.parse(response); - std::string message = json[(XorStr("message"))]; + std::string message = json[(OBFUSCATE_STR("message"))]; // from https://github.com/h5p9sl/hmac_sha256 std::stringstream ss_result; @@ -206,20 +207,20 @@ void KeyAuth::api::login(std::string username, std::string password) } load_response_data(json); - if (json[(XorStr("success"))]) - load_user_data(json[(XorStr("info"))]); + if (json[(OBFUSCATE_STR("success"))]) + load_user_data(json[(OBFUSCATE_STR("info"))]); } void KeyAuth::api::chatget(std::string channel) { checkInit(); - auto data = + std::string data = XorStr("type=chatget") + XorStr("&channel=") + channel + - XorStr("&sessionid=") + sessionid + - XorStr("&name=") + name + - XorStr("&ownerid=") + ownerid; + OBFUSCATE_STR("&sessionid=") + sessionid + + OBFUSCATE_STR("&name=") + name + + OBFUSCATE_STR("&ownerid=") + ownerid; auto response = req(data, url); auto json = response_decoder.parse(response); @@ -233,15 +234,15 @@ bool KeyAuth::api::chatsend(std::string message, std::string channel) auto data = XorStr("type=chatsend") + XorStr("&message=") + message + - XorStr("&channel=") + channel + - XorStr("&sessionid=") + sessionid + - XorStr("&name=") + name + - XorStr("&ownerid=") + ownerid; + OBFUSCATE_STR("&channel=") + channel + + OBFUSCATE_STR("&sessionid=") + sessionid + + OBFUSCATE_STR("&name=") + name + + OBFUSCATE_STR("&ownerid=") + ownerid; auto response = req(data, url); auto json = response_decoder.parse(response); load_response_data(json); - return json[("success")]; + return json[(OBFUSCATE_STR("success"))]; } void KeyAuth::api::changeusername(std::string newusername) @@ -251,13 +252,13 @@ void KeyAuth::api::changeusername(std::string newusername) auto data = XorStr("type=changeUsername") + XorStr("&newUsername=") + newusername + - XorStr("&sessionid=") + sessionid + - XorStr("&name=") + name + - XorStr("&ownerid=") + ownerid; + OBFUSCATE_STR("&sessionid=") + sessionid + + OBFUSCATE_STR("&name=") + name + + OBFUSCATE_STR("&ownerid=") + ownerid; auto response = req(data, url); auto json = response_decoder.parse(response); - std::string message = json[(XorStr("message"))]; + std::string message = json[(OBFUSCATE_STR("message"))]; // from https://github.com/h5p9sl/hmac_sha256 std::stringstream ss_result; @@ -497,14 +498,14 @@ void KeyAuth::api::web_login() // keyauth request std::string hwid = utils::get_hwid(); - auto data = + std::string data = XorStr("type=login") + XorStr("&username=") + user + - XorStr("&token=") + token + - XorStr("&hwid=") + hwid + - XorStr("&sessionid=") + sessionid + - XorStr("&name=") + name + - XorStr("&ownerid=") + ownerid; + OBFUSCATE_STR("&token=") + token + + OBFUSCATE_STR("&hwid=") + hwid + + OBFUSCATE_STR("&sessionid=") + sessionid + + OBFUSCATE_STR("&name=") + name + + OBFUSCATE_STR("&ownerid=") + ownerid; auto resp = req(data, api::url); auto json = response_decoder.parse(resp); std::string message = json[(XorStr("message"))]; @@ -710,16 +711,16 @@ void KeyAuth::api::regstr(std::string username, std::string password, std::strin checkInit(); std::string hwid = utils::get_hwid(); - auto data = + std::string data = XorStr("type=register") + XorStr("&username=") + username + - XorStr("&pass=") + password + - XorStr("&key=") + key + - XorStr("&email=") + email + - XorStr("&hwid=") + hwid + - XorStr("&sessionid=") + sessionid + - XorStr("&name=") + name + - XorStr("&ownerid=") + ownerid; + OBFUSCATE_STR("&pass=") + password + + OBFUSCATE_STR("&key=") + key + + OBFUSCATE_STR("&email=") + email + + OBFUSCATE_STR("&hwid=") + hwid + + OBFUSCATE_STR("&sessionid=") + sessionid + + OBFUSCATE_STR("&name=") + name + + OBFUSCATE_STR("&ownerid=") + ownerid; auto response = req(data, url); auto json = response_decoder.parse(response); std::string message = json[(XorStr("message"))]; @@ -744,23 +745,23 @@ void KeyAuth::api::regstr(std::string username, std::string password, std::strin } load_response_data(json); - if (json[(XorStr("success"))]) - load_user_data(json[(XorStr("info"))]); + if (json[(OBFUSCATE_STR("success"))]) + load_user_data(json[(OBFUSCATE_STR("info"))]); } void KeyAuth::api::upgrade(std::string username, std::string key) { checkInit(); - auto data = + std::string data = XorStr("type=upgrade") + XorStr("&username=") + username + - XorStr("&key=") + key + - XorStr("&sessionid=") + sessionid + - XorStr("&name=") + name + - XorStr("&ownerid=") + ownerid; + OBFUSCATE_STR("&key=") + key + + OBFUSCATE_STR("&sessionid=") + sessionid + + OBFUSCATE_STR("&name=") + name + + OBFUSCATE_STR("&ownerid=") + ownerid; auto response = req(data, url); auto json = response_decoder.parse(response); - std::string message = json[(XorStr("message"))]; + std::string message = json[(OBFUSCATE_STR("message"))]; // from https://github.com/h5p9sl/hmac_sha256 std::stringstream ss_result; @@ -781,7 +782,7 @@ void KeyAuth::api::upgrade(std::string username, std::string key) { error("Signature checksum failed. Request was tampered with or session ended most likely. & echo: & echo Message: " + message); } - json[(XorStr("success"))] = false; + json[(OBFUSCATE_STR("success"))] = false; load_response_data(json); } @@ -789,16 +790,16 @@ void KeyAuth::api::license(std::string key) { checkInit(); std::string hwid = utils::get_hwid(); - auto data = + std::string data = XorStr("type=license") + XorStr("&key=") + key + - XorStr("&hwid=") + hwid + - XorStr("&sessionid=") + sessionid + - XorStr("&name=") + name + - XorStr("&ownerid=") + ownerid; + OBFUSCATE_STR("&hwid=") + hwid + + OBFUSCATE_STR("&sessionid=") + sessionid + + OBFUSCATE_STR("&name=") + name + + OBFUSCATE_STR("&ownerid=") + ownerid; auto response = req(data, url); auto json = response_decoder.parse(response); - std::string message = json[(XorStr("message"))]; + std::string message = json[(OBFUSCATE_STR("message"))]; // from https://github.com/h5p9sl/hmac_sha256 std::stringstream ss_result; @@ -820,20 +821,20 @@ void KeyAuth::api::license(std::string key) { } load_response_data(json); - if (json[(XorStr("success"))]) - load_user_data(json[(XorStr("info"))]); + if (json[(OBFUSCATE_STR("success"))]) + load_user_data(json[(OBFUSCATE_STR("info"))]); } void KeyAuth::api::setvar(std::string var, std::string vardata) { checkInit(); - auto data = + std::string data = XorStr("type=setvar") + XorStr("&var=") + var + - XorStr("&data=") + vardata + - XorStr("&sessionid=") + sessionid + - XorStr("&name=") + name + - XorStr("&ownerid=") + ownerid; + OBFUSCATE_STR("&data=") + vardata + + OBFUSCATE_STR("&sessionid=") + sessionid + + OBFUSCATE_STR("&name=") + name + + OBFUSCATE_STR("&ownerid=") + ownerid; auto response = req(data, url); auto json = response_decoder.parse(response); load_response_data(json); @@ -842,15 +843,15 @@ void KeyAuth::api::setvar(std::string var, std::string vardata) { std::string KeyAuth::api::getvar(std::string var) { checkInit(); - auto data = + std::string data = XorStr("type=getvar") + XorStr("&var=") + var + - XorStr("&sessionid=") + sessionid + - XorStr("&name=") + name + - XorStr("&ownerid=") + ownerid; + OBFUSCATE_STR("&sessionid=") + sessionid + + OBFUSCATE_STR("&name=") + name + + OBFUSCATE_STR("&ownerid=") + ownerid; auto response = req(data, url); auto json = response_decoder.parse(response); - std::string message = json[(XorStr("message"))]; + std::string message = json[(OBFUSCATE_STR("message"))]; // from https://github.com/h5p9sl/hmac_sha256 std::stringstream ss_result; @@ -872,21 +873,21 @@ std::string KeyAuth::api::getvar(std::string var) { } load_response_data(json); - return !json[(XorStr("response"))].is_null() ? json[(XorStr("response"))] : XorStr(""); + return !json[(OBFUSCATE_STR("response"))].is_null() ? json[(OBFUSCATE_STR("response"))] : ""; } void KeyAuth::api::ban(std::string reason) { checkInit(); - auto data = + std::string data = XorStr("type=ban") + XorStr("&reason=") + reason + - XorStr("&sessionid=") + sessionid + - XorStr("&name=") + name + - XorStr("&ownerid=") + ownerid; + OBFUSCATE_STR("&sessionid=") + sessionid + + OBFUSCATE_STR("&name=") + name + + OBFUSCATE_STR("&ownerid=") + ownerid; auto response = req(data, url); auto json = response_decoder.parse(response); - std::string message = json[(XorStr("message"))]; + std::string message = json[(OBFUSCATE_STR("message"))]; // from https://github.com/h5p9sl/hmac_sha256 std::stringstream ss_result; @@ -914,15 +915,15 @@ bool KeyAuth::api::checkblack() { checkInit(); std::string hwid = utils::get_hwid(); - auto data = + std::string data = XorStr("type=checkblacklist") + XorStr("&hwid=") + hwid + - XorStr("&sessionid=") + sessionid + - XorStr("&name=") + name + - XorStr("&ownerid=") + ownerid; + OBFUSCATE_STR("&sessionid=") + sessionid + + OBFUSCATE_STR("&name=") + name + + OBFUSCATE_STR("&ownerid=") + ownerid; auto response = req(data, url); auto json = response_decoder.parse(response); - std::string message = json[(XorStr("message"))]; + std::string message = json[(OBFUSCATE_STR("message"))]; // from https://github.com/h5p9sl/hmac_sha256 std::stringstream ss_result; @@ -1068,7 +1069,7 @@ std::string KeyAuth::api::webhook(std::string id, std::string params, std::strin { checkInit(); - CURL *curl = curl_easy_init(); + CURL* curl = curl_easy_init(); auto data = XorStr("type=webhook") + XorStr("&webid=") + id + @@ -1103,7 +1104,7 @@ std::string KeyAuth::api::webhook(std::string id, std::string params, std::strin } load_response_data(json); - return !json[(XorStr("response"))].is_null() ? json[(XorStr("response"))] : XorStr(""); + return !json[(XorStr("response"))].is_null() ? json[(XorStr("response"))] : ""; } std::string KeyAuth::api::fetchonline() @@ -1430,7 +1431,7 @@ void modify() while (true) { - if ( check_section_integrity( XorStr( ".text" ).c_str( ), false ) ) + if ( check_section_integrity(XorStr( ".text" ).c_str( ), false ) ) { error("check_section_integrity() failed, don't tamper with the program."); } diff --git a/auth.hpp b/auth.hpp index 07b1aee..10a4cc3 100644 --- a/auth.hpp +++ b/auth.hpp @@ -15,7 +15,11 @@ namespace KeyAuth { class api { public: - std::string name, ownerid, secret, version, url; + std::string name; + std::string ownerid; + std::string secret; + std::string version; + std::string url; api(std::string name, std::string ownerid, std::string secret, std::string version, std::string url) : name(name), ownerid(ownerid), secret(secret), version(version), url(url) {} diff --git a/library.vcxproj b/library.vcxproj index b2894c6..6865f7a 100644 --- a/library.vcxproj +++ b/library.vcxproj @@ -217,8 +217,10 @@ + + diff --git a/library.vcxproj.filters b/library.vcxproj.filters index 5b1a39b..be80299 100644 --- a/library.vcxproj.filters +++ b/library.vcxproj.filters @@ -194,6 +194,12 @@ Header Files + + Source Files + + + Source Files + diff --git a/random.hpp b/random.hpp new file mode 100644 index 0000000..1427ae1 --- /dev/null +++ b/random.hpp @@ -0,0 +1,62 @@ +#pragma once + +#include +#include + +#pragma warning(push) +#pragma warning(disable: 4307) +constexpr static auto time_from_string(const char* str, int offset) +{ + return ((static_cast(str[offset]) - '0') * 10) + + (static_cast(str[offset + 1]) - '0'); +} + +template +constexpr static auto get_seed_constexpr() +{ + constexpr auto t = __TIME__; + constexpr auto nt = (time_from_string(t, 0) * 60 * 60 + time_from_string(t, 3) * 60 + time_from_string(t, 6)); + + uint64_t hashedValue = 3074457345618258791ul; + for (int i = 0; i < sizeof(uint64_t); i++) + { + hashedValue += nt & (1i64 << i) + Counter; + hashedValue *= 3074457345618258799ul; + } + + return hashedValue; +} + +constexpr uint64_t lce_a = 1273686654176231872; +constexpr uint64_t lce_c = 1278361726378617232; +constexpr uint64_t lce_m = 187236981273; + +constexpr static std::uint64_t uniform_distribution(uint64_t& previous) +{ + previous = ((lce_a * previous + lce_c) % lce_m); + return previous; +} + + +constexpr static double uniform_distribution_n(uint64_t& previous) +{ + auto dst = uniform_distribution(previous); + return static_cast(dst) / lce_m; +} + +template +constexpr static auto uniform_distribution(T min, T max) +{ + std::array dst{}; + auto previous = get_seed_constexpr(); + for (auto& el : dst) + el = static_cast(uniform_distribution_n(previous) * (max - min) + min); + + return dst; +} +#pragma warning(pop) + +#define RAND_NUM(mi, ma) (uniform_distribution(mi, ma)[0]) + +#define gen_rand32 (uniform_distribution(0, UINT32_MAX)[0]) +#define gen_rand64 (uniform_distribution(0, UINT64_MAX)[0]) \ No newline at end of file diff --git a/stringEncrypt.hpp b/stringEncrypt.hpp new file mode 100644 index 0000000..527d44f --- /dev/null +++ b/stringEncrypt.hpp @@ -0,0 +1,60 @@ + +#pragma once +#include + +#include "Random.hpp" + +#pragma warning(disable: 4307) +namespace Obfuscation::String +{ + template + struct ObfuscatedString + { + static constexpr std::array XOR = uniform_distribution(0, 255); + std::array Encrypted; + + static __forceinline constexpr char Encrypt(uint32_t Idx, char C) { + return C ^ XOR[Idx]; + } + + template + __forceinline constexpr ObfuscatedString(const char* Str, std::index_sequence) : + Encrypted({ Encrypt(Idx, Str[Idx])... }) { } + + __forceinline const char* Decrypt() { + for (uint32_t x = 0; x < Size; x++) + Encrypted[x] ^= XOR[x]; + + return Encrypted.data(); + } + }; +} + +#pragma warning(disable: 4307) +namespace OtherObfuscation::String +{ + template + struct ObfuscatedString + { + static constexpr std::array XOR = uniform_distribution(0, 255); + std::array Encrypted; + + static __forceinline constexpr char Encrypt(uint32_t Idx, char C) { + return C ^ XOR[Idx]; + } + + template + __forceinline constexpr ObfuscatedString(const char* Str, std::index_sequence) : + Encrypted({ Encrypt(Idx, Str[Idx])... }) { } + + __forceinline std::string Decrypt() { + for (uint32_t x = 0; x < Size; x++) + Encrypted[x] ^= XOR[x]; + + return std::string(Encrypted.data(), Size); + } + }; +} + +#define OBFUSCATE_STR(s) (Obfuscation::String::ObfuscatedString(s, std::make_index_sequence()).Decrypt()) +#define OBFUSCATE_OTHER(s) (OtherObfuscation::String::ObfuscatedString(s, std::make_index_sequence()).Decrypt()) \ No newline at end of file diff --git a/utils.cpp b/utils.cpp index 0b09151..5e2ebab 100644 --- a/utils.cpp +++ b/utils.cpp @@ -23,4 +23,4 @@ std::tm utils::timet_to_tm(time_t timestamp) { localtime_s(&context, ×tamp); return context; -} +} \ No newline at end of file