Modify binary files with VIM

Modify binary files with VIM

TL;DR xxd ./bin/app | vim — and :%!xxd -r > ./bin/new_app

Photo by Markus Spiske on Unsplash

When I was a student, I used a lot Windows. It was hard times and we had to crack tools like Total Commander or FAR manager or upgrade Diablo’s heroes in saves files. I used editors like: WinHex and UltraEdit .

Today I came to similar problem modify binary file in Linux terminal. I started search with one requirements:

  1. it should be cross distributive solution

  2. should be easy to use with Vim (as main my editor for linux machines)

Few searches and I came to: xxd. It is a part of vim-common package, that lucky would be installed on each system. I need to learn only how to read, modify and write.

Read: Use xxd to decode binary and redirect output to vim: xxd ./bin/app | vim -

Modification: You can edit evrything - because it is just a text. There are 3 big sections. First column is the addresses, second is the hex representation of a binary file, and third one is the ASCII preview of the binary. With this solution preview would not be updated on changes.

Write: After you modify required bytes in the middle section. Instead of type :w , you should run xdd: :%!xdd -r > ./bin/new_app .

Summary

Youtube

That’s all Folks

Michael Nikitochkin is a Lead Software Engineer. Follow him on LinkedIn or GitHub.

If you enjoyed this story, we recommend reading our latest tech stories and trending tech stories.