我有以下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