Advertisement
alien_fx_fiend

Advanced Title Changer (Now /w multiple process names & Persistent/ Single Hooking!) (Console-Based)

Jul 5th, 2024 (edited)
992
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.39 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <string>
  3. #include <TlHelp32.h>
  4. #include <tchar.h>
  5. #include <Psapi.h>
  6. #include <iostream>
  7. #include <vector>
  8. #include <sstream>  // For std::wistringstream
  9.  
  10. #pragma comment(lib, "Psapi.lib")
  11.  
  12. struct ProcessInfo {
  13.     std::wstring processName;
  14.     HWND hwnd;
  15. };
  16.  
  17. std::vector<ProcessInfo> targetProcesses;
  18. std::vector<std::wstring> processNames;
  19. bool running = true;
  20.  
  21. BOOL SetPrivilege(HANDLE hToken, LPCTSTR lpszPrivilege, BOOL bEnablePrivilege) {
  22.     TOKEN_PRIVILEGES tp;
  23.     LUID luid;
  24.  
  25.     if (!LookupPrivilegeValue(NULL, lpszPrivilege, &luid)) {
  26.         std::wcout << L"LookupPrivilegeValue error: " << GetLastError() << std::endl;
  27.         return FALSE;
  28.     }
  29.  
  30.     tp.PrivilegeCount = 1;
  31.     tp.Privileges[0].Luid = luid;
  32.     tp.Privileges[0].Attributes = (bEnablePrivilege) ? SE_PRIVILEGE_ENABLED : 0;
  33.  
  34.     if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), (PTOKEN_PRIVILEGES)NULL, (PDWORD)NULL)) {
  35.         std::wcout << L"AdjustTokenPrivileges error: " << GetLastError() << std::endl;
  36.         return FALSE;
  37.     }
  38.  
  39.     if (GetLastError() == ERROR_NOT_ALL_ASSIGNED) {
  40.         std::wcout << L"The token does not have the specified privilege. \n" << std::endl;
  41.         return FALSE;
  42.     }
  43.  
  44.     return TRUE;
  45. }
  46.  
  47. BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) {
  48.     DWORD processId;
  49.     GetWindowThreadProcessId(hwnd, &processId);
  50.  
  51.     HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId);
  52.     if (hProcess != NULL) {
  53.         TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
  54.         if (GetModuleFileNameEx(hProcess, NULL, szProcessName, MAX_PATH)) {
  55.             std::wstring processName(szProcessName);
  56.             size_t pos = processName.find_last_of(L"\\");
  57.             if (pos != std::wstring::npos) {
  58.                 processName = processName.substr(pos + 1);
  59.             }
  60.             CloseHandle(hProcess);
  61.  
  62.             TCHAR windowTitle[MAX_PATH];
  63.             GetWindowText(hwnd, windowTitle, MAX_PATH);
  64.  
  65.             for (const auto& targetName : *(std::vector<std::wstring>*)lParam) {
  66.                 if (processName == targetName) {
  67.                     targetProcesses.push_back({ processName, hwnd });
  68.                 }
  69.             }
  70.         }
  71.         else {
  72.             std::wcout << L"GetModuleFileNameEx error: " << GetLastError() << std::endl;
  73.         }
  74.     }
  75.     return TRUE;
  76. }
  77.  
  78. bool ModifyWindowTitles(const std::wstring& newTitle) {
  79.     bool anyModified = false;
  80.     for (const auto& process : targetProcesses) {
  81.         if (SetWindowText(process.hwnd, newTitle.c_str())) {
  82.             anyModified = true;
  83.             std::wcout << L"Modified window title of " << process.processName << std::endl;
  84.         }
  85.         else {
  86.             std::wcout << L"Failed to modify window title of " << process.processName << std::endl;
  87.         }
  88.     }
  89.     return anyModified;
  90. }
  91.  
  92. DWORD WINAPI TitleModifierThread(LPVOID lpParam) {
  93.     std::wstring newTitle = *(std::wstring*)lpParam;
  94.     while (running) {
  95.         ModifyWindowTitles(newTitle);
  96.         Sleep(1000);
  97.     }
  98.     return 0;
  99. }
  100.  
  101. std::vector<std::wstring> Split(const std::wstring& s, wchar_t delimiter) {
  102.     std::vector<std::wstring> tokens;
  103.     std::wstring token;
  104.     std::wistringstream tokenStream(s); // std::wistringstream for wide strings
  105.     while (std::getline(tokenStream, token, delimiter)) {
  106.         tokens.push_back(token);
  107.     }
  108.     return tokens;
  109. }
  110.  
  111. int main() {
  112.     std::wstring input;
  113.     std::wcout << L"Enter the process names separated by semicolons (e.g., notepad.exe;calc.exe): ";
  114.     std::getline(std::wcin, input);
  115.     processNames = Split(input, L';');
  116.  
  117.     std::wstring newTitle;
  118.     std::wcout << L"Enter the new window title text: ";
  119.     std::getline(std::wcin, newTitle);
  120.  
  121.     std::wstring persistence;
  122.     std::wcout << L"Do you want persistence (Y/N)? ";
  123.     std::getline(std::wcin, persistence);
  124.  
  125.     HANDLE hToken;
  126.     if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
  127.         std::wcout << L"OpenProcessToken error: " << GetLastError() << std::endl;
  128.         return 1;
  129.     }
  130.  
  131.     if (!SetPrivilege(hToken, SE_DEBUG_NAME, TRUE)) {
  132.         std::wcout << L"Failed to enable debug privilege." << std::endl;
  133.         CloseHandle(hToken);
  134.         return 1;
  135.     }
  136.  
  137.     EnumWindows(EnumWindowsProc, (LPARAM)&processNames);
  138.  
  139.     if (targetProcesses.empty()) {
  140.         std::wcout << L"No windows found for the specified processes." << std::endl;
  141.     }
  142.     else {
  143.         if (persistence == L"Y" || persistence == L"y") {
  144.             HANDLE hThread = CreateThread(NULL, 0, TitleModifierThread, &newTitle, 0, NULL);
  145.             if (hThread == NULL) {
  146.                 std::wcout << L"Failed to create thread." << std::endl;
  147.                 return 1;
  148.             }
  149.  
  150.             std::wcout << L"Window titles are being modified persistently. Press Enter to stop and exit..." << std::endl;
  151.             std::cin.get();
  152.  
  153.             running = false;
  154.             WaitForSingleObject(hThread, INFINITE);
  155.             CloseHandle(hThread);
  156.         }
  157.         else {
  158.             ModifyWindowTitles(newTitle);
  159.             std::wcout << L"Window titles modified once. Press Enter to exit..." << std::endl;
  160.             std::cin.get();
  161.         }
  162.     }
  163.  
  164.     SetPrivilege(hToken, SE_DEBUG_NAME, FALSE);
  165.     CloseHandle(hToken);
  166.  
  167.     return 0;
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement