分析原因
利用ICSharpCode.SharpZipLib.Zip进行APK解析时,因为APK内编译的名称为中文,查询微软开发文档936为gb2312中文编码
错误代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| using (ZipInputStream zip = new ZipInputStream(File.OpenRead(path))) { using (var filestream = new FileStream(path, FileMode.Open, FileAccess.Read)) { ZipFile zipfile = new ZipFile(filestream); foreach (ZipEntry entry in zipfile) { if (entry != null) { if (entry.Name.ToLower() == "androidmanifest.xml") { manifestData = new byte[50 * 1024]; Stream strm = zipfile.GetInputStream(entry); strm.Read(manifestData, 0, manifestData.Length); } if (entry.Name.ToLower() == "resources.arsc") { Stream strm = zipfile.GetInputStream(entry); using (BinaryReader s = new BinaryReader(strm)) { resourcesData = s.ReadBytes((int)entry.Size); } } } } } }
|
解决方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| using (ZipInputStream zip = new ZipInputStream(File.OpenRead(path))) { using (var filestream = new FileStream(path, FileMode.Open, FileAccess.Read)) { System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); ZipFile zipfile = new ZipFile(filestream); foreach (ZipEntry entry in zipfile) { if (entry != null) { if (entry.Name.ToLower() == "androidmanifest.xml") { manifestData = new byte[50 * 1024]; Stream strm = zipfile.GetInputStream(entry); strm.Read(manifestData, 0, manifestData.Length); } if (entry.Name.ToLower() == "resources.arsc") { Stream strm = zipfile.GetInputStream(entry); using (BinaryReader s = new BinaryReader(strm)) { resourcesData = s.ReadBytes((int)entry.Size); } } } } } }
|