Created
September 19, 2011 02:42
-
-
Save 7shi/1225880 to your computer and use it in GitHub Desktop.
JIT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <stdio.h> | |
#include <string.h> | |
unsigned char testf[] = { | |
0x8b, 0x44, 0x24, 0x04, // mov eax, [esp+4] | |
0x03, 0x44, 0x24, 0x08, // add eax, [esp+8] | |
0xc3 // ret | |
}; | |
int main() { | |
auto page = VirtualAlloc(nullptr, sizeof(testf), MEM_COMMIT, PAGE_EXECUTE_READWRITE); | |
memcpy(page, testf, sizeof(testf)); | |
auto test = reinterpret_cast<int(*)(int, int)>(page); | |
printf("test(2, 3): %d\n", test(2, 3)); | |
VirtualFree(page, 0, MEM_RELEASE); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "xbyak/xbyak.h" | |
struct TestFunc : public Xbyak::CodeGenerator { | |
TestFunc() { | |
mov(eax, ptr[esp+4]); | |
add(eax, ptr[esp+8]); | |
ret(); | |
} | |
}; | |
int main() { | |
TestFunc testf; | |
auto test = reinterpret_cast<int(*)(int, int)>( | |
const_cast<Xbyak::uint8 *>(testf.getCode())); | |
printf("test(2, 3): %d\n", test(2, 3)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment