ICSharpCode.SharpZipLib.Zip 解析时报错System.NotSupportedException: No data is available for encoding 936

简介: ​分析原因利用ICSharpCode.SharpZipLib.Zip进行APK解析时,因为APK内编译的名称为中文,查询微软开发文档936为gb2312中文编码[微软开发文档地址](https://docs.microsoft.com/zh-cn/windows/win32/intl/code-page-identifiers "微软开发文档地址")```csharp// 错误代码using (ZipInputStream zip = new ZipInputStream(File.OpenRead(path))) { using (var filestream = new


分析原因
利用ICSharpCode.SharpZipLib.Zip进行APK解析时,因为APK内编译的名称为中文,查询微软开发文档936为gb2312中文编码
请在此添加图片描述

微软开发文档地址

// 错误代码
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);
                    }
                }
            }
        }
    }
}
// 解决方法
using (ZipInputStream zip = new ZipInputStream(File.OpenRead(path))) 
{
   
   
    using (var filestream = new FileStream(path, FileMode.Open, FileAccess.Read)) 
    {
   
   
        // 在.Net Core中默认System.Text中不支持CodePagesEncodingProvider.Instance
        // 添加下方这行代码允许访问.Net Framework平台上不支持的编码提供程序
     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);
                    }
                }
            }
        }
    }
}

以上就是ICSharpCode.SharpZipLib.Zip 解析时报错System.NotSupportedException: No data is availa的介绍,做此记录,如有帮助,欢迎点赞关注收藏!

目录
相关文章
|
21天前
zip,with-core-zip,selfcontained这些都是什么意思?
zip,with-core-zip,selfcontained这些都是什么意思?
|
21天前
|
存储 XML JSON
Unity 数据读取|(三)ini文件解析(INIParser,StreamReader,System.Runtime.InteropServices)
Unity 数据读取|(三)ini文件解析(INIParser,StreamReader,System.Runtime.InteropServices)
|
8月前
|
C#
利用ICSharpCode.SharpZipLib.dll解析 出错:“Wrong Local header signature: 0xFF8”
## 分析原因 利用ICSharpCode.SharpZipLib.dll解析APK时,进入APK的AndroidXml获取时出现报错 ## 出错代码 ```csharp using (ICSharpCode.SharpZipLib.Zip.ZipInputStream zip = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(path))) { using (var filestream = new FileStream(path, FileMode.Open, FileAccess.Read)) {
78 1
jogbuild-common.xml:17: Cannot find /home/tsit/tio-software/jogamp/gluegen/make/gluegen-cpptasks.xml
jogbuild-common.xml:17: Cannot find /home/tsit/tio-software/jogamp/gluegen/make/gluegen-cpptasks.xml
50 0
|
测试技术 Python
Python常见问题 - 使用openpyxl模块时出现错误: zipfile.BadZipFile: File is not a zip file
Python常见问题 - 使用openpyxl模块时出现错误: zipfile.BadZipFile: File is not a zip file
1587 0
Python常见问题 - 使用openpyxl模块时出现错误: zipfile.BadZipFile: File is not a zip file
|
测试技术 机器人
Robot Framework之读取后缀名为.xls文件,并保存为list
一、首先读文件需要ExcelLibrary包支持 1.安装ExcelLibrary 可以直接通过命令安装:pip install robotframework-ExcelLibrary robotframework-ExcelLibrary 2.
1921 0
|
XML Java Android开发
快速生成Plugman中的"lib-file"、"source-file"的xml内容
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.
775 0

热门文章

最新文章