From aadb50fb6135f4bf5c26aa22fb3c87c1b97c705a Mon Sep 17 00:00:00 2001 From: Joaquin <67109235+Taiga74164@users.noreply.github.com> Date: Fri, 12 Apr 2024 05:08:56 -0600 Subject: [PATCH] misc: Randomize string --- cheat/src/Render/Gui/gui.cpp | 3 +- cheat/src/Utils.cpp | 356 ++++++++++++++++++----------------- cheat/src/Utils.h | 2 + injector/src/main.cpp | 4 +- injector/src/util.cpp | 20 ++ injector/src/util.h | 2 + 6 files changed, 217 insertions(+), 170 deletions(-) diff --git a/cheat/src/Render/Gui/gui.cpp b/cheat/src/Render/Gui/gui.cpp index 6d22975..668fb5c 100644 --- a/cheat/src/Render/Gui/gui.cpp +++ b/cheat/src/Render/Gui/gui.cpp @@ -1,5 +1,6 @@ #include "gui.h" #include "global.h" +#include "imgui.h" #include "Utils.h" #include "utils/gui-util.hpp" @@ -12,7 +13,7 @@ void Gui::Render() ImGui::BeginGroup(); { ImGui::PushStyleColor(ImGuiCol_ChildBg, IM_COL32(0, 0, 0, 0)); - GuiUtil::CenterText("Solo Leveling Cheeto", 0, 0); + GuiUtil::CenterText(Utils::GenerateRandomString(10).c_str(), 0, 0); ImGui::Spacing(); ImGui::Spacing(); ImGui::PopStyleColor(); diff --git a/cheat/src/Utils.cpp b/cheat/src/Utils.cpp index 517bd2b..3ad524e 100644 --- a/cheat/src/Utils.cpp +++ b/cheat/src/Utils.cpp @@ -5,196 +5,216 @@ #include #include #include +#include std::mutex mutex; -namespace Utils -{ - void AttachConsole() - { - AllocConsole(); - freopen_s((FILE**)stdin, "CONIN$", "r", stdin); - freopen_s((FILE**)stdout, "CONOUT$", "w", stdout); - freopen_s((FILE**)stderr, "CONOUT$", "w", stderr); - SetConsoleOutputCP(CP_UTF8); - } - - void DetachConsole() - { - fclose(stdin); - fclose(stdout); - fclose(stderr); - FreeConsole(); - } - - void ConsolePrint(const char* filepath, int line, const char* fmt, ...) - { - char buf[4096]; +void Utils::AttachConsole() +{ + AllocConsole(); + freopen_s((FILE**)stdin, "CONIN$", "r", stdin); + freopen_s((FILE**)stdout, "CONOUT$", "w", stdout); + freopen_s((FILE**)stderr, "CONOUT$", "w", stderr); + SetConsoleOutputCP(CP_UTF8); +} - va_list va; - va_start(va, fmt); - vsprintf_s(buf, fmt, va); - va_end(va); +void Utils::DetachConsole() +{ + fclose(stdin); + fclose(stdout); + fclose(stderr); + FreeConsole(); +} - const std::lock_guard lock(mutex); +void Utils::ConsolePrint(const char* filepath, int line, const char* fmt, ...) +{ + char buf[4096]; - auto filename = std::filesystem::path(filepath).filename().string(); - auto logLineConsole = string_format("[%s:%d] %s", filename.c_str(), line, buf); - auto str = (logLineConsole + std::string(fmt)).c_str(); + va_list va; + va_start(va, fmt); + vsprintf_s(buf, fmt, va); + va_end(va); - std::cout << logLineConsole << std::endl; - } + const std::lock_guard lock(mutex); - void ConsolePrint(const char* filepath, int line, const wchar_t* fmt, ...) - { - wchar_t buf[4096]; + auto filename = std::filesystem::path(filepath).filename().string(); + auto logLineConsole = string_format("[%s:%d] %s", filename.c_str(), line, buf); + auto str = (logLineConsole + std::string(fmt)).c_str(); + + std::cout << logLineConsole << std::endl; +} - va_list va; - va_start(va, fmt); - vswprintf_s(buf, fmt, va); - va_end(va); +void Utils::ConsolePrint(const char* filepath, int line, const wchar_t* fmt, ...) +{ + wchar_t buf[4096]; - const std::lock_guard lock(mutex); + va_list va; + va_start(va, fmt); + vswprintf_s(buf, fmt, va); + va_end(va); - auto filename = std::filesystem::path(filepath).filename().string(); - auto logLineConsole = string_format("[%s:%d] %s", filename.c_str(), line, buf); - auto str = (logLineConsole + to_string(std::wstring(fmt))).c_str(); + const std::lock_guard lock(mutex); - std::cout << logLineConsole << std::endl; - } + auto filename = std::filesystem::path(filepath).filename().string(); + auto logLineConsole = string_format("[%s:%d] %s", filename.c_str(), line, buf); + auto str = (logLineConsole + to_string(std::wstring(fmt))).c_str(); + + std::cout << logLineConsole << std::endl; +} + +void Utils::ClearConsole() +{ + DWORD n; /* Number of characters written */ + DWORD size; /* number of visible characters */ + COORD coord = { 0 }; /* Top left screen position */ + CONSOLE_SCREEN_BUFFER_INFO csbi; + + /* Get a handle to the console */ + HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); + + GetConsoleScreenBufferInfo(h, &csbi); - void ClearConsole() - { - DWORD n; /* Number of characters written */ - DWORD size; /* number of visible characters */ - COORD coord = { 0 }; /* Top left screen position */ - CONSOLE_SCREEN_BUFFER_INFO csbi; - - /* Get a handle to the console */ - HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); - - GetConsoleScreenBufferInfo(h, &csbi); - - /* Find the number of characters to overwrite */ - size = csbi.dwSize.X * csbi.dwSize.Y; - - /* Overwrite the screen buffer with whitespace */ - FillConsoleOutputCharacter(h, TEXT(' '), size, coord, &n); - GetConsoleScreenBufferInfo(h, &csbi); - FillConsoleOutputAttribute(h, csbi.wAttributes, size, coord, &n); - - /* Reset the cursor to the top left position */ - SetConsoleCursorPosition(h, coord); - } - - char ConsoleReadKey() - { - auto key = char{ 0 }; - auto keysread = DWORD{ 0 }; - - //ReadConsoleA(_in, &key, 1, &keysread, nullptr); - return std::cin.get(); - } - - std::string GetAddressModuleName(uintptr_t address) - { - std::vector Modules{}; - - static DWORD pid = GetCurrentProcessId(); - MODULEENTRY32 mod{}; - mod.dwSize = sizeof(mod); - HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid); - for (Module32First(snap, &mod); Module32Next(snap, &mod);) - { - if (mod.th32ProcessID != pid) - continue; - - Modules.emplace_back(mod); - } - CloseHandle(snap); - - for (const auto& it : Modules) - { - if (address >= (uintptr_t)it.modBaseAddr && address <= (uintptr_t)it.modBaseAddr + it.modBaseSize) - return it.szModule; - } - - return "unknown"; - } - - std::wstring GetCurrentProcessNameW() + /* Find the number of characters to overwrite */ + size = csbi.dwSize.X * csbi.dwSize.Y; + + /* Overwrite the screen buffer with whitespace */ + FillConsoleOutputCharacter(h, TEXT(' '), size, coord, &n); + GetConsoleScreenBufferInfo(h, &csbi); + FillConsoleOutputAttribute(h, csbi.wAttributes, size, coord, &n); + + /* Reset the cursor to the top left position */ + SetConsoleCursorPosition(h, coord); +} + +char Utils::ConsoleReadKey() +{ + auto key = char{ 0 }; + auto keysread = DWORD{ 0 }; + + //ReadConsoleA(_in, &key, 1, &keysread, nullptr); + return std::cin.get(); +} + +std::string Utils::GetAddressModuleName(uintptr_t address) +{ + std::vector Modules{}; + + static DWORD pid = GetCurrentProcessId(); + MODULEENTRY32 mod{}; + mod.dwSize = sizeof(mod); + HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid); + for (Module32First(snap, &mod); Module32Next(snap, &mod);) { - DWORD processID = GetCurrentProcessId(); - HANDLE processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID); - - if (processHandle != NULL) - { - WCHAR processName[MAX_PATH] = L""; - GetModuleBaseNameW(processHandle, NULL, processName, MAX_PATH); - CloseHandle(processHandle); - return std::wstring(processName); - } - - // In case the handle could not be opened, return an error message. - return L"Unable to retrieve process name."; + if (mod.th32ProcessID != pid) + continue; + + Modules.emplace_back(mod); } + CloseHandle(snap); - std::string GetCurrentProcessNameA() + for (const auto& it : Modules) { - return to_string(GetCurrentProcessNameW()); - } - - std::string to_string(const std::wstring& wstr) - { - std::wstring_convert> strconverter; - return strconverter.to_bytes(wstr); - } - - std::wstring to_wstring(const std::string& str) - { - std::wstring_convert> strconverter; - return strconverter.from_bytes(str); - } - - bool KeyDown(std::uint16_t vk) - { - const auto hWindow = FindWindowA("UnityWndClass", nullptr); - if (GetForegroundWindow() != hWindow) - return false; - - return (GetAsyncKeyState(vk) & 0x8000) != 0; - } - - bool KeyPressed(std::uint16_t vk) - { - const auto hWindow = FindWindowA("UnityWndClass", nullptr); - if (GetForegroundWindow() != hWindow) - return false; - - return (GetAsyncKeyState(vk) & 1) != 0; - } - - void OpenURL(const std::string& url) - { - ShellExecuteA(nullptr, "open", url.c_str(), nullptr, nullptr, SW_SHOWNORMAL); + if (address >= (uintptr_t)it.modBaseAddr && address <= (uintptr_t)it.modBaseAddr + it.modBaseSize) + return it.szModule; } - std::string GetModulePath(HMODULE hModule /*= nullptr*/) - { - char pathOut[MAX_PATH] = {}; - GetModuleFileNameA(hModule, pathOut, MAX_PATH); + return "unknown"; +} - return std::filesystem::path(pathOut).parent_path().string(); - } +std::wstring Utils::GetCurrentProcessNameW() +{ + DWORD processID = GetCurrentProcessId(); + HANDLE processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID); - static std::filesystem::path _currentPath; - void SetCurrentPath(const std::filesystem::path& current_path) + if (processHandle != NULL) { - _currentPath = current_path; + WCHAR processName[MAX_PATH] = L""; + GetModuleBaseNameW(processHandle, NULL, processName, MAX_PATH); + CloseHandle(processHandle); + return std::wstring(processName); } - std::filesystem::path GetCurrentPath() - { - return _currentPath; - } + // In case the handle could not be opened, return an error message. + return L"Unable to retrieve process name."; +} + +std::string Utils::GetCurrentProcessNameA() +{ + return to_string(GetCurrentProcessNameW()); +} + +std::string Utils::to_string(const std::wstring& wstr) +{ + std::wstring_convert> strconverter; + return strconverter.to_bytes(wstr); +} + +std::wstring Utils::to_wstring(const std::string& str) +{ + std::wstring_convert> strconverter; + return strconverter.from_bytes(str); +} + +bool Utils::KeyDown(std::uint16_t vk) +{ + const auto hWindow = FindWindowA("UnityWndClass", nullptr); + if (GetForegroundWindow() != hWindow) + return false; + + return (GetAsyncKeyState(vk) & 0x8000) != 0; } + +bool Utils::KeyPressed(std::uint16_t vk) +{ + const auto hWindow = FindWindowA("UnityWndClass", nullptr); + if (GetForegroundWindow() != hWindow) + return false; + + return (GetAsyncKeyState(vk) & 1) != 0; +} + +void Utils::OpenURL(const std::string& url) +{ + ShellExecuteA(nullptr, "open", url.c_str(), nullptr, nullptr, SW_SHOWNORMAL); +} + +std::string Utils::GetModulePath(HMODULE hModule /*= nullptr*/) +{ + char pathOut[MAX_PATH] = {}; + GetModuleFileNameA(hModule, pathOut, MAX_PATH); + + return std::filesystem::path(pathOut).parent_path().string(); +} + +static std::filesystem::path _currentPath; +void Utils::SetCurrentPath(const std::filesystem::path& current_path) +{ + _currentPath = current_path; +} + +std::filesystem::path Utils::GetCurrentPath() +{ + return _currentPath; +} + +std::string Utils::GenerateRandomString(size_t length) +{ + const std::vector charset = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' + }; + + std::random_device rd; + std::mt19937 generator(rd()); + + std::uniform_int_distribution distribution(0, charset.size() - 1); + + std::string randomString; + for (size_t i = 0; i < length; ++i) + randomString += charset[distribution(generator)]; + + return randomString; +} \ No newline at end of file diff --git a/cheat/src/Utils.h b/cheat/src/Utils.h index 22d1c14..2128699 100644 --- a/cheat/src/Utils.h +++ b/cheat/src/Utils.h @@ -49,4 +49,6 @@ namespace Utils void SetCurrentPath(const std::filesystem::path& curren_path); std::filesystem::path GetCurrentPath(); + + std::string GenerateRandomString(size_t length); } \ No newline at end of file diff --git a/injector/src/main.cpp b/injector/src/main.cpp index 4e93d09..7b21973 100644 --- a/injector/src/main.cpp +++ b/injector/src/main.cpp @@ -69,6 +69,8 @@ int main() if (!config.DLLPath_1.empty()) { + auto shuffledPath = util::ShuffleDllName(config.DLLPath_1); + std::cout << "Shuffled DLL 1 path: " << shuffledPath << std::endl; if (!Inject(hProcess, config.DLLPath_1)) std::cerr << "Failed to inject DLL 1" << std::endl; } @@ -85,7 +87,7 @@ int main() std::cerr << "Failed to inject DLL 3" << std::endl; } - Sleep(2000); + Sleep(3000); ResumeThread(hThread); CloseHandle(hProcess); return 0; diff --git a/injector/src/util.cpp b/injector/src/util.cpp index 8224409..fd8aba7 100644 --- a/injector/src/util.cpp +++ b/injector/src/util.cpp @@ -1,6 +1,7 @@ #include "util.h" #include +#include std::optional util::SelectFile(const char* filter, const char* title) { @@ -42,4 +43,23 @@ std::string util::GetLastErrorAsString(DWORD errorId) std::string message(messageBuffer, size); LocalFree(messageBuffer); return message; +} + +std::string util::ShuffleDllName(const std::string& path) +{ + size_t lastSlash = path.find_last_of("\\"); + size_t lastDot = path.find_last_of("."); + + if (lastSlash == std::string::npos || lastDot == std::string::npos || lastDot <= lastSlash) + return path; + + std::string directory = path.substr(0, lastSlash + 1); + std::string filename = path.substr(lastSlash + 1, lastDot - lastSlash - 1); + std::string extension = path.substr(lastDot); + + std::random_device rd; + std::mt19937 g(rd()); + std::shuffle(filename.begin(), filename.end(), g); + + return directory + filename + extension; } \ No newline at end of file diff --git a/injector/src/util.h b/injector/src/util.h index 2f6389a..faa89a9 100644 --- a/injector/src/util.h +++ b/injector/src/util.h @@ -9,4 +9,6 @@ namespace util { std::optional SelectFile(const char* filter = "All Files (*.*)\0*.*\0", const char* title = "Select a File to Open"); std::string GetLastErrorAsString(DWORD errorId = 0); + + std::string ShuffleDllName(const std::string& path); } \ No newline at end of file