C - The %x format specifier

前端 未结 5 1856
礼貌的吻别
礼貌的吻别 2020-12-22 23:15

I have a small question. I know that the %x format specifier can be used to read values from the stack in a format string attack.

I found the following code:

<
5条回答
  •  时光取名叫无心
    2020-12-22 23:59

    Break-down:

    • 8 says that you want to show 8 digits
    • 0 that you want to prefix with 0's instead of just blank spaces
    • x that you want to print in lower-case hexadecimal.

    Quick example (thanks to Grijesh Chauhan):

    #include 
    int main() {
        int data = 29;
        printf("%x\n", data);    // just print data
        printf("%0x\n", data);   // just print data ('0' on its own has no effect)
        printf("%8x\n", data);   // print in 8 width and pad with blank spaces
        printf("%08x\n", data);  // print in 8 width and pad with 0's
    
        return 0;
    }
    

    Output:

    1d
    1d
          1d
    0000001d
    

    Also see http://www.cplusplus.com/reference/cstdio/printf/ for reference.

提交回复
热议问题