Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C printf formatting: What does "." and "|" mean in this context?

Tags:

c

I'm taking a security course and am having trouble understanding this code due to a lack of understanding of the C programming language.

printf  ("%08x.%08x.%08x.%08x|%s|");

I was told that this code should move along the stack until a pointer to a function is found.

I thought the . was just an indicator of precision of output, so I don't know what this means in this context since there are indicators of precision?

Also, I don't understand what the | means, and I can't find it in the C documentation.

like image 770
user1330217 Avatar asked Jan 12 '13 23:01

user1330217


Video Answer


2 Answers

The symbols have no special meaning here since they are outside of a format specifier, they are simply output literally. Note however that you haven't provided all the arguments that printf expects so it will instead print 5 values that happen to be on the stack.

like image 137
Neil Avatar answered Oct 13 '22 00:10

Neil


In this string the . and | characters are just outputted. The dots acted as separators for hex strings and the pipes highlighting a string.

The dots are only considered an indicator of precession if they appear after the % sign and before the format specifier, for example %4.2f.

like image 27
Steve Avatar answered Oct 12 '22 23:10

Steve