Create a gist now

Instantly share code, notes, and snippets.

@kosh04 /xd.lsp
Created May 30, 2010

What would you like to do?
xd.lsp - 16進ダンプツール (hexdump -C風味)
#!/usr/bin/newlisp
;; Hex dump tool
;; Usage: newlisp xd.lsp < FILENAME
(constant 'stdin 0)
(define-macro (loop)
(let ((return throw))
(catch (while true
(map eval (args))))))
(setq offset 0)
(loop
(or (read stdin s 16) (return 'eof))
;; ADDRESS
(print (format "%08X " offset))
;; HEXDUMP
(print (format (dup "%02X " (length s))
(unpack (dup "b" (length s)) s))
(dup " " (- 16 (length s))))
;; CHARACTER
(print " |" (replace "[^[:print:]]" s "." 0) "|\n")
(++ offset (length s)))
(exit)
@kosh04

This comment has been minimized.

Show comment Hide comment
@kosh04

kosh04 Jul 28, 2010

read関数が指定したバイト数より小さい場合でも入力を受けつけるのがちょっと気になる…。

Owner

kosh04 commented Jul 28, 2010

read関数が指定したバイト数より小さい場合でも入力を受けつけるのがちょっと気になる…。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment