十六进制转储输出

问题描述 投票:0回答:1

我非常喜欢hd命令的默认格式。例如:

$ head -c128 /bin/bash |hd
00000000  7f 45 4c 46 02 01 01 00  00 00 00 00 00 00 00 00  |.ELF............|
00000010  03 00 3e 00 01 00 00 00  30 f6 02 00 00 00 00 00  |..>.....0.......|
00000020  40 00 00 00 00 00 00 00  48 ce 11 00 00 00 00 00  |@.......H.......|
00000030  00 00 00 00 40 00 38 00  0b 00 40 00 1d 00 1c 00  |[email protected]...@.....|
00000040  06 00 00 00 04 00 00 00  40 00 00 00 00 00 00 00  |........@.......|
00000050  40 00 00 00 00 00 00 00  40 00 00 00 00 00 00 00  |@.......@.......|
00000060  68 02 00 00 00 00 00 00  68 02 00 00 00 00 00 00  |h.......h.......|
00000070  08 00 00 00 00 00 00 00  03 00 00 00 04 00 00 00  |................|
00000080

我正在寻找一个执行相同操作但是双倍宽度的hexdump命令。输出应类似于:

$ head -c128 /bin/bash |2hd
00000000  7f 45 4c 46 02 01 01 00  00 00 00 00 00 00 00 00  03 00 3e 00 01 00 00 00  30 f6 02 00 00 00 00 00  |.ELF............| |..>.....0.......|
00000020  40 00 00 00 00 00 00 00  48 ce 11 00 00 00 00 00  00 00 00 00 40 00 38 00  0b 00 40 00 1d 00 1c 00  |@.......H.......| |[email protected]...@.....|
00000040  06 00 00 00 04 00 00 00  40 00 00 00 00 00 00 00  40 00 00 00 00 00 00 00  40 00 00 00 00 00 00 00  |........@.......| |@.......@.......|
00000060  68 02 00 00 00 00 00 00  68 02 00 00 00 00 00 00  08 00 00 00 00 00 00 00  03 00 00 00 04 00 00 00  |h.......h.......| |................|
00000080

到目前为止,我已经知道了。排列不正确。

2hd() {
  local poe='"  " 8/1 "%02x "'  # pieces of eight, heh
  hexdump -e '"%07.7_Ax\n"' \
          -e '"%07.7_ax" '"$poe $poe $poe $poe"' "  |" 32/1 "%_p" "|\n"' "$@"
}
$ head -c128 /bin/bash |2hd
0000000  7f 45 4c 46 02 01 01 00  00 00 00 00 00 00 00 00  03 00 3e 00 01 00 00 00  30 f6 02 00 00 00 00 00  |@[email protected]...@.....|
0000040  06 00 00 00 04 00 00 00  40 00 00 00 00 00 00 00  40 00 00 00 00 00 00 00  40 00 00 00 00 00 00 00  |h.......h.......................|
0000080  a8 02 00 00 00 00 00 00  a8 02 00 00 00 00 00 00  a8 02 00 00 00 00 00 00  1c 00 00 00 00 00 00 00  |................................|
00000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  98 cd 02 00 00 00 00 00  98 cd 02 00 00 00 00 00  |................................|
0000100

((我还没有决定是否要将右侧显示器分成两半。)

我希望在对hexdump的单一引用中完全做到这一点。知道获得16列hexdump输出的hd命令看起来也将是有帮助的。 (我可以找到的文档对此没有帮助。)

shell formatting hex hexdump
1个回答
1
投票

我想您可能只需要分割第二个-e

2hd() {
  local poe='"  " 8/1 "%02x "'
  hexdump -e '"%07.7_Ax\n"' \
          -e '"%07.7_ax" '"$poe $poe $poe $poe" \
          -e ' "  |" 32/1 "%_p" "|\n"' "$@"
}

多个-e每个都在同一输入上工作。在您的原始文件中,%_p适用于输入%x的输入[,因为它位于相同的-e中。


[busybox hexdump source定义-C为:

bb_dump_add(dumper, "\"%08.8_Ax\n\""); // final address line after dump //------------------- "address " 8 * "xx " " " 8 * "xx " bb_dump_add(dumper, "\"%08.8_ax \"8/1 \"%02x \"\" \"8/1 \"%02x \""); //------------------- " |ASCII...........|\n" bb_dump_add(dumper, "\" |\"16/1 \"%_p\"\"|\n\"");

因此,您可以将hd实现为:

hexdump -e "\"%08.8_Ax\n\"" -e "\"%08.8_ax \"8/1 \"%02x \"\" \"8/1 \"%02x \"" \ -e "\" |\"16/1 \"%_p\"\"|\n\""

© www.soinside.com 2019 - 2024. All rights reserved.