2012-10-28 21 views
6

exe ​​파일을 추출하고 싶습니다. exe 파일에는 일부 파일과 폴더가 들어 있습니다. 나는이 추출됩니다 WinRAR과를 사용하여 파일을 추출하려고하지만 언제 몇 가지 예를 사용하여 exe 파일을 추출하려고 할 때이 오류가 무엇입니까 : 나는 몇 가지 샘플을 사용하고 내 문제에 대한 많은 검색 좀GZip 헤더의 매직 번호가 올바르지 않습니다. GZip 스트림을 전달하고 있는지 확인하십시오. (.exe 파일)

The magic number in GZip header is not correct. Make sure you are passing in a GZip stream.

을 그러나 내 대답을 얻지 못했고, 나는 또한 몇몇 도서관을 사용했다. .exe 파일이 자동 압축 풀림 보관이기 때문이다

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); 

       } 
      } 
     } 
    } 
+2

.exe 파일은 유효한 .gzip 파일이 아니고 _ 포함되어 있기 때문입니다. 실행 파일입니다. Winrar는 분명히 .gzip을 찾을 수 있습니다 (실행 파일을 만들 수 있기 때문에 레이아웃을 알고 읽을 수 있기 때문입니다). 모든 .exe 파일이 자동 압축 풀림 보관소는 아닙니다. –

+0

그래서 내가 할 수 있으면 어떻게해야합니까 몇 가지 예제 코드를 제공 할 수있는 큰 감사가있을 것입니다 당신이 도와 줄 수있는 @ JanDvorak –

+0

내가 할 수 있으면 좋겠다. 나는 너를 위해 약간의 수색을 할지도 모른다. 그러나 나는 어떤 보증도 줄 수 없다. –

답변

4

...

당신은 DotNetZip 시도를 제공해야합니다 :

는이 코드 만 같은 오류를 사용했다. 프로젝트 FAQ에서 :

Does this library read self-extracting zip files?

Yes. DotNetZip can read self-extracting archives (SFX) generated by WinZip, and WinZip can read SFX files generated by DotNetZip.

쉽게 install it from Nuget하실 수 있습니다.