Bash 'printf' equivalent for command prompt?

I'm looking to pipe some String input to a small C program in Windows's command prompt. In bash I could use

$ printf "AAAAAx86x08x04xed" | ./program

Essentially, I need something to escape those hexadecimal numbers in command prompt.

Is there an equivalent or similar command for printf in command prompt/powershell?

Thanks


在PowerShell中,你可以这样做:

"AAAAA{0}{1}{2}{3}" -f 0x86,0x08,0x04,0xed | ./program

I recently came up with the same question myself and decided that for someone developing Windows exploits it is worth installing cygwin :)

Otherwise one could build a small C program mimicking printf 's functionality:

#include <string.h>

int main(int argc, char *argv[])
{
    int i;
    char tmp[3];

    tmp[2] = '';

    if (argc > 1) {
        for (i = 2; i < strlen(argv[1]); i += 4) {
            strncpy(tmp, argv[1]+i, 2);
            printf("%c", (char)strtol(tmp, NULL, 16));
        }
    }
    else {
        printf("USAGE: printf.exe SHELLCODEn");
        return 1;
    }

    return 0;
}

The program only handles "xABxCD" strings, but it shouldn't be difficult to extend it to handle "AAAAAxABxCD" strings if one needs it.

链接地址: http://www.djcxy.com/p/25716.html

上一篇: 如何在Python中scp?

下一篇: Bash'printf'等效于命令提示符?