Skip to content

Instantly share code, notes, and snippets.

Created May 19, 2013 11:02
Show Gist options
  • Save anonymous/5607365 to your computer and use it in GitHub Desktop.
Save anonymous/5607365 to your computer and use it in GitHub Desktop.
test: test.c test.h
gcc -o test test.c
test.h: test.bin
xxd -i test.bin > test.h
test.bin: test.s
nasm -f bin -o test.bin test.s
clean:
rm test.bin test.h test
.PHONY: clean
#include <sys/mman.h>
#include <unistd.h>
#include "test.h"
int main(void) {
int (*func)();
int *pageptr;
pageptr = test_bin - ((int)test_bin % getpagesize());
mprotect(pageptr, getpagesize(), PROT_READ|PROT_EXEC);
func = (int (*)())test_bin;
(*func)();
return 0;
}
SECTION .text
BITS 64
mov rax, 1
mov rbx, 1
int 0x80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment