zoukankan      html  css  js  c++  java
  • 最小化JIT示例(仅限Intel x86+Windows)

    #include <Windows.h>
    #include <cstdint>
    #include <cstring>
    #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;
    }
    
  • 相关阅读:
    K
    A
    C
    E
    2020/9/14
    hdu5306 hdu3954 cf438D
    2020/9/10-9/11
    题解
    2020/8/31
    2020/8/30
  • 原文地址:https://www.cnblogs.com/kelthuzadx/p/10682246.html
Copyright © 2011-2022 走看看