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

标签 c string assembly hex buffer

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

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 code> 不是 ascii/字母数字值。

最佳答案

如果您想将任意字节作为参数发送到命令,则必须在 shell 中对它们进行转义。例如,在 bash 中,您可以执行以下操作:

echo $'a\x09b\x33c'

它会显示:

a       b3c

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

关于c - 如何将字符缓冲区中的十六进制地址转换为写入内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30385792/

相关文章:

c - 退出子进程

c - C-接受已知大小但未知类型的参数

ruby - Camel-cased 方法名的英文句子

c - 无法识别的选项“-tree-vectorize”

macos - 将 JonesForth 移植到 macOS v10.15 (Catalina)

c - fclose 似乎不能在 C 中工作

比较两个字符串,字典程序

java - 对子字符串内的子字符串进行排序

c - C 中的 strcat 错误

assembly - JS 在 Assembly x86 中做什么?