【发布时间】:2014-02-14 21:29:56
【问题描述】:
unsigned char hexData[14] = {
0x31, 0xC0, 0xBB, 0x42, 0x24, 0x80, 0x7C, 0x66,
0xB8, 0x88, 0x13, 0x50, 0xFF, 0xD3
};
void dummy(){}
int main()
{
void *code_ptr = &dummy;
PDWORD OP;
__asm
{
call code_ptr
add code_ptr,10h
}
VirtualProtect(code_ptr, 14, PAGE_EXECUTE_WRITECOPY, OP);
memcpy(code_ptr, hexData, 14);
.
.
.
在反汇编中
_LoadLibraryA@4:
003C11E0 jmp _LoadLibraryA@4 (03C1430h)
dummy:
003C11E5 jmp dummy (03C1A80h)
_printf:
003C11EA jmp _printf (03C1436h)
_VirtualProtect@16:
003C11EF jmp _VirtualProtect@16 (03C143Ch)
003C11F4 int 3
003C11F5 int 3
003C11F6 int 3
003C11F7 int 3
看来我可以在 003C11E5 之后复制 15 个块
但是当我这样做时,我得到访问访问冲突错误
我尝试使用 VirtualAlloc 之类的
void *code_ptr = &dummy;
code_ptr = VirtualAlloc(NULL, 14, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
memcpy(code_ptr, hexData, 14);
__asm
{
call code_ptr
}
我又遇到了这个错误
int (*func)();
func = (int (*)()) code;
(int)(*func)();
那个也不行
我的IDE是VS2013,我的操作系统是win8.1
我会很感激任何想法
【问题讨论】:
-
不能保证从函数类型转换为指向 void。
标签: c++ c operating-system windows-8.1 portable-executable