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;
- // ... [Keep the SetPrivilege function as it is] ...
- 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);
- std::wcout << L"Process: " << processName << L", Window Title: " << windowTitle << std::endl;
- if (processName == L"notepad.exe" || processName == L"notepad++.exe") {
- targetProcesses.push_back({ processName, hwnd });
- }
- }
- else {
- std::wcout << L"GetModuleFileNameEx error: " << GetLastError() << std::endl;
- }
- }
- return TRUE;
- }
- bool ModifyWindowTitles() {
- bool anyModified = false;
- for (const auto& process : targetProcesses) {
- std::wstring newTitle = L"Wormhole Vortex";
- 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;
- }
- void RestoreWindowTitles() {
- for (const auto& process : targetProcesses) {
- if (SetWindowText(process.hwnd, process.processName.c_str())) {
- std::wcout << L"Restored window title of " << process.processName << std::endl;
- }
- else {
- std::wcout << L"Failed to restore window title of " << process.processName << std::endl;
- }
- }
- }
- DWORD WINAPI TitleModifierThread(LPVOID lpParam) {
- while (running) {
- ModifyWindowTitles();
- Sleep(1000);
- }
- return 0;
- }
- int main() {
- // ... [Keep the privilege setting code as it is] ...
- 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, 0);
- if (ModifyWindowTitles()) {
- std::wcout << L"Notepad and Notepad++ have been modified successfully." << std::endl;
- }
- else {
- std::wcout << L"Unable to modify Notepad or Notepad++ window titles." << std::endl;
- }
- HANDLE hThread = CreateThread(NULL, 0, TitleModifierThread, NULL, 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);
- RestoreWindowTitles();
- // ... [Keep the privilege resetting code as it is] ...
- SetPrivilege(hToken, SE_DEBUG_NAME, FALSE);
- CloseHandle(hToken);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement