#include<stdio.h> #include<stdlib.h> int chunk_time =0; int chunk_size[50]; char *chunk_ptr[50]; voidinit(){ setvbuf(stdout, 0, 2, 0); setvbuf(stdin, 0, 2, 0); } voidgift(){ size_t puts_addr = (size_t)&puts; printf("%p",(void *)puts_addr); } voidmenu(){ puts("Life is fucking movie"); puts("Life is always full of unhappiness, like this question"); puts("Anyway, what's your answer"); puts(">"); } voidadd(){ int index; char size[20]; puts("What do you really want?"); if(chunk_time<=32&&chunk_time>=0){ if(!chunk_ptr[chunk_time]){ printf("This is the %dth choice in your life\n",chunk_time); puts("You can customize the size of chunk, but what about your life"); read(0,size,0x8); chunk_size[chunk_time] = atoi(size); chunk_ptr[chunk_time] = malloc(chunk_size[chunk_time]); chunk_time++; }else{ puts("error"); exit(0); } }else{ exit(0); puts(""); } } voidadd2(){ int index; char size[20]; puts("What do you really want?"); if(chunk_time<=32&&chunk_time>=0){ if(!chunk_ptr[chunk_time]){ printf("This is the %dth choice in your life\n",chunk_time); puts("You can customize the size of chunk, but what about your life"); read(0,size,0x8); chunk_size[chunk_time] = atoi(size); chunk_ptr[chunk_time] = calloc(1,chunk_size[chunk_time]); chunk_time++; }else{ puts("error"); exit(0); } }else{ exit(0); puts(""); } } voiddelete(){ char data[100]; int index; puts("I didn't set the pointer to zero, just like some things can't be repeated"); scanf("%d",&index); free(chunk_ptr[index]); } voidedit(){ int index; int size; puts("It's never too late to start again. What do you regret?"); scanf("%d",&index); puts("You all know that there can be overflows here, so why do you set limits on your life?"); scanf("%d",&size); puts("Come back!"); read(0,chunk_ptr[index],size); } voidshow(){ puts("You can't live a perfect life without making any effort"); int index; scanf("%d",&index); puts(chunk_ptr[index]); } intmain(){ int choice; init(); puts("This program is used to debug heap vulnerabilities"); puts("write by chen"); while(1){ menu(); scanf("%d",&choice); switch(choice){ case1: add(); break; case2: delete(); break; case3: edit(); break; case4: show(); break; case5: gift(); break; case6: add2(); break; case7: puts("The fog of that morning cleared, not only in the morning, but also in the fog"); puts("You will be stronger next time I see you"); exit(0); break; } } }