博客专栏

EEPW首页 > 博客 > Linux下查看二进制文件命令-hexdump

Linux下查看二进制文件命令-hexdump

发布人:电子禅石 时间:2020-03-10 来源:工程师 发布文章

一、在Linux下查看二进制文件的软件:

 

xxd

 

hexdump

root@imx6qsabresd:/home/v2x# hexdump -C EA_PublicKey.key |less -S
00000000  04 b0 cd 7f 67 e5 59 38  41 b9 d7 ca 25 4c 27 ca  |....g.Y8A...%L'.|
00000010  bd 46 9e 36 69 66 16 70  84 b7 fa d1 bf 35 64 d2  |.F.6if.p.....5d.|
00000020  aa 4a d4 f7 d5 a9 5d 49  8f 63 b7 3a f8 a4 18 b1  |.J....]I.c.:....|
00000030  63 20 0a e7 e1 17 87 00  93 0d cf 28 bb 69 aa 17  |c .........(.i..|
00000040  c1
Usage:
 hexdump [options] <file>...
Display file contents in hexadecimal, decimal, octal, or ascii.
Options:
 -b, --one-byte-octal      one-byte octal display
 -c, --one-byte-char       one-byte character display
 -C, --canonical           canonical hex+ASCII display
 -d, --two-bytes-decimal   two-byte decimal display
 -o, --two-bytes-octal     two-byte octal display
 -x, --two-bytes-hex       two-byte hexadecimal display
 -L, --color[=<mode>]      interpret color formatting specifiers
                             colors are enabled by default
 -e, --format <format>     format string to be used for displaying data
 -f, --format-file <file>  file that contains format strings
 -n, --length <length>     interpret only length bytes of input
 -s, --skip <offset>       skip offset bytes from the beginning
 -v, --no-squeezing        output identical lines
 -h, --help     display this help and exit
 -V, --version  output version information and exit


 

二、编辑:

 

1、biew

 

2、hexedit

 

3、vim

 

Vim 来编辑二进制文件。Vim 本非为此而设计的,因而有若干局限。但你能读

取一个文件,改动一个字符,然后把它存盘。结果是你的文件就只有那一个字符给改了,

其它的就跟原来那个一模一样。

   要保证 Vim 别把它那些聪明的窍门用错地方,启动 Vim 时加上 "-b" 参数:

        vim -b datafile

这个参数设定了 'binary' 选项。其作用是排除所有的意外副作用。例如,'textwidth'

设为零,免得文本行给擅自排版了。并且,文件一律以 Unix 文件格式读取。

二进制模式可以用来修改某程序的消息报文。小心别插入或删除任何字符,那会让程序运

行出问题。用 "R" 命令进入替换模式。

文件里的很多字符都是不可显示的。用 Hex 格式来显示它们的值:

        :set display=uhex

另外,也可以用命令 "ga"  来显示光标下的字符值。当光标位于一个  字符上时,

该命令的输出看起来就像这样:

          27, Hex 1b,  Octal 033

文件中也许没那么多换行符。你可以关闭 'wrap' 选项来获得总览的效果:

        :set nowrap

字 节 位 置

要发现你在文件中的当前字节位置,请用这个命令:

        g CTRL-G

其输出十分冗长:

    Col 9-16 of 9-16; Line 277 of 330; Word 1806 of 2058; Byte 10580 of 12206

最后两个数字就是文件中的当前字节位置和文件字节总数。这已经考虑了 'fileformat'

选项导致换行符字节不同的影响。

要移到文件中某个指定的字节,请用 "go" 命令。例如,要移到字节 2345:

        2345go

使 用 XXD

一个真正的二进制编辑器用两种方式来显示文本: 二进制和十六进制格式。你可以在 Vim

里通过转换程序 "xxd" 来达到这效果。该程序是随 Vim 一起发布的。

   首先以二进制方式编辑这个文件:

        vim -b datafile

现在用 xxd 把这个文件转换成十六进制:

        :%!xxd

文本看起来像这样:

        0000000: 1f8b 0808 39d7 173b 0203 7474 002b 4e49  ....9..;..tt.+NI

        0000010: 4b2c 8660 eb9c ecac c462 eb94 345e 2e30  K,.`.....b..4^.0

        0000020: 373b 2731 0b22 0ca6 c1a2 d669 1035 39d9  7;'1.".....i.59.

现在你可以随心所欲地阅读和编辑这些文本了。 Vim 把这些信息当作普通文本来对待。

修改了十六进制部分并不导致可显示字符部分的改变,反之亦然。

   最后,用下面的命令把它转换回来:

        :%!xxd -r

只有十六进制部分的修改才会被采用。右边可显示文本部分的修改忽略不计。


*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。



关键词:

相关推荐

技术专区

关闭