| git.druid.rocks | index | druid520 | radium | radium-binary.el |
radium-binary.el
;;; radium-binary.el, hex editing + radare2 + objdump -*- lexical-binding: t; -*-
;;
;; item 16: "hex editor" is emacs's own built-in hexl-mode, not a
;; third-party package - nothing to add there beyond wiring it up for
;; the extensions that are always real binary (.bin/.o - never .elf,
;; on purpose: kaboom's own .nsc/.nsh already claim real, non-binary
;; meaning for plenty of extensions in this same tree, and an .elf's
;; real content is exactly what C-c x d (below) already shows in a
;; genuinely more useful form than a raw hex dump would) plus C-c x h
;; to toggle it by hand on anything else. radare2 gets a real comint
;; repl, same shape as kona's own (radium-lang-kona.el) - r2 already
;; has a rich interactive command set of its own, there's nothing to
;; wrap beyond starting it against the right file. the "objdump-like
;; thing" is a real objdump -d -M att (AT&T syntax, matching this
;; config's own asm convention - radium-lang-asm.el) run and shown in
;; a real asm-mode buffer for the highlighting, not a raw shell
;; command output.
;;
;; item 22 (capstone/keystone/unicorn): checked directly before
;; writing anything here, not assumed - none of the three ship a
;; standalone cli tool at all (installed all three fresh in this same
;; sandbox specifically to check: no cstool-like binary appears on
;; $PATH for any of them), they're consumed by writing real python
;; that imports them as a library. radium-lang-python.el is the real
;; prerequisite this actually needed (this config had no python
;; support at all before it) - there's no further "integration" a
;; capstone/keystone/unicorn script needs beyond a working python-mode
;; to write it in, so nothing more lives here.
(require 'hexl)
(require 'comint)
(add-to-list 'auto-mode-alist '("\\.\\(bin\\|o\\)\\'" . hexl-mode))
(defun radium-hexl-toggle ()
"C-c x h: toggle hexl-mode on this buffer."
(interactive)
(if (eq major-mode 'hexl-mode)
(hexl-mode-exit)
(hexl-mode)))
(defun radium-run-r2 (file)
"C-c x r: radare2 on FILE (default: this buffer's own file), in a
real comint repl - r2's own command set (aa, pdf, V, ...) is already
rich, nothing to wrap."
(interactive (list (or buffer-file-name (read-file-name "r2 file: "))))
(let ((buf (get-buffer-create (format "*r2:%s*" (file-name-nondirectory file)))))
(unless (comint-check-proc buf)
(with-current-buffer buf
(apply #'make-comint-in-buffer "r2" buf "r2" nil (list (expand-file-name file)))
(comint-mode)))
(pop-to-buffer buf)))
(defun radium-objdump (file)
"C-c x d: objdump -d -M att on FILE (default: this buffer's own
file), AT&T syntax matching this config's own asm convention, shown
in a real asm-mode buffer (view-mode, q to close)."
(interactive (list (or buffer-file-name (read-file-name "objdump file: "))))
(let ((buf (get-buffer-create (format "*objdump:%s*" (file-name-nondirectory file)))))
(with-current-buffer buf
(let ((inhibit-read-only t))
(erase-buffer)
(unless (zerop (call-process "objdump" nil buf nil "-d" "-M" "att" (expand-file-name file)))
(error "radium-objdump: objdump failed, see %s" (buffer-name)))
(asm-mode)
(goto-char (point-min))
(view-mode 1)))
(pop-to-buffer buf)))
(global-set-key (kbd "C-c x h") #'radium-hexl-toggle)
(global-set-key (kbd "C-c x r") #'radium-run-r2)
(global-set-key (kbd "C-c x d") #'radium-objdump)
(provide 'radium-binary)