执行汇编指令 - AsmCall
函数简介
在指定进程中执行汇编指令,支持多种执行模式。
接口名称
AsmCall
DLL调用
long AsmCall(long instance, long hwnd, string asmStr, int type, long baseAddr);
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| hwnd | 长整数型 | 窗口句柄或进程ID,根据type参数决定用途 |
| asmStr | 字符串 | 汇编语言字符串,大小写均可,如"mov eax,1",也支持输入机器码 |
| type | 整数型 | 执行类型: 0: 在本进程中执行(创建线程),hwnd无效 1: 在hwnd指定进程内执行(创建远程线程) 2: 在已注入绑定的目标进程创建线程执行(需排队) 3: 同模式2,但在hwnd所在线程直接执行 4: 同模式0,但在当前线程直接执行 5: 在hwnd指定进程内执行(APC注入) 6: 直接在hwnd所在线程执行 |
| baseAddr | 长整数型 | 汇编指令所在的地址,如果为0则自动分配内存 |
示例
// 在当前进程中执行简单汇编指令
char asm_code[] = "mov eax, 123\nret";
long result = AsmCall(ola, 0, asm_code, 0, 0);
printf("执行结果: %ld\n", result);
// 在目标进程中执行汇编指令
long target_hwnd = FindWindow(ola, "Notepad", "");
if (target_hwnd != 0) {
char asm_code[] = "mov eax, 456\nret";
long result = AsmCall(ola, target_hwnd, asm_code, 1, 0);
printf("远程执行结果: %ld\n", result);
}
// 直接在当前线程执行
char asm_code[] = "mov eax, 111\nmov edx, 222\nret";
long result = AsmCall(ola, 0, asm_code, 4, 0);
printf("当前线程执行结果: %ld\n", result);
返回值
长整数型,32位进程返回EAX,64位进程返回RAX,执行失败返回0。
注意事项
- 错误的汇编指令可能导致程序崩溃,建议在测试环境中先验证
- 不同执行模式适用于不同场景,请根据需求选择合适的type参数
- 在目标进程中执行需要相应的权限
- 使用APC注入模式(type=5)需要开启memory防护盾
- 返回值的解释取决于汇编指令的具体内容
