将非 ASCII 字符输入到 scanf("%s") [英] Inputting Non ASCII characters to scanf("%s")
问题描述
有没有一种方法可以向使用 %s
的 scanf 发出非 ascii 十六进制字符?我正在尝试插入像 x08xDExAD
等十六进制字符(以演示缓冲区溢出).
Is there a way one can issue non ascii hex characters to a scanf that uses %s
? I'm trying to insert hexadecimal chars like x08xDExAD
and so on (to demonstrate buffer overflow).
输入的不是命令行参数,而是程序内部的一个scanf.
The input is not to a command line parameter, but to a scanf inside the program.
推荐答案
我假设你想在标准输入上提供任意数据(因为你使用 scanf
阅读).
I assume you want to feed arbitrary data on stdin (since you read with scanf
).
您可以使用 shell 创建数据并将其通过管道传输到您的程序中,例如
You can use the shell to create the data and pipe it into your program, e.g.
printf 'x08xDExAD' | yourprogram
请注意,这仅在没有空白字符被输入时才有效(因为 %s
格式的 scanf
在空白处停止).
Note that this will only work as long as there are no white-space characters to be fed (because scanf
with a %s
format stops at white-space).
这篇关于将非 ASCII 字符输入到 scanf("%s")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!