写个好玩的JIT demo,仅限Intel x86+ windows+msvc

2021-06-18 10:03

阅读:570

标签:write   cut   const   ...   commit   reserve   x64   return   null   

#include 
#include 
#include 
#define BACK_FILL (0)

int main() {
    char* native = (char*)VirtualAlloc(NULL, 1024, MEM_COMMIT | MEM_RESERVE,
                                       PAGE_EXECUTE_READWRITE);
    char code[] = {0x68, 0x65, 0x6c, 0x6c,      0x6f,      0x20,      0x77,
                   0x6f, 0x72, 0x6c, 0x64,      0x00,      0xff,      0xf5,
                   0x89, 0xe5, 0x68, BACK_FILL, BACK_FILL, BACK_FILL, BACK_FILL,
                   0xff, 0x95, 0x08, 0x00,      0x00,      0x00,      0x81,
                   0xc4, 0x04, 0x00, 0x00,      0x00,      0x8f,      0xc5,
                   0xc3, 0x00};
    memcpy(native, code, sizeof(code) / sizeof(char));
    *(int32_t*)(native + 17) = (int32_t)native;
    ((void (*)(int (*)(const char*, ...)))(native + 12))(&printf);
    VirtualFree(native, 0, MEM_RELEASE);
    getchar();
    return 0;
}

have fun~

写个好玩的JIT demo,仅限Intel x86+ windows+msvc

标签:write   cut   const   ...   commit   reserve   x64   return   null   

原文地址:https://www.cnblogs.com/racaljk/p/10311837.html


评论


亲,登录后才可以留言!