virtualProtect

// VirtualProtect.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "windows.h"
typedef void (*FUN)();

FUN fun = NULL;
int _tmain(int argc, _TCHAR* argv[])
{
    char* p2 = "Helloworld";
    char p[100] = {0xE9,0x01,0x20};
    DWORD Old = 0;
    VirtualProtect(p, 5, PAGE_EXECUTE_READWRITE, &Old);//修改完属性就可以执行了

    fun = (FUN)&p;
    //fun();          //栈区的属性是可读可写不可执行

    VirtualProtect(p2, 4, PAGE_EXECUTE_READWRITE, &Old);//修改完了,常量区也就可以写了

    p2[8] = 'W'; //常量区属性是可读不可写  


    return 0;
}

 

posted @ 2016-03-29 21:22  天还是那么蓝  阅读(808)  评论(0编辑  收藏  举报