What the hell is this file?

Sep 11, 2011 at 8:29 PM

Hi,

     I have a situation where my program uses DotNetZip to extract updates to a program.  Some updates are .zip and some are .exe.  I just run the .exe to actually install the updates, but I want to use DotNetZip to extract the files prior to installation to read the new file version numbers so that a user can choose whether or not to install the update.

     For reference, here is an example file that I can open with 7-Zip and see the contents, but which is an EXE: http://www.fiddler2.com/dl/FiddlerJSFormatSetup.exe.  Currently, with DotNetZip, I get a BadReadException when I try to extract from one of these Stub .exe + contents files.  These are the types of files I would love for DotNetZip to be able to handle.  I'm not concerned about being able to generate them, just read and extract from them.

Thanks,
~Chad 

Coordinator
Sep 11, 2011 at 10:43 PM
Edited Sep 11, 2011 at 10:44 PM

Hi Chad, thanks for starting a fresh discussion thread.

That file is not an actual zip file, right?  You cannot read it as a "compressed folder" in Windows, and you cannot read it in WinZip, right?  How did you generate it?

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.  How exactly are you trying to read it?  Are you using a program that you write? If so, it should be pretty easy to do it yourself.  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).  Then create a ZipFile instance with ZipFile.Read(), passing the FileStream, with the Position in the FileStream set to read the 0x50 of the ZIP entry signature.

I think it'd be pretty easy for me to create a helper method that did that for you.   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.  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.  It's possible I'd be able to make the logic smart enough to handle Save() too, without surprises.  But for that I'd need some samples of such "stub.exe + contents" files to put into the test suite.

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.

So just try what I described in code and see if it works for you. 

 

Sep 11, 2011 at 11:26 PM
Edited Sep 11, 2011 at 11:28 PM

Hi Cheeso, thanks for writing back so quickly.  I'll try your code suggestion and report back.

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.  

I'm using DotNetZip in a C#/.NET 3.5 project and I'm using the Ionic.Reduced.Zip.dll as my reference.  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).

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.  No, I can't open it as a Windows Compressed Folder.

Thanks again and I'll let you know how it goes.

Sep 12, 2011 at 6:47 AM

Hi Cheeso,

So, I went down that path and found out that that file didn't have 0x504b0304 (or 0x04034b50 just in case the endianess was switched).  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.  So, it looks like DotNetZip won't be much help...

However, I still haven't found any code to actually extract the files.  I tried tar_cs (from Google Code), but have just gotten errors when I try to read in the file.

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.

The only thing to go on is that 7-zip can open the file, but I need to programmatically open and extract files.  I'm not sure if it's any help, but here's 7-Zip's info on the file:

---------------------------
Properties
---------------------------
Size: 0
Packed Size: 9 457
Folders: 0
Files: 1
----------------------------
Path: [0]
Type: Nsis
Method: LZMA:23
Solid: +
----
Path: [0]
Size: 9 464
Packed Size: 9 464
Offset: 32768
----------------------------
Path: C:\Temp\FiddlerJSFormatSetup.exe
Type: PE
CPU: x86
Characteristics: Executable 32-bit NoRelocs NoLineNums NoLocalSyms
Created: 2009-06-06 14:41:54
Physical Size: 47 216
Headers Size: 1 024
Checksum: 110657
Image Size: 184320
Section Alignment: 4096
File Alignment: 512
Code Size: 23552
Initialized Data Size: 119808
Uninitialized Data Size: 1024
Linker Version: 6.0
OS Version: 4.0
Image Version: 6.1
Subsystem Version: 4.0
Subsystem: Windows GUI
DLL Characteristics: TerminalServerAware
Stack Reserve: 1048576
Stack Commit: 4096
Heap Reserve: 1048576
Heap Commit: 4096
Image Base: 4194304

---------------------------
OK   
---------------------------

Does that help to figure out what might be going on with this file?  Thanks.

Coordinator
Sep 12, 2011 at 1:47 PM

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.

it could be the 7z format, I don't know the format, I'ver never studied it.  But if it was, it seems to me you'd realize this because 7zip would have already extracted the file.  The .Z extension is usually applied to an old unix compression format.  But the old .Z doesn't use LZMA, I don't think.  If you trust the 7zip tool's claim that it uses LZMA, then it cannot be .z. 

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?

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?

Anyway, good luck.

 

 

 

Sep 13, 2011 at 1:25 AM

Hi Cheeso,

Thanks again for your comments and help.

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.  Plus, I would need to read-up on the 7zip license, etc...

In any case, I was able to 7zip to extract the .exe as follows:
7z.exe x -y -oC:\Temp "C:\Downloads\FiddlerJSFormatSetup.exe" 

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.

Thanks again for all your help and take care,
~Chad 

Coordinator
Sep 14, 2011 at 6:27 PM

Gotcha.  Ok, thanks for clarifying.