【问题标题】:Cannot read that as a ZipFile for .exe file C#无法将其作为 .exe 文件 C# 的 ZipFile 读取
【发布时间】:2012-07-26 09:50:35
【问题描述】:

我正在使用 SevenZIP 库文件解压缩/提取 .exe 文件。当我尝试这个方法时,我收到了一个错误Cannot read that as a ZipFile & zip exception was unhanded。我不想在我的项目中使用任何 7zip.exe 控制台应用程序,我更喜欢在我的项目中使用 .dll 文件。

还有其他方法可以解压.exe文件吗?

  private void MyExtract()
    {
        if(x86)
            ExtractZip(@"D:\22.1.2.702\64\953-win_x86.exe", ".");
        else
            ExtractZip(@"D:\22.1.2.702\64\.702-win_x64.exe", ".");
    }

    private void ExtractZip(string zipFile, string directory)
    {
        using (var zip1 = ZipFile.Read(zipFile))
        {
            // here, we extract every entry, but we could extract conditionally
            // based on entry name, size, date, checkbox status, etc.  
            foreach (var e in zip1)
            {
            e.Extract(directory, ExtractExistingFileAction.OverwriteSilently);
            }
        }
    }

【问题讨论】:

  • 是否有任何 API 调用接受流而不是整个文件?您要么需要解析 .exe 标头以找出最后一部分的结束位置(以及 .zip 的开始位置),要么搜索文件直到找到 .zip magic PK\x03\x04,然后将文件的其余部分传递给 API - 或如果您改用该格式,那么 .7z 的魔力。
  • 令我惊讶的是,当我将我的 exe 文件拖放到 winzip 并手动解压缩时,它可以正常工作。

标签: c# extract unzip


【解决方案1】:

代码示例看起来您使用的是DotNetZip 而不是SevenZipLib。 DotNetZip 只能提取 .zip 文件,不能提取 7-zip 或 .exe

【讨论】:

  • :在这个链接中有一个压缩 exe 文件的例子,但没有解压 fexe 文件。 dotnetzip.codeplex.com/wikipage?title=CS-Examples>
【解决方案2】:

不要使用 SevenZip 库,而是在控制台中尝试 7zip.exe。使用 Process 类执行 7zip.exe。效果很好。

【讨论】:

  • 但他说他不想那样做,不是吗?使用该库将带来其他优势,例如流式传输数据,无需将其写入临时存储。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-17
  • 2019-07-13
  • 2021-10-03
相关资源
最近更新 更多