【问题标题】:The magic number in GZip header is not correct. Make sure you are passing in a GZip stream.(.exe file)GZip 标头中的幻数不正确。确保您传入的是 GZip 流。(.exe 文件)
【发布时间】:2012-10-29 23:55:54
【问题描述】:

我想提取一个 exe 文件。 exe 文件包含一些文件和文件夹。当我尝试使用 winrar 提取文件时,它会被提取,但是当我尝试使用一些示例提取 exe 文件时,我收到此错误:

GZip 标头中的幻数不正确。确保您传递的是 GZip 流。

我使用了一些示例并在 Google 上搜索了很多问题,但没有得到我的答案,而且我还使用了一些库。

我使用了这段代码,但同样的错误:

    public static void Decompress(FileInfo fi)
    {
        // Get the stream of the source file.
        using (FileStream inFile = fi.OpenRead())
        {
            // Get original file extension, for example
            // "doc" from report.doc.gz.
            string curFile = fi.FullName;
            string origName = curFile.Remove(curFile.Length -
                    fi.Extension.Length);

            //Create the decompressed file.
            using (FileStream outFile = File.Create(origName))
            {
                using (GZipStream Decompress = new GZipStream(inFile,
                        CompressionMode.Decompress))
                {
                    // Copy the decompression stream 
                    // into the output file.
                    Decompress.CopyTo(outFile);

                    Console.WriteLine("Decompressed: {0}", fi.Name);

                }
            }
        }
    }

【问题讨论】:

  • 这是因为 .exe 文件不是有效的 .gzip 文件,但包含一个。它是一个可执行文件。 Winrar 显然能够在其中找到 .gzip(因为它可以创建这样的可执行文件,它知道它的布局并且可以读取它)。请注意,到目前为止,并非每个 .exe 文件都是自解压存档。
  • 那么我该怎么办你能给我一些示例代码吗如果你能帮助我@JanDvorak 将不胜感激
  • 我希望可以。我可能会为你做一些搜索,但我不能保证。

标签: c# winforms unzip compression self-extracting


【解决方案1】:

那是因为.exe 文件是一个自解压档案...

你应该试试DotNetZip。来自项目的常见问题解答:

此库是否读取自解压 zip 文件?

是的。 DotNetZip 可以读取由 WinZip 和 WinZip 生成的自解压档案 (SFX) 可以读取 DotNetZip 生成的 SFX 文件。

您可以轻松install it from Nuget

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    相关资源
    最近更新 更多