Emacs: Binary File Viewer
Quick visualization tool for Binary data using C header definition.
- Semantic parses the C header file and generates a type definition.
- The type definition is passed to bindat-unpack along with the binary data.
- The result is displayed using speedbar.
;; Note: The command works on the binary data in the current buffer.
M-x hexl-form
(hexl-form)
The image shows the example included in the commentary section of bindat.el.
Conversions
(format "%02X" 255) ;; => "FF"
(string-to-number "FF" 16) ;; => 255
(string-to-number "FF" 16) ;; => 255
;; Little endian unpacking
(let* ((bindat-raw [1 2 3 4 5 6 7 8])
(bindat-idx 0))
(bindat--unpack-u64r))
(bindat-idx 0))
(bindat--unpack-u64r))
;; Little endian packing
(let* ((bindat-raw [0 0 0 0 0 0 0 0])
(bindat-idx 0))
(bindat--pack-u64r #x0102030405060708)
bindat-raw)
(bindat-idx 0))
(bindat--pack-u64r #x0102030405060708)
bindat-raw)
Insert Binary Data
Emacs creates a multibyte buffer by default. While working with binary file (not in hexl-mode), this must be disabled.
(set-buffer-multibyte nil)
(insert 192) ; c0
(insert 192) ; c0
(setq binary-data
[ 192 168 1 100 192 168 1 101 01 28 21 32 2 0 0 0
2 3 0 5 ?A ?B ?C ?D ?E ?F 0 0 1 2 3 4 5 0 0 0
1 4 0 7 ?B ?C ?D ?E ?F ?G 0 0 6 7 8 9 10 11 12 0 ])
(mapc 'insert binary-data)
Code: https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/hexl.el
Usage
Disk Partition Table
References
- Sanitize vector unpacking
- Little Endian bindat-type usage documentation
- Disk partition definitions
- Binary patching (xxd)
- Binary File I/O (dd)
Comments
Post a Comment