Skip to content

Commit 3fc8ac5

Browse files
authored
Add files via upload
1 parent e97de3c commit 3fc8ac5

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

挂起程序.cpp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#include <windows.h>
2+
#include <tlhelp32.h>
3+
#include <iostream>
4+
#include <vector>
5+
#include <string>
6+
7+
//提升权限为DEBUG,处理GetLastError返回5 无权限操作错误
8+
BOOL EnableDebugPrivilege(){
9+
HANDLE hToken;
10+
BOOL fOk=FALSE;
11+
if(OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES,&hToken)){
12+
TOKEN_PRIVILEGES tp;
13+
tp.PrivilegeCount=1;
14+
LookupPrivilegeValue(NULL,SE_DEBUG_NAME,&tp.Privileges[0].Luid);
15+
16+
tp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
17+
AdjustTokenPrivileges(hToken,FALSE,&tp,sizeof(tp),NULL,NULL);
18+
19+
fOk=(GetLastError()==ERROR_SUCCESS);
20+
CloseHandle(hToken);
21+
}
22+
return fOk;
23+
}
24+
25+
// 获取进程句柄
26+
HANDLE get_process_handle(DWORD process_id) {
27+
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, process_id);
28+
if (hProcess == NULL) {
29+
std::cerr << "OpenProcess failed for PID " << process_id << ": " << GetLastError() << std::endl;
30+
}
31+
return hProcess;
32+
}
33+
34+
// 挂起进程中的所有线程
35+
void suspend_threads(HANDLE hProcess) {
36+
THREADENTRY32 te;
37+
te.dwSize = sizeof(te);
38+
HANDLE hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
39+
if (hThreadSnap != INVALID_HANDLE_VALUE) {
40+
if (Thread32First(hThreadSnap, &te)) {
41+
do {
42+
if (te.dwSize >= FIELD_OFFSET(THREADENTRY32, th32OwnerProcessID) + sizeof(te.th32OwnerProcessID)) {
43+
if (te.th32OwnerProcessID == GetProcessId(hProcess)) {
44+
HANDLE hThread = OpenThread(THREAD_SUSPEND_RESUME, FALSE, te.th32ThreadID);
45+
if (hThread != NULL) {
46+
SuspendThread(hThread);
47+
CloseHandle(hThread);
48+
}
49+
}
50+
}
51+
} while (Thread32Next(hThreadSnap, &te));
52+
}
53+
}
54+
CloseHandle(hThreadSnap);
55+
}
56+
57+
int main() {
58+
BOOL EnableDebugPrivilege();
59+
EnableDebugPrivilege();
60+
std::vector<std::string> exeNames = {"SeewoAbility.exe", "SeewoFreezeUpdateAssist.exe", "SeewoCore.exe", "SeewoServiceAssistant.exe", "SeewoIwbAssistant.exe"};
61+
PROCESSENTRY32 pe;
62+
pe.dwSize = sizeof(pe);
63+
64+
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
65+
if (hSnapshot == INVALID_HANDLE_VALUE) {
66+
std::cerr << "CreateToolhelp32Snapshot failed for processes: " << GetLastError() << std::endl;
67+
return 1;
68+
}
69+
70+
if (!Process32First(hSnapshot, &pe)) {
71+
std::cerr << "Process32First failed: " << GetLastError() << std::endl;
72+
CloseHandle(hSnapshot);
73+
return 1;
74+
}
75+
76+
do {
77+
std::string processName(pe.szExeFile);
78+
for (const auto& name : exeNames) {
79+
if (processName == name) {
80+
HANDLE hProcess = get_process_handle(pe.th32ProcessID);
81+
if (hProcess != NULL) {
82+
suspend_threads(hProcess);
83+
CloseHandle(hProcess);
84+
}
85+
break;
86+
}
87+
}
88+
} while (Process32Next(hSnapshot, &pe));
89+
90+
CloseHandle(hSnapshot);
91+
92+
std::cout << "All specified programs have been attempted to be suspended." << std::endl;
93+
94+
return 0;
95+
}

0 commit comments

Comments
 (0)