主题
创建远程线程 - CreateRemoteThread
函数简介
在指定的窗口所在进程中创建一个线程,常用于进程注入、代码注入等高级系统编程场景。
接口名称
CreateRemoteThreadDLL调用
c
long CreateRemoteThread(long instance, long hwnd, long lpStartAddress, long lpParameter, int dwCreationFlags, long* lpThreadId);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| hwnd | 长整数型 | 窗口句柄或者进程ID。 |
| lpStartAddress | 长整数型 | 线程入口地址。 |
| lpParameter | 长整数型 | 线程参数。 |
| dwCreationFlags | 整数型 | 创建标志,控制线程的创建方式。 |
| lpThreadId | 长整数型指针 | 返回线程ID的指针。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
long handle = ola.CreateRemoteThread(hwnd, 0, 0, 0, "value");csharp
using OLAPlug;
var ola = new OLAPlugServer();
long handle = ola.CreateRemoteThread(hwnd, 0, 0, 0, "value");python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
handle = ola.CreateRemoteThread(hwnd, 0, 0, 0, "value")java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
long handle = ola.CreateRemoteThread(hwnd, 0, 0, 0, "value");cpp
var ola = com("OlaPlug.OlaSoft")
var handle = ola.CreateRemoteThread(hwnd, 0, 0, 0, "value")vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
handle = ola.CreateRemoteThread(hwnd, 0, 0, 0, "value")text
.局部变量 ola, OLAPlug
ola.创建 ()
handle = ola.CreateRemoteThread(hwnd, 0, 0, 0, "value")aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var handle = ola.CreateRemoteThread(hwnd, 0, 0, 0, "value");text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 handle = ola.CreateRemoteThread(hwnd, 0, 0, 0, "value")cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
long handle = ola.CreateRemoteThread(hwnd, 0, 0, 0, "value");原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
CreateRemoteThread(instance, hwnd, 0, 0, 0, 0);csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateRemoteThread(long ola, long hwnd, long lpStartAddress, long lpParameter, int dwCreationFlags, long lpThreadId);
long instance = CreateCOLAPlugInterFace();
CreateRemoteThread(instance, hwnd, 0, 0, 0, 0);python
from ctypes import CDLL, c_int, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ola.CreateRemoteThread(instance, hwnd, 0, 0, 0, 0)返回值
| 返回值 | 说明 |
|---|---|
非 0 | 成功,返回 线程句柄。 |
0 | 失败。 |
注意事项
| 项目 | 说明 |
|---|---|
| 权限 | 创建远程线程需要相应的进程权限。 |
| 线程入口地址必须在目标进程的地址空间内有效 | 线程入口地址必须在目标进程的地址空间内有效。 |
| 建议在不再需要线程句柄时调用 CloseHand | 建议在不再需要线程句柄时调用 CloseHandle 关闭。 |
| 创建挂起状态的线程可以使用 CREATE_SUS | 创建挂起状态的线程可以使用 CREATE_SUSPENDED 标志。 |
| 使用不当可能导致目标进程崩溃或系统不稳定 | 使用不当可能导致目标进程崩溃或系统不稳定。 |
