聘我网

新概念招聘3.0

如何解读这段hexdump脚本?

vote up0vote downstar
[root@test]# hexdump -e '"%06_ax " 16/1 "%02X " "\n"' bar.c 
000000 23 69 6E 63 6C 75 64 65 20 22 66 6F 6F 2E 68 22
000010 0A 0A 76 6F 69 64 0A 62 61 72 28 76 6F 69 64 29
000020 0A 7B 0A 20 20 72 65 74 75 72 6E 3B 0A 7D 0A 0A

那段format如何解读?

 

1 个答复

vote up0vote downcheck

man hexdump可以发现关于-e format_string的解释,除了支持printfconvertion specifier外,还额外支持以下转换符号:

 _a[dox]     Display the input offset, cumulative across input files, of the next byte to be displayed.  The appended char-
             acters d, o, and x specify the display base as decimal, octal or hexadecimal respectively.

 _A[dox]     Identical to the _a conversion string except that it is only performed once, when all of the input data has
             been processed.

 _c          Output characters in the default character set.  Nonprinting characters are displayed in three character,
             zero-padded octal, except for those representable by standard escape notation (see above), which are displayed
             as two character strings.

 _p          Output characters in the default character set.  Nonprinting characters are displayed as a single “.”.

 _u          Output US ASCII characters, with the exception that control characters are displayed using the following,
             lower-case, names.  Characters greater than 0xff, hexadecimal, are displayed as hexadecimal strings.

printfformat格式是

[flag][field width][precision][length modifier][convertion specifier]

"%06_ax " 16/1 "%02X " "\n"对号入座

%06_axflag0field width6_ax转换符。

%02Xflag0field width2X转换符。

16/1分别是hexdumpformat unititeration countbyte count

A format string contains any number of format units, separated by whitespace. A format unit contains up to three items: an iteration count, a byte count, and a format.

链接

您的回答





不是您要找的问题? 浏览其他含有标签 的问题或者 自己问个.