如何将char缓冲区中的十六进制地址转换为写入内存

时间:2015-05-21 23:04:28

标签: c string assembly hex buffer

所以我在这里得到了这个函数,它是从main函数调用的:

void overflow(char *arg)
{
    char buf[1369];

    strcpy (buf, arg);

    printf ("Thank you for contacting customer service. You are so important to us that we wrote a program to serve you.\n");
    printf ("Please hold for %u minutes while I drop your call\n", (int)strlen(buf));

    return;
} 

字符串*arg来自argv[1]

当我做类似的事情时:


./overflow1 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa29390408

堆栈看起来像这样:


0xffffce80: 0x07    0x00    0x00    0x61    0x61    0x61    0x61    0x61
0xffffce88: 0x61    0x61    0x61    0x61    0x61    0x61    0x61    0x61
0xffffce90: 0x61    0x61    0x61    0x61    0x61    0x61    0x61    0x61
0xffffce98: 0x61    0x61    0x61    0x61    0x61    0x61    0x61    0x61
0xffffcea0: 0x61    0x61    0x61    0x61    0x61    0x61    0x61    0x61
0xffffcea8: 0x61    0x61    0x61    0x61    0x61    0x61    0x61    0x61
0xffffceb0: 0x61    0x61    0x61    0x61    0x61    0x61    0x61    0x61
0xffffceb8: 0x61    0x61    0x61    0x61    0x61    0x61    0x61    0x61
0xffffcec0: 0x61    0x61    0x32    0x39    0x33    0x39    0x30    0x34
0xffffcec8: 0x30    0x38

那我怎么得到:

0x32 0x39 0x33 0x39 0x30 0x34 0x30 0x38

是:

29 39 04 08

我确实认识到这需要从实际的十六进制值转换为字母数字值,例如08,但是网络上的每个字符串工具都没有给出结果,因为08不是ascii /字母数字值。

1 个答案:

答案 0 :(得分:0)

如果要将任意字节作为参数发送到命令,则必须在shell中将它们转义。例如,在bash中,你可以这样做:

echo $'a\x09b\x33c'

它会显示:

a       b3c

因为bash将$''结构中的\ xHH(两个十六进制数字)解释为单字节十六进制值。 0x09是一个标签,0x33是数字3。