Hacker News new | ask | show | jobs
by boneitis 927 days ago
> In Visual Studio Code, there is an extension called Hex Editor, which lets you view and edit the binary file.

I'll take this opportunity to bring up a method to patch binary data in True Scots^H^H^H^H^HHackerman fashion, using nothing more than vim and xxd, which are already installed everywhere (for some definition of "everywhere").

LiveOverflow describes it between 5:02-7:46 in:

https://www.youtube.com/watch?v=LyNyf3UM9Yc&t=302s

It is the `:%!xxd` and `:%!xxd -r` trick.

(Trying it out again before commenting here, it seems like one might need to `:set nofixeol` beforehand so as not to append any nonexistent newline at the end of file).

My mind is blown by this trick, and I've still never got around to understanding wtf is happening here. (ETA: Upon some thought, I reckon `xxd -r` can just chug along happily by completely ignoring the ascii rendering columns.)

1 comments

This isn't so much a "trick" as it is the main purpose of xxd. xxd is distributed with vim (as in, I'm pretty sure if you want to send a patch to xxd, you send it to the vim repo). One of it's primary purposes is to allow for the editing of binary files in Vim.
I had no idea!