So what i am trying to achieve is the auto-editing of hex files. For example - The user enters a hex address, and the hex value to replace at that address. This change is to be applied to 10 different binary files

Can anyone point me in the direction of auto-editing files(emacs auto opens the file, switches to hexl mode, jumps to address provided by user, inserts hex code at that address which is also provided by the user and saves file then finally exits) So far i have only been able to achieve auto opening to hexl mode by launching it like

emacs file -f hexl-mode -f hexl-goto-hex-address

From here on i have no idea how to input the hex address and then move onto changing the code

  • 2
    Does it have to be inside Emacs? This seems like it would be simpler to do in some sort of script run from your terminal.
    – zck
    Aug 8, 2018 at 17:54
  • Yes actually, i am using AppleScript to send keystrokes. But it would be better if there was a way to do it through Emacs. I am trying to develop this Tool for Mac as well as Windows, but i dont know an equivalent for AppleScript on Windows
    – TheArmKing
    Aug 8, 2018 at 18:07
  • You can do "auto editing" by writing an Emacs function in elisp. Start C-h i and select "Emacs Lisp Intro" for an introduction and "elisp" for a reference manual. The function need to visit a the, perform the edit, and save the file. By the way, you don't have to use hexl, you can simply open the file and write an elisp function that replaces the characters you want replaced. Aug 8, 2018 at 19:13
  • 1
    @TheArmKing I was thinking of writing, for example, a Python script to do this. I don't know if Emacs is the right tool. Why did you want to use Emacs specifically?
    – zck
    Aug 8, 2018 at 19:34
  • @Lindydancer i will check it out, Thanks!
    – TheArmKing
    Aug 9, 2018 at 8:09

1 Answer 1


The following call to emacs inserts the hexadecimal number \x0b at character position 10 of the files 1st.bin and 2nd.bin.

emacs --batch --eval '(dolist (file-name (list "1st.bin" "2nd.bin")) (find-file-literally file-name) (goto-char 10) (insert "\x0b") (save-buffer 0) (kill-buffer))'
  • Answers the question well but not convinent for me, thus my proposal of using applescript and hexcurse instead.
    – TheArmKing
    Aug 16, 2018 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.