C#解压缩Android备份(adb)文件 [英] C# Decompress an Android Backup (adb) file
问题描述
我正在尝试使用 Deflate 算法解压缩Android adb文件。我已经尝试过DotNetZips Ionic Zlib以及Microsoft内置的 System.IO.Compression ,但是它们两者都导致归档文件损坏。它们都具有完全相同的文件大小,但是散乱的和好的档案之间的哈希值不匹配。
I'm trying to decompress an Android adb file using the Deflate algorithm. I've tried both DotNetZips Ionic Zlib as well as Microsofts built-in System.IO.Compression introduced in Net 4.5 but both of them result in a corrupted archive. They both have the exact same file size, but the hashes don't match up between the corrupt and good archives.
我正在使用以下代码进行解压缩。 / p>
I'm using the following code to decompress.
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将其解压缩,并且可以正确解压缩,所以我知道我的文件不是
I can decompress it via CygWin with OpenSSL and it's decompressing it properly so I know my files aren't corrupted or anything.
cat app_stripped.ab | openssl zlib -d > app.tar
推荐答案
使用离子库
尝试使用此方法解压缩:
try use this method to decompress :
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();
}
}
}
以及您想致电的时间:
and when you want call :
byte[] app = Decompress(File.ReadAllBytes(tb_keyOutDir.Text + "\\app_stripped.ab"));
File.WriteAllBytes(tb_keyOutDir.Text + "\\app.tar", app);
这篇关于C#解压缩Android备份(adb)文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!