Last active
August 29, 2015 13:57
-
-
Save regnerjr/9537492 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
called out from elisp to python to do the binary conversion.