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

修复Tarfix.pl中的错误,从android adb备份生成tar文件,android,perl,character-encoding,adb,Android,Perl,Character Encoding,Adb,我已经用这个adb备份命令备份了我的android手机 ./adb backup -f /mnt/tvshows/android/backup2.img -shared -nosystem 我现在有一个19GB的图像,但不能用tar打开。许多网站建议使用一个名为tarfix.pl的脚本来修复该文件,但当我运行它时,输出如下所示: [21:40: Downloads$] perl tarfix.pl /mnt/tvshows/android/backup2.img /mnt/tvshows/an

我已经用这个adb备份命令备份了我的android手机

./adb backup -f /mnt/tvshows/android/backup2.img -shared -nosystem
我现在有一个19GB的图像,但不能用tar打开。许多网站建议使用一个名为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.
谁能告诉我怎么修理这个吗?我已将其内联粘贴到下面:

#!/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;
    }
}
#/usr/bin/perl
#=====================================================================================-*-perl-*-
#
#pl:修复android备份在使用
#-共享标志
#
#用法
#塔菲克斯
#
#描述
# 
#“adb备份”是有缺陷的,并且在某些组合中使用“-shared”和
#其他选项它生成一个*未压缩*(尽管
#压缩行正在1)损坏的tar输出。腐败
#发生的情况如下:
#
#   1. 每个文件的512字节头块前面都有一个额外的
#四个字节“00 02 00”。请注意,第3个字节“02”是
#(通常)标头占用的块数的两倍
#
#   2. 数据被分成64个512字节的块组,并使用
#最后一组是填写表格所需的尽可能多的区块
#数据。在每个组之前,以“00”的形式插入4个字节
#xy 00”,其中十六进制对xy等于
#组中有512字节的块。所以,如果组是一个完整的64
#块,然后插入“00 80 00”。同样,如果有
#组中只有Z块,则“xy”等于十六进制中的2*Z。
#
#注意:所有跳过的第三个字节之和等于两倍
#tar文件中的块总数(头+数据)。
#
#注意:该文件以一个以“78 da”开头的17字节字符串结尾
#这恰好是zlib的“adb备份”使用的神奇数字
#放气。当这个17字节的字符串膨胀时,它产生一个
#1024字节的文件,用空值(00)填充。这个17字节的字符串是
#显然是没有意义的,被丢弃了。
#   
#作者
#杰弗里·J·科索斯基
#
#版权所有
#版权所有(C)2012 Jeffrey J.Kosowsky
#
#这个程序是自由软件;您可以重新分发和/或修改它
#它是根据GNU通用公共许可证的条款发布的
自由软件基金会;许可证的第2版,或
#(由您选择)任何更高版本。
#
#这个节目的发布是希望它会有用,
#但无任何保证;甚至没有任何关于
#适销性或适合某一特定目的。见
#有关更多详细信息,请参阅GNU通用公共许可证。
#
#您应该已经收到GNU通用公共许可证的副本
#与此同时,;如果没有,请写信给自由软件
基金会,59庙,套房330,波士顿,MA 02111-1307美国
#
#========================================================================
#
#版本0.1,2012年6月发布
#
#========================================================================
#变更日志
#0.1(2012年6月)-初始版本
#========================================================================
严格使用;
使用警告;
#使用数据::转储程序#只是为了调试。。。
#========================================================================
###I/O设置
我的($输入,$输出);
my$infle=$ARGV[0];
如果(!已定义($infle)|$infle eq'-')){
$in=*STDIN;
}否则{

(open($in,“所以,我也遇到了同样的问题,并找到了提取文件的方法,所以至少这是一个开始

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

为此,我搜索了单词“shared”的第一个实例。这将我带到了这个连接点。就在这之前,您应该看到00 00 02 00十六进制值。您需要在这之前选择拆分文件。直接选择00 00 02 00的左侧,按住Ctrl键并按住Shift键以选择文件的最顶部,然后删除。这将只剩下文件的未加密部分。您可以保存该文件现在你可以在这个文件上运行tarfix.pl行(不需要备份解密脚本),它将提取图像的共享部分。最后你会得到一个错误,但根据我的经验,那里的所有内容都提取正确

接下来,您必须再次进入原始文件,突出显示并删除00 02 00,一直到文件末尾(Ctrl-Shift-end),并将其保存为另一个名称不同的文件(这次留给您的是图像的加密部分)。在此基础上,您现在可以运行backupdecrypt脚本(无需tarfix脚本)。这将生成一个tar文件,您可以使用7-zip进行解压缩

仅供参考,在运行backupdecrypt脚本的最后,以及使用7-zip提取tar文件时,我确实遇到了一些错误,但所有文件似乎都提取得很好

脚本,以及我刚才提供的解释,以及更多详细信息可以在脚本的原始线程中找到:

我确信有一种更干净的方法来避免这些错误,甚至还有一种方法可以把图像重新组合起来,但我只是想继续,用粗糙的方法,这样我们就可以得到一个完整的解决方案