-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathControlRemoteProcess.cpp
More file actions
45 lines (40 loc) · 1.15 KB
/
ControlRemoteProcess.cpp
File metadata and controls
45 lines (40 loc) · 1.15 KB
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
#include <windows.h>
#include <tlhelp32.h>
#include "NativeCore.hpp"
void RC_CallConv ControlRemoteProcess(RC_Pointer handle, ControlRemoteProcessAction action)
{
if (action == ControlRemoteProcessAction::Suspend || action == ControlRemoteProcessAction::Resume)
{
const auto processId = GetProcessId(handle);
if (processId != 0)
{
const auto snapshotHandle = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if (snapshotHandle != INVALID_HANDLE_VALUE)
{
const auto fn = action == ControlRemoteProcessAction::Suspend ? SuspendThread : ResumeThread;
THREADENTRY32 te32 = {};
te32.dwSize = sizeof(THREADENTRY32);
if (Thread32First(snapshotHandle, &te32))
{
do
{
if (te32.th32OwnerProcessID == processId)
{
const auto threadHandle = OpenThread(THREAD_SUSPEND_RESUME, FALSE, te32.th32ThreadID);
if (threadHandle)
{
fn(threadHandle);
CloseHandle(threadHandle);
}
}
} while (Thread32Next(snapshotHandle, &te32));
}
CloseHandle(snapshotHandle);
}
}
}
else if (action == ControlRemoteProcessAction::Terminate)
{
TerminateProcess(handle, 0);
}
}