Skip to content

Instantly share code, notes, and snippets.

@regnerjr
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save regnerjr/9537492 to your computer and use it in GitHub Desktop.
Save regnerjr/9537492 to your computer and use it in GitHub Desktop.
(defun john-convert ()
"Takes Hex dump from Wireshark, looks for the ack offset \"3032\"
Then finds the byte offset requested, and converts that hex to binary"
(interactive)
(beginning-of-line)
(search-forward "3032")
(newline)
(while (not (eolp))
(forward-char 2)(princ " " (current-buffer)))
(beginning-of-line)
(setq byte-offset (read-from-minibuffer "Byte: "))
(forward-word (string-to-number byte-offset))
(princ "\n" (current-buffer))
(forward-word)
(forward-char)
(princ "\n" (current-buffer))
(previous-line)
(beginning-of-line)
(princ (concat ";;byte " byte-offset ": 0x") (current-buffer))
(delete-char 1)
(forward-char)
;; do python processing on (current-word)
(forward-word)
(setq beg (point))
(convert-to-binary)
(kill-region beg (point))
(princ " -> " (current-buffer))
(yank) (backward-delete-char 1)
(backward-char 4) (princ " " (current-buffer)))
(defun convert-to-binary ()
(interactive)
(call-process "python" nil (current-buffer) nil "-c"
(format "print bin(int(%s))[2:].zfill(8)" (current-word))))
@regnerjr
Copy link
Author

called out from elisp to python to do the binary conversion.

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