Executing machine code in memory

Run Settings
LanguageC
Language Version
Run Command
#include <stdio.h> #include <stdint.h> #include <string.h> #include <sys/mman.h> /* ; Returns 69 push rbp mov eax, 0x45 pop rbp ret */ uint8_t func[] = {0x55, 0xB8, 0x45, 0x00, 0x00, 0x00, 0x5D, 0xC3}; int (*test)(void); int main() { uint8_t *f = mmap(NULL, sizeof(func), PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, NULL); // PROT_READ probably not needed memcpy(f, func, sizeof(func)); test = f; printf("%d\n", test()); return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines