Gameprocesswatcher.cpp

bool GameProcessWatcher::setProcessByName(const std::string& processName) std::lock_guard<std::mutex> lock(m_mutex); DWORD pid = findProcessIdByName(processName); if (pid == 0) m_lastError = "Process not found: " + processName; return false; return openProcessById(pid);

// Process selection bool setProcessByName(const std::string& processName); bool setProcessById(DWORD processId);

// 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; gameprocesswatcher.cpp

#pragma once #include <string> #include <thread> #include <mutex> #include <functional> #include <vector> #include <windows.h>

// Getters DWORD getProcessId() const return m_processId; bool isWatching() const return m_isWatching; private: DWORD findProcessIdByName(const std::string& processName) const; bool openProcessById(DWORD processId); void closeProcessHandle(); void watchLoop(); DWORD pid = findProcessIdByName(processName)

void GameProcessWatcher::closeProcessHandle() if (m_hProcess != nullptr) CloseHandle(m_hProcess); m_hProcess = nullptr; m_processId = 0;

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; bool setProcessById(DWORD processId)

std::string GameProcessWatcher::getLastError() const return m_lastError;

GameProcessWatcher::GameProcessWatcher() : m_hProcess(nullptr) , m_processId(0) , m_isWatching(false) , m_checkInterval(1000)

DWORD GameProcessWatcher::findProcessIdByName(const std::string& processName) const std::string targetName = processName; std::transform(targetName.begin(), targetName.end(), targetName.begin(), ::tolower); HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hSnapshot == INVALID_HANDLE_VALUE) return 0; PROCESSENTRY32 processEntry; processEntry.dwSize = sizeof(PROCESSENTRY32); DWORD pid = 0; if (Process32First(hSnapshot, &processEntry)) do std::string currentName = processEntry.szExeFile; std::transform(currentName.begin(), currentName.end(), currentName.begin(), ::tolower); if (currentName == targetName) pid = processEntry.th32ProcessID; break; while (Process32Next(hSnapshot, &processEntry)); CloseHandle(hSnapshot); return pid;

Back
Top