主题
指定窗口修改内存保护属性 - VirtualProtectEx
函数简介
修改指定的内存保护属性。
接口名称
VirtualProtectExDLL调用
int VirtualProtectEx(long instance, long hwnd, long addr, int size, int newProtect, int* oldProtect);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| hwnd | 长整数型 | 窗口句柄或进程ID。 |
| addr | 长整数型 | 要修改的内存地址。 |
| size | 整数型 | 需要修改的内存大小。 |
| newProtect | 整数型 | 内存类型:0x10 PAGE_EXECUTE 可执行,0x20 PAGE_EXECUTE_READ 可读可执行,0x40 PAGE_READWRITE 可读可写可执行,0x80 PAGE_EXECUTE_WRITECOPY。 |
| oldProtect | 整数型指针 | 返回修改前的保护属性。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int ret = ola.VirtualProtectEx(hwnd, 0, 0, 0, "value");csharp
using OLAPlug;
var ola = new OLAPlugServer();
int ret = ola.VirtualProtectEx(hwnd, 0, 0, 0, "value");python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
ret = ola.VirtualProtectEx(hwnd, 0, 0, 0, "value")java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
int ret = ola.VirtualProtectEx(hwnd, 0, 0, 0, "value");go
import "github.com/ola/olaplug/olaplug"
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
ret := ola.VirtualProtectEx(hwnd, 0, 0, 0, "value")rust
use olaplug::OLAPlugServer;
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let ret = ola.virtual_protect_ex(&hwnd, 0, 0, 0, "value");cpp
var ola = com("OlaPlug.OlaSoft")
var ret = ola.VirtualProtectEx(hwnd, 0, 0, 0, "value")vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ret = ola.VirtualProtectEx(hwnd, 0, 0, 0, "value")text
.局部变量 ola, OLAPlug
ola.创建 ()
ret = ola.VirtualProtectEx(hwnd, 0, 0, 0, “value”)aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var ret = ola.VirtualProtectEx(hwnd, 0, 0, 0, "value");text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
整数 ret = ola.VirtualProtectEx(hwnd, 0, 0, 0, "value")cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int32_t ret = ola.VirtualProtectEx(hwnd, 0, 0, 0, "value");原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
VirtualProtectEx(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 int VirtualProtectEx(long ola, long hwnd, long addr, int size, int newProtect, int oldProtect);
long instance = CreateCOLAPlugInterFace();
VirtualProtectEx(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.VirtualProtectEx(instance, hwnd, 0, 0, 0, 0)返回值
| 返回值 | 说明 |
|---|---|
1 | 成功。 |
0 | 失败。 |
