-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProcessNameScanner.cpp
61 lines (49 loc) · 1.33 KB
/
ProcessNameScanner.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <Windows.h>
#include <TlHelp32.h>
#include <vector>
#include <string>
#include "ScannerInterface.h"
#include "ProcessNameScanner.h"
void ProcessNameScanner::Process()
{
if (!m_bRun) return;
for (auto &it : m_pVecCDB)
{
OnScan(it);
}
}
void ProcessNameScanner::OnRecvCheatDBPacket(ScannerInterface::eScannerType type, std::vector<ScannerInterface::CheatDefinition> vecData)
{
if (type != m_ScannerType) return;
}
void ProcessNameScanner::OnScan(std::string strProcName) {
PROCESSENTRY32 pe32;
HANDLE hSnapshot = NULL;
pe32.dwSize = sizeof(PROCESSENTRY32);
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (Process32First(hSnapshot, &pe32)) {
do {
for (DWORD i = 0; i < strlen(pe32.szExeFile); ++i)
pe32.szExeFile[i] = tolower(pe32.szExeFile[i]);
if (_stricmp(pe32.szExeFile, strProcName.c_str()) == 0)
{
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID); // Close detected process
TerminateProcess(hProcess, NULL);
Sleep(300);
DWORD exitCode = 0;
if (GetExitCodeProcess(hProcess, &exitCode) == FALSE)
{
//Handle error here.
}
if (exitCode != STILL_ACTIVE)
{
break;
} else {
ExitProcess(0);
}
}
} while (Process32Next(hSnapshot, &pe32));
}
if (hSnapshot != INVALID_HANDLE_VALUE)
CloseHandle(hSnapshot);
}