July 25, 2011

Editing hex file via Vim

It took me some time to find useful tools comparing hex file in mac. I had tried DiffMerge, kdiff3, HexEditor, and several other apps whose names I could not recall. At last, the most viable way is still using the vim editor. But the problem was still there: it was painful to look at hex code in that editor.

Solution:
Adding some configuration in the ~/.vimrc will make everything peace and clean:)


" vim -b : edit binary using xxd-format!
augroup Binary
au!
au BufReadPre *.bin let &bin=1
au BufReadPost *.bin if &bin | %!xxd
au BufReadPost *.bin set ft=xxd | endif
au BufWritePre *.bin if &bin | %!xxd -r
au BufWritePre *.bin endif
au BufWritePost *.bin if &bin | %!xxd
au BufWritePost *.bin set nomod | endif
augroup END


Note that this configuration only works with the file with .bin extension, which is already enough for me to hack into the targeting files:) Check the reference #1 for further reading of more general hex file editing.

cheers:)

References:
1) Improve hex editing
2) Vim commands cheat sheet

No comments:

Post a Comment

Days of our lives

Daisypath Anniversary tickers