我有以下C
程序,我想通過更改內存地址來更改變量secret
。你能不能給我一個例子,我應該給以下兩個輸入來完成這個。任何幫助將大大appriciated更改存儲在變量中的內存地址C
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
unsigned secret = 0xdeadbeef;
int main(int argc, char **argv){
unsigned *ptr;
unsigned value;
printf("Welcome! I will grant you one arbitrary write!\n");
printf("Where do you want to write to? ");
scanf("%p", &ptr);
printf("Okay! What do you want to write there? ");
scanf("%p", (void **)&value);
printf("Writing %p to %p...\n", (void *)value, (void *)ptr);
*ptr = value;
printf("Value written!\n");
if (secret == 0x1337beef){
printf("Woah! You changed my secret!\n");
exit(0);
}
printf("My secret is still safe! Sorry.\n");
}
如果可以的話,請告訴我用一個例子
this line:scanf(「%p」,(void **)&value);將值的地址作爲void **進行投射。 scanf只關心地址和格式轉換,所以(無效**)是無用的 – user3629249 2014-11-02 11:20:43
寫一些用戶提供的地址(一些隨機地址)是一個很好的方式來崩潰程序,可能是一個seg故障。 – user3629249 2014-11-02 11:22:13