[英]What does this syntax *((unsigned int *)(buffer+i)) mean in C
This is the code:这是代码:
char *command, *buffer;
command = (char *) malloc(200);
bzero(command, 200);
strcpy(command, "./notesearch \'");
buffer = command + strlen(command);
for(int i=0; i < 160; i+=4) {
*((unsigned int *)(buffer+i)) = ret; // What does this syntax mean?
}
You can get the full code here => https://raw.githubusercontent.com/intere/hacking/master/booksrc/exploit_notesearch.c您可以在此处获取完整代码 => https://raw.githubusercontent.com/intere/hacking/master/booksrc/exploit_notesearch.c
Please help me I'm a beginner.请帮助我,我是初学者。
Read it from the inner part to the outer.从内到外阅读它。 Here we must suppose that
buffer
is a pointer to some memory area or array element.这里我们必须假设
buffer
是指向某个 memory 区域或数组元素的指针。 You have:你有:
buffer + 1
==> address to next memory position or next array element buffer + 1
==> 到下一个 memory position 或下一个数组元素的地址(unsigned int *)(buffer+i)
==> cast of resulting pointer to a pointer of type unsigned int
. (unsigned int *)(buffer+i)
==> 将结果指针转换为unsigned int
类型的指针。*((unsigned int *)(buffer+i))
==> dereference the unsigned int
pointed out (get the value). *((unsigned int *)(buffer+i))
==> 取消引用unsigned int
指出的(获取值)。*((unsigned int *)(buffer+i)) = ret;
==> assign the value to the variable ret
. ret
。 In C, when evaluating expressions, always go from the inside to the outer.在 C 中,计算表达式时,始终从内到外 go。
This writes the unsigned int
ret
to the address buffer+i
这会将
unsigned int
ret
写入地址buffer+i
*((unsigned int *)(buffer+i)) = ret
buffer+i
is a char*
(pointer to char
) buffer+i
是一个char*
(指向char
的指针)(unsigned int *)
in (unsigned int *)(buffer+i)
transforms the pointer to char into an pointer to unsigned int
. (unsigned int *)
(unsigned int *)(buffer+i)
中的 (unsigned int *) 将指向 char 的指针转换为指向unsigned int
的指针。 This is called a cast .*
dereferences this pointer to unsigned int
and writes ret
to that address.*
取消引用指向unsigned int
的指针并将ret
写入该地址。 Be aware that depending on the architecture of your hardware this may fail because of alignement issues.请注意,根据您的硬件架构,这可能会因为对齐问题而失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.