On Wed, Dec 14, 2011 at 11:27:39AM EST, steve wrote: > Im not new to vim, but I realize my huge ignorance when I read that > you can edit binary files with vim via xxd. > > Wow, amazing. However On my first attempt to use it Im kind of > confused and running into some problems. I think probably because I > dont quite understand the nuances of working with binary files. > > I have a file that is a .cab file. It has references to c:\WINNT > \system32\spool everywhere. This is find but I need to change the > WINNT to Windows.
[..] > :1,$s/5c57 494e 4e54 5c/5c 5769 6e64 6f77 735c/g > > Problem is that this doesn really work. [..] I don't know what .cab files are, but just a couple remarks: 1. when editing a ‘binary’ file, it's usually not a good idea to replace a string with another string of a different length. The reason is that the file is not meant to be read by human eyes, but rather by a program and may therefore have some ‘hidden’ structure. As such, replacing 5 bytes by 7 bytes as in this example can wreak havoc with the contents of the file and make it unusable. Can't say if this applies here but since .cab files appear to be some sort of Microsoft compressed format, I would not be too optimistic about being able to use them after editing them as you intend. Maybe there is a tool that allows you to .cab files them in order to make your changes? 2. I am more familiar with the ‘bvi’ program¹, which was written specifically to ‘edit’ binary files, so I am not sure of the implications, but as far as I can tell, since you are replacing a text string by another, you could just as well code and do away with your ‘template’ file: :1,$s/WINNT/Windows/g Naturally, Vim would adjust the hex values of the relevant bytes automatically, (so-to-speak). HTH, CJ ¹ Only available on *nix, Cygwin... etc. -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php
