-
Notifications
You must be signed in to change notification settings - Fork 0
/
poe.cpp
85 lines (73 loc) · 1.69 KB
/
poe.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "string"
#include "time.h"
#include "fstream"
#include "windows.h"
#include "tlhelp32.h"
bool killProcess(LPCTSTR name);
int main(int argc, char const *argv[]) {
auto exec_code = (int)ShellExecute(NULL, NULL, PCHAR("launcher.exe"), NULL, NULL, SW_NORMAL);
if (exec_code < 32) //调用失败
return 0;
Sleep(2000);
std::fstream log_file;
if (argc > 1) //入参有文件路径
log_file.open(argv[1], std::ios::in);
if (!log_file.is_open()) //文件是否打开
return 0;
std::string line;
log_file.seekg(0, std::ios::end);
// Start Scan
while (true) {
if (log_file.peek() == EOF) //实时更新文件指针
{
if (clock() > 300000) {
log_file.close();
return 0;
}
log_file.clear();
Sleep(2000);
}
std::getline(log_file, line);
if (line.find("Connected to") != std::string::npos) //已连接服务器
{
log_file.close();
break;
}
}
// End Scan
killProcess("tgp_daemon.exe");
killProcess("GameLoader.exe");
return 0;
}
bool killProcess(LPCTSTR name) {
DWORD pid = 0;
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pe; pe.dwSize = sizeof(PROCESSENTRY32);
if (!Process32First(hSnapshot, &pe))
return 0;
while (true) {
pe.dwSize = sizeof(PROCESSENTRY32);
if (Process32Next(hSnapshot, &pe) == FALSE)
break;
if (strcmp(pe.szExeFile, name) == 0) {
pid = pe.th32ProcessID;
break;
}
Sleep(1);
}
CloseHandle(hSnapshot);
if (pid != 0) {
HANDLE handle = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
if (TerminateProcess(handle, 0)) {
CloseHandle(handle);
//std::cout << "Success Terminate!";
return true;
}
else {
CloseHandle(handle);
return false;
}
}
else
return true;
}