help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fix the destroyed disk image partition table in a raw image file usi


From: Hongyi Zhao
Subject: Re: Fix the destroyed disk image partition table in a raw image file using Emacs.
Date: Thu, 15 Apr 2021 22:16:22 +0800

On Mon, Apr 12, 2021 at 3:18 AM Gregor Zattler <telegraph@gmx.net> wrote:
>
> Hi Hongyi Zhao,
> * Hongyi Zhao <hongyi.zhao@gmail.com> [2021-04-11; 21:34]:
> > $ dd if=disk.img bs=1 count=4 skip=440 2>/dev/null | od -t x4 -An
> > 761b36b0
> >
> > It's well known that Emacs is an 8-bit clean editor which makes it
> > safe to edit binary files. So, I want to whether I can fix the above
> > destroyed disk image file with Emacs for my scenario.
>
> If your emacs is able to handle the disk image in memory
> (which probably means you need a 64bit emacs and enough RAM
> installed) you could open the file of the disk image with
>
> find-file-literally
>
>    Visit file FILENAME with no conversion of any kind.
>
>    Format conversion and character code conversion are both
>    disabled, and multibyte characters are disabled in the
>    resulting buffer.  The major mode used is Fundamental
>    mode regardless of the file name, and local variable
>    specifications in the file are ignored.  Automatic
>    uncompression and adding a newline at the end of the file
>    due to require-final-newline is also disabled.
>
> And then the first thing to do would be
>
> binary-overwrite-mode
>
>    When Binary Overwrite mode is enabled, printing
>    characters typed in replace existing text.  Newlines are
>    not treated specially, so typing at the end of a line
>    joins the line to the next, with the typed character
>    between them.  Typing before a tab character simply
>    replaces the tab with the character typed.  C-q replaces
>    the text at the cursor, just as ordinary typing
>    characters do.
>
>
> You then can move point in the disk image to the desired
> place and type in whatever you want and later save the
> buffer to its file.
>
>
> Ciao; Gregor
> --
>  -... --- .-. . -.. ..--.. ...-.-

If the 'conv=notrunc' option of 'dd' is used, the following is a pure
*nix tools based restore method given on comp.unix.shell newsgroup by
Helmut Waitzmann. For the more detailed discussion, see
<https://groups.google.com/g/comp.unix.shell/c/-4jQ-6tkOgs/m/FZl_96n-AQAJ>:

<quote>
[The 'conv=notrunc' option of 'dd']

>Assuming I have used this option, what exact restore command should
>I use?


First you should check, that the command


{
printf '%s\n' 'ibase=16' &&
printf '%s\n' b0 36 1b 76 |
LC_ALL=POSIX tr -- '[:lower:]' '[:upper:]'
} | bc | xargs -E '' -- printf \''\\%.4o'\''\n' |
xargs -E '' -- printf '%b' |
od -v -A n -t x4

yields the output '761b36b0'.  If that's the case, you could have
done

{
printf '%s\n' 'ibase=16' &&
printf '%s\n' b0 36 1b 76 |
LC_ALL=POSIX tr -- '[:lower:]' '[:upper:]'
} | bc | xargs -E '' -- printf \''\\%.4o'\''\n' |
xargs -E '' -- printf '%b' |
dd of=disk.img bs=1 seek=440 conv=notrunc

to restore the original partuuid.
</quote>

To be frank, the internal logic of the above code is still unclear to
me. I post it here for your reference.

Regards
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Polytechnic University of Science and Technology engineering
NO. 552 North Gangtie Road, Xingtai, China



reply via email to

[Prev in Thread] Current Thread [Next in Thread]