Created
November 22, 2009 06:57
-
-
Save ice799/240470 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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sys/mman.h> | |
int rb_new_obj() { | |
printf("hi\n"); | |
exit(1); | |
} | |
void test() { | |
int i = 10; | |
int j = i * j; | |
printf("%d\n", sizeof(i)); | |
return; | |
} | |
static void *blah = &rb_new_obj; | |
//void Init_memprof() | |
void main() | |
{ | |
char assembly[] = { "\xff\x14\x25\x90\x90\x90\x90\x90\x90\x90\x90"}; | |
int i = 0; | |
int x = 0; | |
for (; i < sizeof(long); i++) { | |
assembly[i+3] = ((long)&blah >> i*8) & 0xff; | |
} | |
printf("blah: %p\n", &blah); | |
for(i = 0; i < sizeof(long) + 1; i++) { | |
printf("k: %x\n", assembly[i]); | |
} | |
printf("norm: %p, page: %p\n", test, (void*)(((long)&test)&(0xffffffffffff0000))); | |
if (mprotect((void*)(((long)&test)&(0xffffffffffff0000)), 11, PROT_WRITE|PROT_READ|PROT_EXEC) == -1) | |
perror("asdasdsa\n"); | |
memcpy(test, assembly, 11); | |
mprotect((void*)(((long)&test)& (~(0x1 << 4))), 11, PROT_READ|PROT_EXEC); | |
test(); | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment