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;
    }
    
  • 相关阅读:
    软件工程课程设计团队项目总结与项目报告
    个人总结
    团队项目UI
    黄金点
    wordcount
    小学运算
    第七周
    第八周
    第六周博客
    第五周博客
  • 原文地址:https://www.cnblogs.com/kelthuzadx/p/10682246.html
Copyright © 2011-2022 走看看