【问题标题】:C# Decompress an Android Backup (adb) fileC# 解压 Android 备份 (adb) 文件
【发布时间】:2014-10-12 11:58:01
【问题描述】:

我正在尝试使用 Deflate 算法解压缩 Android adb 文件。我已经尝试过 DotNetZips Ionic Zlib 以及 Net 4.5 中引入的 Microsoft 内置 System.IO.Compression,但它们都导致存档损坏。它们都具有完全相同的文件大小,但损坏的存档和正常存档之间的哈希值不匹配。

我用下面的代码解压。

byte[] app = File.ReadAllBytes(tb_keyOutDir.Text + "\\app_stripped.ab");
MemoryStream ms = new MemoryStream(app);

//skip first two bytes to avoid invalid block length error
ms.Seek(2, SeekOrigin.Begin);

DeflateStream deflate = new DeflateStream(ms, CompressionMode.Decompress);
string dec = new StreamReader(deflate, Encoding.ASCII).ReadToEnd();

File.WriteAllText(tb_keyOutDir.Text + "\\app.tar", dec);

我可以通过 CygWin 和 OpenSSL 解压它,它可以正确解压它,所以我知道我的文件没有损坏或任何东西。

cat app_stripped.ab | openssl zlib -d > app.tar

【问题讨论】:

    标签: c# android adb archive zlib


    【解决方案1】:

    使用离子库

    试试用这个方法解压:

        public static byte[] Decompress(byte[] gzip) {
            using (var stream = new Ionic.Zlib.ZlibStream(new MemoryStream(gzip), Ionic.Zlib.CompressionMode.Decompress)) {
                const int size = 1024;
                byte[] buffer = new byte[size];
                using (MemoryStream memory = new MemoryStream()) {
                    int count = 0;
                    do {
                        count = stream.Read(buffer, 0, size);
                        if (count > 0) {
                            memory.Write(buffer, 0, count);
                        }
                    }
                    while (count > 0);
                    return memory.ToArray();
                }
            }
        }
    

    当你想打电话时:

        byte[] app = Decompress(File.ReadAllBytes(tb_keyOutDir.Text + "\\app_stripped.ab"));
        File.WriteAllBytes(tb_keyOutDir.Text + "\\app.tar", app);
    

    【讨论】:

    • 谢谢你,成功了!我已经稍微编辑了你的答案,因为我们现在写的是字节而不是文本。
    猜你喜欢
    • 2017-03-05
    • 2012-03-17
    • 1970-01-01
    • 2013-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-30
    • 1970-01-01
    相关资源
    最近更新 更多