本文介绍了C - %x 格式说明符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个小问题.我知道 %x 格式说明符可用于在格式字符串攻击中从堆栈中读取值.
I have a small question. I know that the %x format specifier can be used to read values from the stack in a format string attack.
我找到了以下代码:
%08x%08x%08x%08x
08 是什么意思?它到底在做什么?谢谢:)
What does the 08 mean? What is it doing exactly? Thanks :)
推荐答案
故障:
8
表示要显示8位数字0
你想用0
的前缀而不是空格x
要以小写十六进制打印.
8
says that you want to show 8 digits0
that you want to prefix with0
's instead of just blank spacesx
that you want to print in lower-case hexadecimal.
快速示例(感谢 Grijesh Chauhan):
Quick example (thanks to Grijesh Chauhan):
#include <stdio.h>
int main() {
int data = 29;
printf("%x
", data); // just print data
printf("%0x
", data); // just print data ('0' on its own has no effect)
printf("%8x
", data); // print in 8 width and pad with blank spaces
printf("%08x
", data); // print in 8 width and pad with 0's
return 0;
}
输出:
1d
1d
1d
0000001d
另请参阅 http://www.cplusplus.com/reference/cstdio/printf/ 以供参考.
Also see http://www.cplusplus.com/reference/cstdio/printf/ for reference.
这篇关于C - %x 格式说明符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!