Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <string>
- #include <TlHelp32.h>
- #include <tchar.h>
- #include <Psapi.h>
- #include <iostream>
- #include <vector>
- #pragma comment(lib, "Psapi.lib")
- struct ProcessInfo {
- std::wstring processName;
- HWND hwnd;
- };
- std::vector<ProcessInfo> targetProcesses;
- bool running = true;
- // Function to set privileges
- BOOL SetPrivilege(HANDLE hToken, LPCTSTR lpszPrivilege, BOOL bEnablePrivilege) {
- TOKEN_PRIVILEGES tp;
- LUID luid;
- if (!LookupPrivilegeValue(NULL, lpszPrivilege, &luid)) {
- std::wcout << L"LookupPrivilegeValue error: " << GetLastError() << std::endl;
- return FALSE;
- }
- tp.PrivilegeCount = 1;
- tp.Privileges[0].Luid = luid;
- tp.Privileges[0].Attributes = (bEnablePrivilege) ? SE_PRIVILEGE_ENABLED : 0;
- if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), (PTOKEN_PRIVILEGES)NULL, (PDWORD)NULL)) {
- std::wcout << L"AdjustTokenPrivileges error: " << GetLastError() << std::endl;
- return FALSE;
- }
- if (GetLastError() == ERROR_NOT_ALL_ASSIGNED) {
- std::wcout << L"The token does not have the specified privilege. \n" << std::endl;
- return FALSE;
- }
- return TRUE;
- }
- // Callback function for EnumWindows
- BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) {
- DWORD processId;
- GetWindowThreadProcessId(hwnd, &processId);
- HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId);
- if (hProcess != NULL) {
- TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
- if (GetModuleFileNameEx(hProcess, NULL, szProcessName, MAX_PATH)) {
- std::wstring processName(szProcessName);
- size_t pos = processName.find_last_of(L"\\");
- if (pos != std::wstring::npos) {
- processName = processName.substr(pos + 1);
- }
- CloseHandle(hProcess);
- TCHAR windowTitle[MAX_PATH];
- GetWindowText(hwnd, windowTitle, MAX_PATH);
- if (processName == *(std::wstring*)lParam) {
- targetProcesses.push_back({ processName, hwnd });
- }
- }
- else {
- std::wcout << L"GetModuleFileNameEx error: " << GetLastError() << std::endl;
- }
- }
- return TRUE;
- }
- // Function to modify window titles
- bool ModifyWindowTitles(const std::wstring& newTitle) {
- bool anyModified = false;
- for (const auto& process : targetProcesses) {
- if (SetWindowText(process.hwnd, newTitle.c_str())) {
- anyModified = true;
- std::wcout << L"Modified window title of " << process.processName << std::endl;
- }
- else {
- std::wcout << L"Failed to modify window title of " << process.processName << std::endl;
- }
- }
- return anyModified;
- }
- // Thread function to persistently modify window titles
- DWORD WINAPI TitleModifierThread(LPVOID lpParam) {
- std::wstring newTitle = *(std::wstring*)lpParam;
- while (running) {
- ModifyWindowTitles(newTitle);
- Sleep(1000);
- }
- return 0;
- }
- int main() {
- std::wstring processName;
- std::wcout << L"Enter the process name (e.g., notepad.exe): ";
- std::getline(std::wcin, processName);
- std::wstring newTitle;
- std::wcout << L"Enter the new window title text: ";
- std::getline(std::wcin, newTitle);
- HANDLE hToken;
- if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
- std::wcout << L"OpenProcessToken error: " << GetLastError() << std::endl;
- return 1;
- }
- if (!SetPrivilege(hToken, SE_DEBUG_NAME, TRUE)) {
- std::wcout << L"Failed to enable debug privilege." << std::endl;
- CloseHandle(hToken);
- return 1;
- }
- EnumWindows(EnumWindowsProc, (LPARAM)&processName);
- if (targetProcesses.empty()) {
- std::wcout << L"No windows found for process: " << processName << std::endl;
- }
- else {
- HANDLE hThread = CreateThread(NULL, 0, TitleModifierThread, &newTitle, 0, NULL);
- if (hThread == NULL) {
- std::wcout << L"Failed to create thread." << std::endl;
- return 1;
- }
- std::wcout << L"Window titles are being modified. Press Enter to stop and exit..." << std::endl;
- std::cin.get();
- running = false;
- WaitForSingleObject(hThread, INFINITE);
- CloseHandle(hThread);
- }
- SetPrivilege(hToken, SE_DEBUG_NAME, FALSE);
- CloseHandle(hToken);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement