From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Hongyi Zhao Newsgroups: gmane.emacs.help 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 Message-ID: References: <87tuocfx5g.fsf@no.workgroup> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10648"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Apr 15 16:17:23 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lX2o7-0002eT-BO for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 15 Apr 2021 16:17:23 +0200 Original-Received: from localhost ([::1]:41830 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lX2o6-000087-EF for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 15 Apr 2021 10:17:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59912) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lX2nS-00007x-0q for help-gnu-emacs@gnu.org; Thu, 15 Apr 2021 10:16:42 -0400 Original-Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]:46661) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lX2nO-0004HG-In for help-gnu-emacs@gnu.org; Thu, 15 Apr 2021 10:16:41 -0400 Original-Received: by mail-lf1-x134.google.com with SMTP id 12so39317214lfq.13 for ; Thu, 15 Apr 2021 07:16:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=wxiS1ncqTkDIGeidwuRj8H+VLltd+R1MZRlbI/TDc9c=; b=AsLG3vpA/VKS4T0qBCYy4zoK4SQlUsrSJ4768OODfbCZKqnEgD7Hg1zbf2HQTHEE8E SZ8HI5LSrDVRFx2Wu9fLfF/O/+onI/o5T5zHo0/LdpJD51pGbpQ5RbapP8HStjXTly7b 1Gv3qNKmI2/7s+ar163VJvfZgfKvK2WjFqas8lWfIZUlVossh9nb1bnG6SntUR1UpjRZ RYsxTOsaFZIAzGTfGWz/L/MZ9tx8jOVY7UOtTiXbvtTuz9BdCuEQD/47bv4ENqZwzzcX DDjBwBJ6TV0Bax7WYLOL4DbfG07RG8ARKHVynTcNhcAZ8lSmD29RZxFLICg2Sd2EFK8V m1Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=wxiS1ncqTkDIGeidwuRj8H+VLltd+R1MZRlbI/TDc9c=; b=XPP/g5BM/K0Ks5TSUcQt6shJJQmwEfDPY0c169gyfa7rMFo+j2yOLZ25t/1zEXi4eS L6XryJ0chrHIG3m8V963CE7b6qkSKIQ0kkS4OiCUgJ7fc5kHqSOONakuNrBMrkbL3BPE HfC5dyZiMbIjcpwBPAIMyCNujOs/LZwQssg8HlmJusHvvNebWiqPPmlKkX8gXGJywOiT gUp3UOh5Y0RlZqDctyOjz+E4IEI01CtEgx6RIuD3CzE1iGR+8n1BJQUYvZqYaXItEsOH /Ni8Pwk/C9W2YS/N/Yg3qLmj+gW4wQx0/9CjNPJjB/+pQcRw0t5Y93F5+hQTQAerXv/k zjlg== X-Gm-Message-State: AOAM532RAEloJt0j3FOg15F4OcQ8sAvyGD4YHN0vZv4oBwP1p0iRQz95 KpdMeHkKFb4RgkJQ2YPEclIa6UzT8ZkQ5xCJNYIxaIYbDrz5ytlz X-Google-Smtp-Source: ABdhPJynmXwGCdw2krx1GplXMkrJ0UpBCAhwX335Y3/Lm86gP3h1DNmuoK09v6jMKiSwMFTF/gH05gr/SLKKAA6KVB0= X-Received: by 2002:a05:6512:31d3:: with SMTP id j19mr2825710lfe.231.1618496193872; Thu, 15 Apr 2021 07:16:33 -0700 (PDT) In-Reply-To: <87tuocfx5g.fsf@no.workgroup> Received-SPF: pass client-ip=2a00:1450:4864:20::134; envelope-from=hongyi.zhao@gmail.com; helo=mail-lf1-x134.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:129003 Archived-At: On Mon, Apr 12, 2021 at 3:18 AM Gregor Zattler wrote: > > Hi Hongyi Zhao, > * Hongyi Zhao [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 : [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. 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 Theory and Simulation of Materials Hebei Polytechnic University of Science and Technology engineering NO. 552 North Gangtie Road, Xingtai, China