Last active
April 24, 2017 11:40
-
-
Save koturn/45d8f0c9073fb93e0b597f68f746a2b4 to your computer and use it in GitHub Desktop.
Hello World on Windows x64
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> | |
#if defined(_MSC_VER) | |
# pragma section(".text", read, execute) | |
__declspec(allocate(".text")) | |
#elif defined(__GNUC__) | |
__attribute__((section(".text"))) | |
#endif | |
const char code[] = | |
// push %rbp | |
"\x55" | |
// mov %rsp,%rbp | |
"\x48\x89\xe5" | |
// mov %rcx,%rax | |
"\x48\x89\xc8" | |
// lea 0x0f(%rip),%rcx | |
"\x48\x8d\x0d\x0f\x00\x00\x00" | |
// sub $0x20,%rsp | |
"\x48\x83\xec\x20" | |
// callq *%rax | |
"\xff\xd0" | |
// add $0x20,%rsp | |
"\x48\x83\xc4\x20" | |
// mov %rbp,%rsp | |
"\x48\x89\xec" | |
// pop %rbp | |
"\x5d" | |
// retq | |
"\xc3" | |
// String data | |
"Hello World!"; | |
int | |
main() | |
{ | |
// DWORD old_protect; | |
// VirtualProtect((LPVOID) code, sizeof(code), PAGE_EXECUTE_READWRITE, &old_protect); | |
((void (*)(int (*)(const char *))) (char *) code)(puts); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment