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>
- #pragma comment(lib, "Psapi.lib")
- BOOL notepadHooked = FALSE;
- BOOL notepadPlusPlusHooked = FALSE;
- 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") {
- std::wstring newTitle = L"Wormhole Vortex";
- if (SetWindowText(hwnd, newTitle.c_str())) {
- std::wcout << L"Modified window title of " << processName << std::endl;
- notepadHooked = TRUE;
- }
- else {
- std::wcout << L"Failed to modify window title of " << processName << std::endl;
- }
- }
- if (processName == L"notepad++.exe") {
- std::wstring newTitle = L"Wormhole Vortex";
- if (SetWindowText(hwnd, newTitle.c_str())) {
- std::wcout << L"Modified window title of " << processName << std::endl;
- notepadPlusPlusHooked = TRUE;
- }
- else {
- std::wcout << L"Failed to modify window title of " << processName << std::endl;
- }
- }
- }
- else {
- std::wcout << L"GetModuleFileNameEx error: " << GetLastError() << std::endl;
- }
- }
- return TRUE;
- }
- int main() {
- 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 (notepadHooked) {
- std::cout << "Notepad.exe window titles modified successfully." << std::endl;
- }
- else {
- std::cout << "Unable to modify Notepad.exe window titles." << std::endl;
- }
- if (notepadPlusPlusHooked) {
- std::cout << "Notepad++.exe window titles modified successfully." << std::endl;
- }
- else {
- std::cout << "Unable to modify Notepad++.exe window titles." << std::endl;
- }
- std::cout << "Press enter to exit...";
- std::cin.get();
- SetPrivilege(hToken, SE_DEBUG_NAME, FALSE);
- CloseHandle(hToken);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement