Created
May 19, 2013 11:02
-
-
Save anonymous/5607365 to your computer and use it in GitHub Desktop.
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
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 |
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 <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; | |
} |
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
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