失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 使用 vim 和 xxd 编辑二进制文件

使用 vim 和 xxd 编辑二进制文件

时间:2019-11-29 08:15:20

相关推荐

使用 vim 和 xxd 编辑二进制文件

xxd

xxd [options] [files]

xxd 可以转储 [dump] 出文件的数据,反之亦可。例如:

xxd -l 0x30 /bin/ls00000000: 7f45 4c46 0201 0100 0000 0000 0000 0000 .ELF............00000010: 0300 3e00 0100 0000 5058 0000 0000 0000 ..>.....PX......00000020: 4000 0000 0000 0000 a003 0200 0000 0000 @...............

上面的命令dumpls命令二进制文件的前 0x30 个字节的数据,第一列是偏移,默认每行两字节一组,8组共16字节,最后一列是数据代表的字符,只显示可打印字符。

因此下面的命令将逐字节显示文件/bin/ls前 0x30 个字节的数据。

xxd -g 1 -l 0x30 /bin/ls00000000: 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 50 58 00 00 00 00 00 00 ..>.....PX......00000020: 40 00 00 00 00 00 00 00 a0 03 02 00 00 00 00 00 @...............

how-to-edit-binary-files-with-vim1

可以使用xxd工具配合 vim 来实现一个16进制编辑器。一个使用场景是更改二进制文件的数据,这样可以在不重新编译可执行文件的情况下,直接更改二进制中的某些指令用于调试。

// open file as binary mode.vim -b file:set binary// : enters command-line mode,// % matches whole file as a range, // ! filters that range through an external command// xxd is that external shell command:%!xxd// edit the file...// Once you make the changes (in the hex part), you can go back to text with -r command on xxd:%!xxd -r// rembember you can also use syntax highlighting for hex editing in vim with that command::set ft=xxd

armeb code dump:0x11223344and0xe3a01001mov r1, #1

00000030: 00 08 00 07 11 22 33 44 e3 a0 10 01 41 00 00 00 ....."3D....A...

arm code dump:0x11223344and0xe3a01001mov r1, #1

00000030: 08 00 07 00 44 33 22 11 01 10 a0 e3 41 1c 00 00 ....D3".....A...

/questions/343/how-to-edit-binary-files-with-vim ↩︎

如果觉得《使用 vim 和 xxd 编辑二进制文件》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。