recover binary file

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

recover binary file

Zbigniew Kowalski

Dear vimmers,

(I hope this one is not too OT)

In order to edit a file binary i did:

1. open with gvim
2. convert to hex (via xxd in menu)
3. edit the hexx
4. convert back to ascii
5. save

and this always worked fine for me, but ...

unfortunately yesterday i forgot to do point no 4, and just saved the
converted file as it was (in hex view). After I realized that I opened
the file again, did convert to ascii but the file turned out to be
corrupted. I tried to experiment on some other file to see what's
being changed in such case. It looks like some extra bytes were
inserted or expanded which resulted in shifting the content, but i
really could not figure out the rule so that i could fix the file
manually.
Any ideas are welcome

regards
Zbikow
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: recover binary file

Matthew Winn-3

On Thu, 13 Mar 2008 01:42:57 -0700 (PDT), Zbikow <[hidden email]>
wrote:

> In order to edit a file binary i did:
>
> 1. open with gvim
> 2. convert to hex (via xxd in menu)
> 3. edit the hexx
> 4. convert back to ascii
> 5. save
>
> and this always worked fine for me, but ...
>
> unfortunately yesterday i forgot to do point no 4, and just saved the
> converted file as it was (in hex view). After I realized that I opened
> the file again, did convert to ascii but the file turned out to be
> corrupted. I tried to experiment on some other file to see what's
> being changed in such case. It looks like some extra bytes were
> inserted or expanded which resulted in shifting the content, but i
> really could not figure out the rule so that i could fix the file
> manually.

I suspect it may be an end-of-line issue.

If you load a binary file it's still treated as a set of lines rather
than a single binary buffer, and any characters that look like line
terminators will be treated as line terminators. If you then resave
the file the line terminators may be written differently depending on
the setting of 'fileformat'.

So what I think may have happened is that when you loaded the binary
file Vim broke the data at what appeared to be line terminators. In
your normal process it remembers the line terminators it identified
and writes out the same ones (so, for example, if it thinks that lines
are terminated with 0x0a then it'll write 0x0a at the end of each line
as the file is written). But if you exit in the middle and then try to
write out the binary file it may be using the wrong line terminators
and putting (say) 0x0d 0x0a where there ought to be a single 0x0a.

There's also the issue of writing a line terminator after the final
line, which may be suppressed in your usual method but not in your
failed attempt.

--
Matthew Winn

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: recover binary file

Benjamin Fritz

On 3/13/08, Matthew Winn <[hidden email]> wrote:

>
>  On Thu, 13 Mar 2008 01:42:57 -0700 (PDT), Zbikow <[hidden email]>
>  wrote:
>
>
>  > In order to edit a file binary i did:
>  >
>  > 1. open with gvim
>  > 2. convert to hex (via xxd in menu)
>  > 3. edit the hexx
>  > 4. convert back to ascii
>  > 5. save
>  >
>  > and this always worked fine for me, but ...
>  >
>  > unfortunately yesterday i forgot to do point no 4, and just saved the
>  > converted file as it was (in hex view). After I realized that I opened
>  > the file again, did convert to ascii but the file turned out to be
>  > corrupted. I tried to experiment on some other file to see what's
>  > being changed in such case. It looks like some extra bytes were
>  > inserted or expanded which resulted in shifting the content, but i
>  > really could not figure out the rule so that i could fix the file
>  > manually.
>
>
> I suspect it may be an end-of-line issue.
>
>  If you load a binary file it's still treated as a set of lines rather
>  than a single binary buffer, and any characters that look like line
>  terminators will be treated as line terminators. If you then resave
>  the file the line terminators may be written differently depending on
>  the setting of 'fileformat'.
>
>  So what I think may have happened is that when you loaded the binary
>  file Vim broke the data at what appeared to be line terminators. In
>  your normal process it remembers the line terminators it identified
>  and writes out the same ones (so, for example, if it thinks that lines
>  are terminated with 0x0a then it'll write 0x0a at the end of each line
>  as the file is written). But if you exit in the middle and then try to
>  write out the binary file it may be using the wrong line terminators
>  and putting (say) 0x0d 0x0a where there ought to be a single 0x0a.
>
>  There's also the issue of writing a line terminator after the final
>  line, which may be suppressed in your usual method but not in your
>  failed attempt.
>
>  --
>
> Matthew Winn

Though it won't help fix your current problem, you may want to
consider this tip to avoid it in the future:

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

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: recover binary file

Zbigniew Kowalski

Unfortunately it is not only line-breaks. As Matthew said it might be
as well case of 'fileformat' or 'encoding'. All in all i had to accept
my loss and had given up. I'll be more carefull next time. Thanks guys
for your help.

best regards
Zbigniew Kowalski
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---