利用Emacs编辑字节流文件

来源:互联网 发布:创建数据表的sql语句 编辑:程序博客网 时间:2024/06/08 19:29

42 Editing Binary Files

There is a special major mode for editing binary files: Hexl mode. To use it, use M-x hexl-find-file instead of C-x C-f to visit the file. This command converts the file’s contents to hexadecimal and lets you edit the translation. When you save the file, it is converted automatically back to binary.

You can also use M-x hexl-mode to translate an existing buffer into hex. This is useful if you visit a file normally and then discover it is a binary file.

Ordinary text characters overwrite in Hexl mode. This is to reduce the risk of accidentally spoiling the alignment of data in the file. There are special commands for insertion. Here is a list of the commands of Hexl mode:

C-M-d

Insert a byte with a code typed in decimal.

C-M-o

Insert a byte with a code typed in octal.

C-M-x

Insert a byte with a code typed in hex.

C-x [

Move to the beginning of a 1k-byte “page”.

C-x ]

Move to the end of a 1k-byte “page”.

M-g

Move to an address specified in hex.

M-j

Move to an address specified in decimal.

C-c C-c

Leave Hexl mode, going back to the major mode this buffer had before you invoked hexl-mode.

Other Hexl commands let you insert strings (sequences) of binary bytes, move by shorts or ints, etc.; type C-h a hexl-RET for details.


备注:

1)在Hexl Mode中不能直接编辑字节值,而只能通过更改相应的ASCII字符来更新字节值,这就限制了能够取到的字节值的范围

2)在Hexl Mode中不能直接删除字节,虽然可通过如下方式,来“曲线救国”:

Hexl mode does not allow you to delete characters. This answer from stack overflow suggests a workaround: overwrite the characters you want to delete with another character (say "X"), switch out of hexl mode, find the characters and delete them there.


综上,Emacs的Hexl Mode对于作为一个编辑字节流数据的工具来说,是个鸡肋。


参考文献:

[1]https://www.gnu.org/software/emacs/manual/html_node/emacs/Editing-Binary-Files.html

[2]http://superuser.com/questions/204576/delete-data-from-the-middle-of-a-binary-file-with-hexl-mode

0 0
原创粉丝点击