it use like in c11/c++?:
printf("%2$*11$s",...)
It is come from a elf file, this file using printf() to operate like mem[4]=mem[2]+mem[1]
. You can refer from this https://ctftime.org/task/5042 (it is a reverse CTF question).
To my point, I know the $ is use to specify the position of which var but no reference notice that one block can have two $.
also, I cannot find any func about $ in format except location.
so, I will be grateful if anyone can tell me it is meaning.
In C printf(), %n is a special format specifier which instead of printing something causes printf() to load the variable pointed by the corresponding argument with a value equal to the number of characters that have been printed by printf() before the occurrence of %n.
We can print the string using %s format specifier in printf function. It will print the string from the given starting address to the null '\0' character. String name itself the starting address of the string. So, if we give string name it will print the entire string.
%s refers to a string %d refers to an integer %c refers to a character. Therefore: %s%d%s%c\n prints the string "The first character in sting ", %d prints i, %s prints " is ", and %c prints str[0].
n$
is an extension defined in POSIX to select which argument to print. This is called Parameter field.
printf format string - Wikipedia
Actually this question is about using two n$
in one format specifier. Let me examine with small examples...
#include <stdio.h>
int main(void) {
printf("%1$*3$s\n", "a", "b", 10, 20);
printf("%1$*4$s\n", "a", "b", 10, 20);
printf("%2$*3$s\n", "a", "b", 10, 20);
printf("%2$*4$s\n", "a", "b", 10, 20);
return 0;
}
Output:
a
a
b
b
It looks like %n$*m$s
means "print the n
-th argument using the width specified by the m
-th argument". The final s
has the meaning of s
in %s
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With