繁体   English   中英

为什么我的代码只能在Windows XP 32位系统上运行?[代码生成]

[英]Why my code can only run on windows xp 32bit system?[code generation]

我正在尝试编写一个生成x86机器代码的程序,但是该代码只能在32位winxp上运行。 它说:“ tiny.exe中0x776315ee处有未处理的异常:0xC0000005:访问冲突。” 在win7 64bit上,为什么?

#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

int main()
{
    char *code = (char *)malloc(1024);
    memset(code, 0, 1024);

    char opcode = 0xB8;
    memcpy(code, &opcode, sizeof(char));

    int oprand = 2;
    memcpy(code + sizeof(char), &oprand, sizeof(int));

    char opret = 0xC3;
    memcpy(code + sizeof(char) + sizeof(int), &opret, sizeof(char));

    typedef void (* func_t)(void);
    func_t func = (func_t)code;

    func();

    return 0;
}

防止在堆上分配的内存被DEP可执行。 它可能在XP计算机上被禁用,或者可能是其他原因,但无论是什么原因:除了malloc() ,您还必须调用(至少)具有PAGE_EXECUTE_READWRITE作为flProtect VirtualAlloc()来动态分配代码可以使用的内存被执行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM