Код: Выделить всё
#include
#include
#include
#include
#include
#include
void a() {
printf("a");
}
int main() {
char * heap_pointer;
char * func_pointer;
int ret;
int pagesize;
int c;
func_pointer = (char *) a;
pagesize = sysconf(_SC_PAGE_SIZE);
heap_pointer = aligned_alloc(pagesize, pagesize); //alligned memory allocation
c = 0;
while(func_pointer[c] != (char)0xc3) { //copying the instructions from one pointer to the other
heap_pointer[c] = func_pointer[c];
c++;
}
heap_pointer[c] = (char)0xc3;
mprotect(heap_pointer, pagesize, PROT_WRITE | PROT_READ | PROT_EXEC); //allowing execution
(*(void (*)())(func_pointer))();
(*(void (*)())(heap_pointer))();
mprotect(heap_pointer, pagesize, PROT_READ);
return 0;
}
Код: Выделить всё
00000000000011a9 :
11a9: f3 0f 1e fa endbr64
11ad: 55 push %rbp
11ae: 48 89 e5 mov %rsp,%rbp
11b1: bf 61 00 00 00 mov $0x61,%edi
11b6: e8 c5 fe ff ff call 1080
11bb: 90 nop
11bc: 5d pop %rbp
11bd: c3 ret
Подробнее здесь: https://stackoverflow.com/questions/798 ... ermissions
Мобильная версия