Wednesday, December 14, 2011

Re: Global change using vim and xxd

On Dec 14, 10:27 am, steve <stevesem...@lycos.com> 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.
>
> I create a file say called template. I put in two strings \WINNT\ hit
> enter few times and then enter \Windows\
>
> I open the template and then go into xxd eg :%!xxd . This gives me ...
>
> 0000000: 5c57 494e 4e54 5c0d 0a0d 0a0d 0a0d 0a0d  \WINNT\.........
> 0000010: 0a0d 0a0d 0a0d 0a0d 0a5c 5769 6e64 6f77  .........\Window
> 0000020: 735c 0d0a 0d0a 0d0a 0d0a 200d 0a         s\........ ..
>
> The reason I have the template file is so that I can cut and paste the
> hex numbers into my global change strings.
>
> Now I open my .cab file that I want to change. Then type :%!xxd
>
> Now I paste the numbers from the template, carfully copying only the
> numbers i want.
>
>  :1,$s/5c57 494e 4e54 5c/5c 5769 6e64 6f77 735c/g
>
> Problem is that this doesn really work. Some strings for example are
> coming out
>
> c:\windows\system3spool\
> others
> C:\Windowssystem32\
>
> I thought that it would ignore the spaces and just change the strings
> but it only changes some of the strings. It is slavishly looking for
> the exact string (sure I guess thats what its suppose to do duuu). But
> how can I get it to be more forgiving.
>
> Im thinking I need to write something like....
>
> 1,$s/5c57 494e 4e54 5c/5c?57?69?6e?64?6f?77?73?5c/g
>
> Although Im not sure. If you know what I mean. Can anyone tell me how
> to resolve this problem. Maybe the search string is not quite righ as
> well.
>

I don't have time to delve into details, but the -p or -ps flag to xxd
puts the hex into a much less rigid format more conducive to edits not
done in replace mode.

See xxd --help or the the man page for xxd for details. A simple
google search for xxd gives several man page hits.

While you're messing with xxd, you might be interested in:

http://vim.wikia.com/wiki/Improved_hex_editing

Although, it currently does not use the -p or -ps flag.

--
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

No comments: