Skip to content

Instantly share code, notes, and snippets.

@romac
Created May 20, 2013 18:58
Show Gist options
  • Save romac/5614597 to your computer and use it in GitHub Desktop.
Save romac/5614597 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
int main( int argc, char * argv[] )
{
unsigned char code[] = "happy birthday";
void * mem = mmap(
NULL,
sizeof( code ),
PROT_WRITE | PROT_EXEC,
MAP_ANON | MAP_PRIVATE,
-1,
0
);
memcpy( mem, code, sizeof( code ) );
void ( * hb )() = mem;
// let's see what that's gonna do
// (not that I expect anything good)
hb();
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment