| 70 | } |
| 71 | |
| 72 | void GetProcesses(std::vector<Process>& processes) { |
| 73 | static char fileName[_MAX_PATH]; |
| 74 | // Get the id of this process so that we can filter it out of the list. |
| 75 | DWORD currentProcessId = GetCurrentProcessId(); |
| 76 | |
| 77 | HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
| 78 | |
| 79 | if (snapshot != INVALID_HANDLE_VALUE) { |
| 80 | |
| 81 | PROCESSENTRY32 processEntry = {0}; |
| 82 | processEntry.dwSize = sizeof(processEntry); |
| 83 | |
| 84 | if (Process32First(snapshot, &processEntry)) { |
| 85 | do { |
| 86 | if (processEntry.th32ProcessID != currentProcessId && processEntry.th32ProcessID != 0) { |
| 87 | |
| 88 | Process process; |
| 89 | |
| 90 | process.id = processEntry.th32ProcessID; |
| 91 | process.name = processEntry.szExeFile; |
| 92 | |
| 93 | HANDLE m_process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, processEntry.th32ProcessID); |
| 94 | if (m_process) { |
| 95 | int err = GetModuleFileNameEx(m_process, nullptr, fileName, _MAX_PATH); |
| 96 | if (err == 0) // ERROR_ACCESS_DENIED = 5 |
| 97 | process.path = "error"; |
| 98 | else process.path = fileName; |
| 99 | |
| 100 | if (!process.path.empty()) { |
| 101 | char windowsPath[MAX_PATH]; |
| 102 | if (SHGetFolderPath(nullptr, CSIDL_WINDOWS, nullptr, SHGFP_TYPE_CURRENT, windowsPath) == 0) { |
| 103 | if (process.path.find(windowsPath) == std::string::npos) { |
| 104 | |
| 105 | HWND hWnd = GetProcessWindow(processEntry.th32ProcessID); |
| 106 | |
| 107 | if (hWnd != nullptr) { |
| 108 | char buffer[1024]; |
| 109 | GetWindowText(hWnd, buffer, 1024); |
| 110 | process.title = buffer; |
| 111 | } |
| 112 | processes.push_back(process); |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | while (Process32Next(snapshot, &processEntry)); |
| 120 | } |
| 121 | CloseHandle(snapshot); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | |
| 126 | void SetBreakpoint(HANDLE hProcess, LPVOID entryPoint, bool set, BYTE *data) { |
no test coverage detected