[
  {
    "Id": "670333",
    "ThreadId": "272220",
    "Html": "\r\n<p>Hi,</p>\r\n<p>&nbsp; &nbsp; &nbsp;I have a situation where my program uses DotNetZip to extract updates to a program. &nbsp;Some updates are .zip and some are .exe. &nbsp;I just run the .exe to actually install the updates, but I want to use DotNetZip to extract the files\r\n prior to installation to read the new file version numbers so that a user can choose whether or not to install the update.</p>\r\n<p>&nbsp; &nbsp; &nbsp;For reference, here is an example file that I can open with 7-Zip and see the contents, but which is an EXE:&nbsp;<a href=\"http://www.fiddler2.com/dl/FiddlerJSFormatSetup.exe\" target=\"_blank\">http://www.fiddler2.com/dl/FiddlerJSFormatSetup.exe</a>.\r\n &nbsp;Currently, with DotNetZip, I get a BadReadException when I try to extract from one of these Stub .exe &#43; contents files. &nbsp;These are the types of files I would love for DotNetZip to be able to handle. &nbsp;I'm not concerned about being able to generate\r\n them, just read and extract from them.</p>\r\n<p>Thanks,<br>\r\n~Chad&nbsp;</p>\r\n",
    "PostedDate": "2011-09-11T13:29:39.873-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "670359",
    "ThreadId": "272220",
    "Html": "<p>Hi Chad, thanks for starting a fresh discussion thread.</p>\n<p>That file is not an actual&nbsp;zip file, right?&nbsp; You cannot read it as a \"compressed folder\" in Windows, and you cannot read it in WinZip, right?&nbsp; How did you generate it?</p>\n<p>My thinking at the time I first looked at this scenario - reading \"stub.exe + contents\" files from DotNetZip - was that it would not be overly difficult to get DotNetZip to read one of these files.&nbsp; How exactly are you trying to read it?&nbsp; Are you using a&nbsp;program that you write? If so, it should be pretty easy to do it yourself.&nbsp; Your program would need to open a FileStream with File.OpenRead(). Then scan forward in that stream looking for the first ZIP entry signature (0x504b0304).&nbsp; Then create a ZipFile instance with ZipFile.Read(), passing the FileStream, with the Position in the FileStream set to read the&nbsp;0x50 of the ZIP entry signature.</p>\n<p>I think it'd be pretty easy for me to create a helper method that did that for you.&nbsp;&nbsp; I *may* also be able to create logic that intelligently did the right thing with both actual SFX archives, which are legal EXEs and legal ZIP archives, and these \"stub.exe + contents\" archives, which are EXEs but are not legal zip archives.&nbsp; The tricky part is the ZipFile.Save*() methods - calling any of those might wipe out the original stub, which would be a surprise, and that's never nice.&nbsp; It's possible I'd be able to make the logic smart enough to handle Save() too, without surprises.&nbsp; But for that I'd need some samples of such \"stub.exe + contents\" files to put into the test suite.</p>\n<p>But before I go there, I'd want to understand the scenario a bit more. It's not a common thing, and if this is a special-case just for Chad, then I'd rather you maintain the code than put it into DotNetZip.</p>\n<p>So just try what I described in code and see if it works for you.&nbsp;</p>\n<p>&nbsp;</p>",
    "PostedDate": "2011-09-11T15:43:01.597-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "670368",
    "ThreadId": "272220",
    "Html": "<p>Hi Cheeso, thanks for writing back so quickly. &nbsp;I'll try your code suggestion and report back.</p>\n<p>I actually didn't generate that file that I linked to, but it's one of the files I'm trying to read with DotNetZip. &nbsp;</p>\n<p>I'm using DotNetZip in a C#/.NET 3.5 project and I'm using the Ionic.Reduced.Zip.dll as my reference. &nbsp;I'm creating an auto-updater program, so I'm trying to unzip a bunch of different files coming from different people (just depends on how they packaged  their code).</p>\n<p>I'm not sure if WinRAR/WinZip can read it (I don't have it installed), but I can open the file with 7-Zip, which I do have installed. &nbsp;No, I can't open it as a Windows Compressed Folder.</p>\n<p>Thanks again and I'll let you know how it goes.</p>",
    "PostedDate": "2011-09-11T16:26:55.57-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "670456",
    "ThreadId": "272220",
    "Html": "<p>Hi Cheeso,</p>\r\n<p>So, I went down that path and found out that that file didn't have 0x504b0304 (or 0x04034b50 just&nbsp;in case&nbsp;the endianess was switched). &nbsp;In fact, after I looked over a bunch of \"magic numbers\" for compression types, the only one that I could find that had a hit in the file's hex was 0xA01F - the tar.z magic header. &nbsp;So, it looks like DotNetZip won't be much help...</p>\r\n<p>However, I still haven't found any code to actually extract the files. &nbsp;I tried tar_cs (from Google Code), but have just gotten errors when I try to read in the file.</p>\r\n<p>Worst of all, I still don't know if this is actually a stub .exe + contents or just something that looks a lot like it.</p>\r\n<p>The only thing to go on is that 7-zip can open the file, but I need to programmatically open and extract files. &nbsp;I'm not sure if it's any help, but here's 7-Zip's info on the file:</p>\r\n<p>\r\n<pre>---------------------------\r\nProperties\r\n---------------------------\r\nSize: 0\r\nPacked Size: 9 457\r\nFolders: 0\r\nFiles: 1\r\n----------------------------\r\nPath: [0]\r\nType: Nsis\r\nMethod: LZMA:23\r\nSolid: +\r\n----\r\nPath: [0]\r\nSize: 9 464\r\nPacked Size: 9 464\r\nOffset: 32768\r\n----------------------------\r\nPath: C:\\Temp\\FiddlerJSFormatSetup.exe\r\nType: PE\r\nCPU: x86\r\nCharacteristics: Executable 32-bit NoRelocs NoLineNums NoLocalSyms\r\nCreated: 2009-06-06 14:41:54\r\nPhysical Size: 47 216\r\nHeaders Size: 1 024\r\nChecksum: 110657\r\nImage Size: 184320\r\nSection Alignment: 4096\r\nFile Alignment: 512\r\nCode Size: 23552\r\nInitialized Data Size: 119808\r\nUninitialized Data Size: 1024\r\nLinker Version: 6.0\r\nOS Version: 4.0\r\nImage Version: 6.1\r\nSubsystem Version: 4.0\r\nSubsystem: Windows GUI\r\nDLL Characteristics: TerminalServerAware\r\nStack Reserve: 1048576\r\nStack Commit: 4096\r\nHeap Reserve: 1048576\r\nHeap Commit: 4096\r\nImage Base: 4194304\r\n\r\n---------------------------\r\nOK   \r\n---------------------------\r\n</pre>\r\n</p>\r\n<p>Does that help to figure out what might be going on with this file? &nbsp;Thanks.</p>",
    "PostedDate": "2011-09-11T23:47:58.863-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "670582",
    "ThreadId": "272220",
    "Html": "<p>This has moved from \"how to read a zip file embedded into another stream\" into \"what the hell is this file?\" And that means it's moved from something I can help you with, into a bit of detective work you're going to have to do on your own.</p>\r\n<p>it could be the 7z format, I don't know the format, I'ver never studied it.&nbsp; But if it was, it seems to me you'd realize this because 7zip would have already extracted the file.&nbsp;&nbsp;The .Z extension is usually applied to an old unix compression format.&nbsp; But the old .Z doesn't use LZMA, I don't think.&nbsp; If you trust the 7zip tool's claim that it uses LZMA, then it cannot be .z.&nbsp;</p>\r\n<p>I don't understand why you are interested in using DotNetZip to extract this file - if 7zip can read it, why not use 7zip to extract it?</p>\r\n<p>And if you're having trouble reading the file, why don't you ask the person who generated it, how to read it? Or to regenerate it in a way that is readable by more common tools?</p>\r\n<p>Anyway, good luck.</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2011-09-12T06:47:42.34-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "670869",
    "ThreadId": "272220",
    "Html": "<p>Hi Cheeso,</p>\r\n<p>Thanks again for your comments and help.</p>\r\n<p>I'd rather not have to include 7zip in my program because I'm going to be distributing my program, which means tacking on another 1 MB of code (my program is only about 50 KB on its own), whereas the reduced DotNetZip is only about 100+ KB. &nbsp;Plus, I would need to read-up on the 7zip license, etc...</p>\r\n<p>In any case, I was able to 7zip to extract the .exe as follows:<br />7z.exe x -y -oC:\\Temp \"C:\\Downloads\\FiddlerJSFormatSetup.exe\"&nbsp;</p>\r\n<p>I will try to contact the person who created that exe and see if they can shed some light on what format it might be.</p>\r\n<p>Thanks again for all your help and take care,<br />~Chad&nbsp;</p>",
    "PostedDate": "2011-09-12T18:25:41.087-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "671848",
    "ThreadId": "272220",
    "Html": "<p>Gotcha.&nbsp; Ok, thanks for clarifying.</p>",
    "PostedDate": "2011-09-14T11:27:47.603-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]