修复Tarfix.pl中的错误,从android adb备份制作tar文件

时间:2014-08-26 21:07:12

标签: android perl character-encoding adb

我已使用此adb备份命令备份了我的Android手机

./adb backup -f /mnt/tvshows/android/backup2.img -shared -nosystem

我现在拥有19GB的图像,但它不会用焦油打开。许多网站建议使用一个名为tarfix.pl的脚本来修复文件,但是当我运行它时,输出看起来像这样:

[21:40: Downloads$] perl tarfix.pl /mnt/tvshows/android/backup2.img /mnt/tvshows/android/backup.
Wide character in oct at tarfix.pl line 107.
Illegal binary digit '�������������' ignored at tarfix.pl line 107.
Illegal octal digit '9' ignored at tarfix.pl line 107.
Illegal octal digit '9' ignored at tarfix.pl line 107.
Illegal octal digit '9' ignored at tarfix.pl line 107.
Wide character in oct at tarfix.pl line 107.
Illegal hexadecimal digit '�������������' ignored at tarfix.pl line 107.
Wide character in oct at tarfix.pl line 107.
Illegal hexadecimal digit '�������������' ignored at tarfix.pl line 107.
Illegal octal digit '9' ignored at tarfix.pl line 107.
Wide character in oct at tarfix.pl line 107.
Illegal binary digit '�������������' ignored at tarfix.pl line 107.
Illegal binary digit '\' ignored at tarfix.pl line 107.
Illegal binary digit 'p' ignored at tarfix.pl line 107.
Wide character in oct at tarfix.pl line 107.
Illegal hexadecimal digit '�������������' ignored at tarfix.pl line 107.
Illegal octal digit '_' ignored at tarfix.pl line 107.
Illegal octal digit '9' ignored at tarfix.pl line 107.
Illegal hexadecimal digit 'Q' ignored at tarfix.pl line 107.
Illegal hexadecimal digit ' ignored at tarfix.pl line 107.
Illegal octal digit '8' ignored at tarfix.pl line 107.
Illegal hexadecimal digit 'v' ignored at tarfix.pl line 107.
Wide character in oct at tarfix.pl line 107.
Illegal hexadecimal digit '�������������' ignored at tarfix.pl line 107.
Illegal binary digit '' ignored at tarfix.pl line 107.
Wide character in oct at tarfix.pl line 107.
Illegal hexadecimal digit '�������������' ignored at tarfix.pl line 107.
Illegal octal digit '9' ignored at tarfix.pl line 107.
Illegal octal digit '9' ignored at tarfix.pl line 107.
Illegal octal digit '9' ignored at tarfix.pl line 107.
Illegal octal digit '9' ignored at tarfix.pl line 107.
Wide character in oct at tarfix.pl line 107.
Illegal binary digit '�������������' ignored at tarfix.pl line 107.
Illegal hexadecimal digit 'Q' ignored at tarfix.pl line 107.
Illegal binary digit 'h' ignored at tarfix.pl line 107.
Wide character in oct at tarfix.pl line 107.
Illegal hexadecimal digit '�������������' ignored at tarfix.pl line 107.
Illegal hexadecimal digit '&' ignored at tarfix.pl line 107.
Wide character in oct at tarfix.pl line 107.
Illegal hexadecimal digit '�������������' ignored at tarfix.pl line 107.
Illegal binary digit ' ignored at tarfix.pl line 107.
Illegal octal digit '9' ignored at tarfix.pl line 107.

有人可以告诉我如何解决这个问题吗? The script and details behind it is here我已将其粘贴在下方:

#!/usr/bin/perl
#============================================================= -*-perl-*-
#
# tarfix.pl: Fix broken tar files produced by android backup when using
#            -shared flag
#
# USAGE
#   tarfix [<input file>|-] [<output file>|-]
#
# DESCRIPTION
# 
#  'adb backup' is buggy and for some combinations of '-shared' with
#   other options it produces an *uncompressed* (despite the
#   compression line being 1) corrupted tar output. The corruption
#   occurs as follows:
#
#   1. The 512-byte header block for each file is preceded by an extra
#      four bytes "00 00 02 00". Note that the 3rd byte '02' is
#      (trivially) twice the number of blocks taken up by the header
#
#   2. The data is divided into groups of 64 512-byte blocks with the
#      final group being as many blocks as needed to fill out the
#      data.  Before each group, 4 bytes are inserted of form "00 00
#      xy 00" where the hex pair xy is equal to twice the number of
#      512-byte blocks in the group. So, if the group is a full 64
#      blocks, then "00 00 80 00" is inserted. Similarly, if there
#      only Z blocks in the group then 'xy' is equal to 2*z in hex.
#
#   Note: Summing the third bytes of all the skips equals two times
#   the total number of blocks in the tar file (headers + data).
#
#   Note: The file ends with a 17-byte string starting with '78 da'
#   which happens to be the magic number used by 'adb backup' for zlib
#   deflate.  When this 17-byte string is inflated, it yields a
#   1024-byte file filled with nulls (00). This 17-byte string is
#   obviously meaningless and is discarded.
#   
# AUTHOR
#   Jeffrey J. Kosowsky
#
# COPYRIGHT
#   Copyright (C) 2012 Jeffrey J. Kosowsky
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#========================================================================
#
# Version 0.1, released June 2012
#
#========================================================================
# CHANGELOG
#     0.1 (June 2012)  - Initial version
#========================================================================

use strict;
use warnings;
#use Data::Dumper; #Just for debugging...

#========================================================================
### I/O Setup
my ($in, $out);

my $infile = $ARGV[0];
if(! defined($infile) || $infile eq '-') {
    $in = *STDIN;
}else {
    (open($in, "<:raw", $infile) or
     die "Error: Can't open input file: $infile\n");
}

my $outfile = $ARGV[1];
if(! defined($outfile) || $outfile eq '-') {
    $out = *STDOUT;
}else {
    (open($out, ">:raw", $outfile) or 
     die "Error: Can't open output file: $outfile\n");
}

binmode $in;
binmode $out;

#========================================================================
#Skip four bytes "00 00 02 00" before reading each new 512-byte header.
#In a sense, this corresponds to two times the number of header blocks.
while(seek($in, 4, 1) && (my $bytes=read($in, my $header, 512))) {
    if($bytes == 17 && unpack('H4', $header) eq '78da') {
        last; #17-byte (nonsense) trailer at end of backup file
    }elsif($bytes < 512) {
        die "Error: Unknown data at end of tar file...\n";
    }

    #Note: number of data bytes in the file is an 11 digit octal
    #string starting at position 124 in the header. The data is
    #divided into 512-byte blocks.
    my $blocks = int((oct(substr($header, 124, 11)) + 511)/512);

    print $out $header; #Print header

    for(my $i=1; $i <= $blocks; $i++) { #Print data
        seek($in, 4, 1) unless ($i-1)%64; 
        #Skip 4 bytes at the beginning of every group of 64 blocks of
        #data.  Note we are skipping 00 00 xy 00 00 where xy is equal
        #to two times the number of blocks following before either the
        #next group of 64 blocks (i.e. 80 = 128 or 2 times 64 blocks)
        #or the end of the data section. 
        #Hence the sum of all the 3rd bytes for all the skips is equal
        #to twice the total number of blocks.

        read($in, my $data, 512) or
            die "Error: Can't read next block of data...\n";
        print $out $data;
    }
}

1 个答案:

答案 0 :(得分:0)

所以,我遇到了同样的问题并想出了如何提取文件,所以至少它是一个开始。

我使用免费软件十六进制编辑器HxD来修改/拆分原始图像文件。根据我对adb如何制作图像的理解,它看起来像是备份了#34;共享&#34;持续。错误是这部分没有加密。所以,你在这里必须要做的是在十六进制编辑器中找到加密部分结束的原始图像文件中的点,以及&#34;纯文本&#34;未加密(共享)部分开始。

为此,我搜索了第一个单词&#34; shared&#34;。这使我正确到了这个交界处。在此之前,您应该看到00 00 02 00十六进制值。您需要将选择之前的文件拆分为此文件。直接选择00 00 02 00的左侧,Ctrl-Shift-Home选择文件的最顶部,然后删除。这将使您只使用文件的未加密部分。您将其另存为不同命名的文件。现在,您可以在此文件上运行tarfix.pl行(不需要backupdecrypt脚本),这将提取图像的共享部分。你最后会收到一个错误,但我的经验是所有的东西都被正确地提取出来了。

接下来,您必须再次进入原始文件并突出显示并删除00 00 02 00 down 到文件末尾(Ctrl-Shift-End),然后保存这是一个不同命名的文件(这次使用图像的加密部分。)在此,您现在可以运行backupdecrypt脚本(不需要tarfix脚本)。这将生成一个tar文件,您可以使用7-zip提取。

仅供参考,我在运行backupdecrypt脚本结束时以及使用7-zip解压缩tar文件时遇到了一些错误,但所有文件似乎都提取得很好。

脚本以及我刚刚提供的解释,以及更多细节可以在脚本中找到&#39;原创主题:http://forum.xda-developers.com/showthread.php?t=1730309

我确定有更清洁的方法来完成所有这些以避免错误等等,甚至是将图像重新组合在一起的方法,但我只想继续前进并获得粗糙的方法,以便我们可以在一个完整的解决方案上滚动。