如何解决这个语法 *((unsigned int *)(buffer+i)) 在 C 中是什么意思
这是代码:
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?
}
您可以在此处获取完整代码 => https://raw.githubusercontent.com/intere/hacking/master/booksrc/exploit_notesearch.c
请帮助我,我是初学者。
解决方法
从内部到外部阅读。这里我们必须假设 buffer
是指向某个内存区域或数组元素的指针。
你有:
-
buffer + 1
==> 下一个内存位置或下一个数组元素的地址 -
(unsigned int *)(buffer+i)
==> 将结果指针转换为unsigned int
类型的指针。 -
*((unsigned int *)(buffer+i))
==> 取消引用unsigned int
指出的(获取值)。 -
*((unsigned int *)(buffer+i)) = ret;
==> 将值赋给变量ret
。
在 C 中,计算表达式时,总是从内到外。
,这会将 unsigned int
ret
写入地址 buffer+i
*((unsigned int *)(buffer+i)) = ret
-
buffer+i
是一个char*
(指向char
的指针) -
(unsigned int *)
中的(unsigned int *)(buffer+i)
将指向 char 的指针转换为指向unsigned int
的指针。这称为演员。 - 最后,
*
将此指针取消引用到unsigned int
并将ret
写入该地址。
请注意,根据您的硬件架构,这可能会因为对齐问题而失败。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。