Gameprocesswatcher.cpp Official
void GameProcessWatcher::closeProcessHandle() if (m_hProcess != nullptr) CloseHandle(m_hProcess); m_hProcess = nullptr; m_processId = 0;
bool GameProcessWatcher::terminateProcess() if (m_hProcess == nullptr) return false; if (!TerminateProcess(m_hProcess, 0)) m_lastError = "Failed to terminate process. Error: " + std::to_string(GetLastError()); return false; closeProcessHandle(); return true;
bool GameProcessWatcher::openProcessById(DWORD processId) PROCESS_VM_OPERATION
std::vector<ProcessInfo> GameProcessWatcher::getAllProcesses() const std::vector<ProcessInfo> processes; HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hSnapshot == INVALID_HANDLE_VALUE) return processes; PROCESSENTRY32 processEntry; processEntry.dwSize = sizeof(PROCESSENTRY32); if (Process32First(hSnapshot, &processEntry)) do ProcessInfo info; info.processId = processEntry.th32ProcessID; info.processName = processEntry.szExeFile; info.threadCount = processEntry.cntThreads; info.parentProcessId = processEntry.th32ParentProcessID; processes.push_back(info); while (Process32Next(hSnapshot, &processEntry)); CloseHandle(hSnapshot); return processes; gameprocesswatcher.cpp
// Memory operations bool readMemory(uintptr_t address, void* buffer, size_t size) const; bool writeMemory(uintptr_t address, const void* buffer, size_t size) const;
// Process control bool terminateProcess();
uintptr_t GameProcessWatcher::getModuleBaseAddress(const std::string& moduleName) const if (m_processId == 0) return 0; HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE void GameProcessWatcher::closeProcessHandle() if (m_hProcess
template<typename T> bool readValue(uintptr_t address, T& value) const return readMemory(address, &value, sizeof(T));
struct ProcessInfo DWORD processId; std::string processName; DWORD threadCount; DWORD parentProcessId; ;
HANDLE m_hProcess; DWORD m_processId; std::atomic<bool> m_isWatching; int m_checkInterval; std::thread m_watchThread; mutable std::mutex m_mutex; std::function<void(DWORD)> m_onProcessExit; mutable std::string m_lastError; ; m_hProcess = nullptr
And here's the corresponding header file gameprocesswatcher.h :
#include "gameprocesswatcher.h" #include <windows.h> #include <tlhelp32.h> #include <algorithm> #include <cstring>
#pragma once #include <string> #include <thread> #include <mutex> #include <functional> #include <vector> #include <windows.h>
// Process monitoring bool startWatching(int intervalMs = 1000); void stopWatching(); bool isProcessRunning() const;