Skip to content

Instantly share code, notes, and snippets.

@moyix
Created March 16, 2018 20:16
Show Gist options
  • Save moyix/e8730927ab470828625855e941f7c1b9 to your computer and use it in GitHub Desktop.
Save moyix/e8730927ab470828625855e941f7c1b9 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
int main(int argc, char **argv) {
unsigned char bytes[] = {
0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0x90, // rep*14 nop
0xc3 // ret
};
unsigned char *code = (unsigned char *) mmap(NULL, 0x1000, PROT_READ|PROT_WRITE|PROT_EXEC,
MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
printf("Code mapped at %p\n", code);
memcpy(code, bytes, 16);
((void (*)(void))code)();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment