Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Alas, it's technically difficult to get input from the user using printf.


If you’re willing to lose almost all portability, I think you could read a value from an I/O port, pass that to printf, use that as the field width for a string to print, count the character length of the resulting string using %n to move it into a variable, and then backspace over that to prevent the output from dirtying your output. You could only use the results in a subsequent call to printf, though.

Of course, just hiding an assignment in a printf argument would be much easier, but wouldn’t be fun.

Of course, that would lose lots and lots of portability, and you could, likely, only get it to work on systems that don’t do memory protection between processes, and then, not all of them.

I guess it would not be very hard to use this trick to have printf read joysticks on many micro’s from the 1980’s.


In that case it might just be easier to ROP your way to scanf.


Hmm that is a good point :-)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: