#pragma once #define WIN32_LEAN_AND_MEAN #include #include #include #include #include #include #include "usings.h" #if defined(_DEBUG) #define OBF(x) x #define OBF_ASCII(x) x #define OBFI(x) x #define OBFI_ASCII(x) x #define OBF_WSTR(x) std::wstring(x) #define OBF_STR(x) std::string(x) #else #include "ADVobfuscator/MetaString.h" #if defined(STRIP_BINARY_FROM_STRINGS_AND_OUTPUTS) #define OBF(x) L"" #define OBF_ASCII(x) "" #define OBFI(x) ADV_OBF_W(x) #define OBFI_ASCII(x) ADV_OBF(x) #else #define OBF(x) ADV_OBF_W(x) #define OBF_ASCII(x) ADV_OBF(x) #define OBFI(x) OBF(x) #define OBFI_ASCII(x) OBF_ASCII(x) #endif //#define OBF_WSTR(x) std::wstring(ADV_OBF_W(x)) //#define OBF_STR(x) std::string(ADV_OBF(x)) #endif extern bool globalQuietOption; extern bool globalVerboseOption; extern bool globalCacheLoglines; extern wchar_t globalLogFilePath[MAX_PATH]; extern std::vector> cachedLogLines; extern std::random_device dev; extern std::mt19937 rng; template std::string formatLogline(Args... args) { std::wostringstream woss; (woss << ... << args); auto a = woss.str(); std::string out(a.begin(), a.end()); out += "\r\n"; return out; } void _output(bool verbose, const std::string& out); template void info(Args... args) { #ifndef STRIP_BINARY_FROM_STRINGS_AND_OUTPUTS const auto out = formatLogline(args...); _output(false, out); #endif } template void output(bool verbose, Args... args) { if (!verbose) return; const auto out = formatLogline(args...); _output(verbose, out); } template void verbose(Args... args) { #ifndef STRIP_BINARY_FROM_STRINGS_AND_OUTPUTS if (globalVerboseOption) { const auto out = formatLogline(args...); _output(true, out); } #endif } void eraseVerboseLinesInCache(); void flushCachedLogLines(bool forceFlushVerbose = false); template std::vector split(const T& s, T seperator) { std::vector output; size_t prev_pos = 0, pos = 0; while ((pos = s.find(seperator, pos)) != T::npos) { T substring(s.substr(prev_pos, pos - prev_pos)); output.push_back(substring); prev_pos = ++pos; } output.push_back(s.substr(prev_pos, pos - prev_pos)); // Last word return output; } template void shuffle(T& t) { std::shuffle(std::begin(t), std::end(t), rng); } template std::vector map_keys(std::map inp) { std::vector _keys; _keys.reserve(inp.size()); for (const auto &m : inp) { _keys.push_back(m.first); } return _keys; } template std::vector map_values(std::map inp) { std::vector _values; _values.reserve(inp.size()); for (const auto &m : inp) { _values.push_back(m.second); } return _values; } template T stringreplace(T str, const T& from, const T& to) { size_t start_pos = str.find(from); if (start_pos == T::npos) return str; T out = str; out.replace(start_pos, from.length(), to); return out; } template bool stringicompare(const T& a, const T& b) { if (a.length() != b.length()) return false; return std::equal( a.begin(), a.end(), b.begin(), [](const unsigned short& a, const unsigned short& b) { return (std::tolower(a) == std::tolower(b)); } ); } std::wstring ltrim(const std::wstring& str, const std::wstring& chars = L"\t\n\v\f\r "); std::wstring rtrim(const std::wstring& str, const std::wstring& chars = L"\t\n\v\f\r "); std::wstring trim(const std::wstring& str, const std::wstring& chars = L"\t\n\v\f\r "); template bool stringicompareWildcard(const T* pattern, const T* value) { // src: https://www.geeksforgeeks.org/wildcard-character-matching/ if (!pattern || !value) return false; // If we reach at the end of both strings, we are done if (*pattern == L'\0' && *value == L'\0') return true; // Make sure that the characters after '*' are present // in second string. This function assumes that the pattern // string will not contain two consecutive '*' if (*pattern == L'*' && *(pattern + 1) != L'\0' && *value == L'\0') return false; // If the pattern string contains '?', or current characters // of both strings match if (*pattern == L'?' || tolower(static_cast(*pattern)) == tolower(static_cast(*value))) return stringicompareWildcard(pattern + 1, value + 1); // If there is *, then there are two possibilities // a) We consider current character of value string // b) We ignore current character of value string. if (*pattern == L'*') return stringicompareWildcard(pattern + 1, value) || stringicompareWildcard(pattern, value + 1); return false; } void die(); int getRandomNumber(int a); int getRandomNumber(int a, int b); std::wstring adjustPath( const std::wstring& szPath ); std::wstring _adjustPath( const std::wstring& szPath ); std::string adjustPathA( const std::string& szPath );