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>
- #include <sstream> // For std::wistringstream
- #pragma comment(lib, "Psapi.lib")
- struct ProcessInfo {
- std::wstring processName;
- HWND hwnd;
- };
- std::vector<ProcessInfo> targetProcesses;
- std::vector<std::wstring> processNames;
- bool running = true;
- 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;
- }
- 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);
- for (const auto& targetName : *(std::vector<std::wstring>*)lParam) {
- if (processName == targetName) {
- targetProcesses.push_back({ processName, hwnd });
- }
- }
- }
- else {
- std::wcout << L"GetModuleFileNameEx error: " << GetLastError() << std::endl;
- }
- }
- return TRUE;
- }
- 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;
- }
- DWORD WINAPI TitleModifierThread(LPVOID lpParam) {
- std::wstring newTitle = *(std::wstring*)lpParam;
- while (running) {
- ModifyWindowTitles(newTitle);
- Sleep(1000);
- }
- return 0;
- }
- std::vector<std::wstring> Split(const std::wstring& s, wchar_t delimiter) {
- std::vector<std::wstring> tokens;
- std::wstring token;
- std::wistringstream tokenStream(s); // std::wistringstream for wide strings
- while (std::getline(tokenStream, token, delimiter)) {
- tokens.push_back(token);
- }
- return tokens;
- }
- int main() {
- std::wstring input;
- std::wcout << L"Enter the process names separated by semicolons (e.g., notepad.exe;calc.exe): ";
- std::getline(std::wcin, input);
- processNames = Split(input, L';');
- std::wstring newTitle;
- std::wcout << L"Enter the new window title text: ";
- std::getline(std::wcin, newTitle);
- std::wstring persistence;
- std::wcout << L"Do you want persistence (Y/N)? ";
- std::getline(std::wcin, persistence);
- 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)&processNames);
- if (targetProcesses.empty()) {
- std::wcout << L"No windows found for the specified processes." << std::endl;
- }
- else {
- if (persistence == L"Y" || persistence == L"y") {
- 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 persistently. Press Enter to stop and exit..." << std::endl;
- std::cin.get();
- running = false;
- WaitForSingleObject(hThread, INFINITE);
- CloseHandle(hThread);
- }
- else {
- ModifyWindowTitles(newTitle);
- std::wcout << L"Window titles modified once. Press Enter to exit..." << std::endl;
- std::cin.get();
- }
- }
- SetPrivilege(hToken, SE_DEBUG_NAME, FALSE);
- CloseHandle(hToken);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement