Advertisement
alien_fx_fiend

AdvTitleChanger

Jun 29th, 2024
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.53 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.  
  9. #pragma comment(lib, "Psapi.lib")
  10.  
  11. struct ProcessInfo {
  12.     std::wstring processName;
  13.     HWND hwnd;
  14. };
  15.  
  16. std::vector<ProcessInfo> targetProcesses;
  17. bool running = true;
  18.  
  19. // Function to set privileges
  20. BOOL SetPrivilege(HANDLE hToken, LPCTSTR lpszPrivilege, BOOL bEnablePrivilege) {
  21.     TOKEN_PRIVILEGES tp;
  22.     LUID luid;
  23.  
  24.     if (!LookupPrivilegeValue(NULL, lpszPrivilege, &luid)) {
  25.         std::wcout << L"LookupPrivilegeValue error: " << GetLastError() << std::endl;
  26.         return FALSE;
  27.     }
  28.  
  29.     tp.PrivilegeCount = 1;
  30.     tp.Privileges[0].Luid = luid;
  31.     tp.Privileges[0].Attributes = (bEnablePrivilege) ? SE_PRIVILEGE_ENABLED : 0;
  32.  
  33.     if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), (PTOKEN_PRIVILEGES)NULL, (PDWORD)NULL)) {
  34.         std::wcout << L"AdjustTokenPrivileges error: " << GetLastError() << std::endl;
  35.         return FALSE;
  36.     }
  37.  
  38.     if (GetLastError() == ERROR_NOT_ALL_ASSIGNED) {
  39.         std::wcout << L"The token does not have the specified privilege. \n" << std::endl;
  40.         return FALSE;
  41.     }
  42.  
  43.     return TRUE;
  44. }
  45.  
  46. // Callback function for EnumWindows
  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.             if (processName == *(std::wstring*)lParam) {
  66.                 targetProcesses.push_back({ processName, hwnd });
  67.             }
  68.         }
  69.         else {
  70.             std::wcout << L"GetModuleFileNameEx error: " << GetLastError() << std::endl;
  71.         }
  72.     }
  73.     return TRUE;
  74. }
  75.  
  76. // Function to modify window titles
  77. bool ModifyWindowTitles(const std::wstring& newTitle) {
  78.     bool anyModified = false;
  79.     for (const auto& process : targetProcesses) {
  80.         if (SetWindowText(process.hwnd, newTitle.c_str())) {
  81.             anyModified = true;
  82.             std::wcout << L"Modified window title of " << process.processName << std::endl;
  83.         }
  84.         else {
  85.             std::wcout << L"Failed to modify window title of " << process.processName << std::endl;
  86.         }
  87.     }
  88.     return anyModified;
  89. }
  90.  
  91. // Thread function to persistently modify window titles
  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. int main() {
  102.     std::wstring processName;
  103.     std::wcout << L"Enter the process name (e.g., notepad.exe): ";
  104.     std::getline(std::wcin, processName);
  105.  
  106.     std::wstring newTitle;
  107.     std::wcout << L"Enter the new window title text: ";
  108.     std::getline(std::wcin, newTitle);
  109.  
  110.     HANDLE hToken;
  111.     if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
  112.         std::wcout << L"OpenProcessToken error: " << GetLastError() << std::endl;
  113.         return 1;
  114.     }
  115.  
  116.     if (!SetPrivilege(hToken, SE_DEBUG_NAME, TRUE)) {
  117.         std::wcout << L"Failed to enable debug privilege." << std::endl;
  118.         CloseHandle(hToken);
  119.         return 1;
  120.     }
  121.  
  122.     EnumWindows(EnumWindowsProc, (LPARAM)&processName);
  123.  
  124.     if (targetProcesses.empty()) {
  125.         std::wcout << L"No windows found for process: " << processName << std::endl;
  126.     }
  127.     else {
  128.         HANDLE hThread = CreateThread(NULL, 0, TitleModifierThread, &newTitle, 0, NULL);
  129.         if (hThread == NULL) {
  130.             std::wcout << L"Failed to create thread." << std::endl;
  131.             return 1;
  132.         }
  133.  
  134.         std::wcout << L"Window titles are being modified. Press Enter to stop and exit..." << std::endl;
  135.         std::cin.get();
  136.  
  137.         running = false;
  138.         WaitForSingleObject(hThread, INFINITE);
  139.         CloseHandle(hThread);
  140.     }
  141.  
  142.     SetPrivilege(hToken, SE_DEBUG_NAME, FALSE);
  143.     CloseHandle(hToken);
  144.  
  145.     return 0;
  146. }
  147.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement