向scanf输入非ASCII字符("%s") [英] Inputting Non ASCII characters to scanf("%s")

查看:312
本文介绍了向scanf输入非ASCII字符("%s")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法可以发出非ASCII ASCII字符到一个scanf,使用%s ?我尝试插入十六进制字符,如 \x08\xDE\xAD 等等(以演示缓冲区溢出)。



输入的不是一个命令行参数,而是一个到程序里面的scanf。

解决方案

假设你想在stdin上提供任意数据(因为你使用 scanf )读取数据。)

你可以使用shell以创建数据并将其传送到您的程序中,例如

  printf'\x08\xDE\xAD'|你的程序

请注意,只有在没有空白字符时才会工作因为 scanf 与一个%s 格式停在空白处)。


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 \x08\xDE\xAD and so on (to demonstrate buffer overflow).

The input is not to a command line parameter, but to a scanf inside the program.

解决方案

I assume you want to feed arbitrary data on stdin (since you read with scanf).

You can use the shell to create the data and pipe it into your program, e.g.

printf '\x08\xDE\xAD' | yourprogram

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).

这篇关于向scanf输入非ASCII字符("%s")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆