Emacs: Binary File Viewer

 

Quick visualization tool for Binary data using C header definition.

  1. Semantic parses the C header file and generates a type definition.
  2. The type definition is passed to bindat-unpack along with the binary data.
  3. 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
 
;; Little endian unpacking
(let* ((bindat-raw [1 2 3 4 5 6 7 8])
          (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)
  

 

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

(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

  1. Sanitize vector unpacking
  2. Little Endian bindat-type usage documentation
  3. Disk partition definitions
  4. Binary patching (xxd)
  5. Binary File I/O (dd)  
     

 

Comments

Popular posts from this blog

HTML Renderer (Emacs)

Emacs: A non-intrusive browser

Text along a path (GNU Emacs)