Create self-extracting exe

Discussion in 'Mac Programming' started by kainjow, Apr 19, 2006.

  1. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #1
    I need to be able to create a self-extracting exe from Mac OS X.

    The only solution I have seen so far that works in Mac OS X is from Stuffit's SDK, but I also need the .exe to launch a file that it uncompresses after it's done uncompressing. Stuffit does not do this.

    The closest I have found is this, but I think the code is based on MFC, and I don't have the time to port that, even if I was able to :)

    There has to be some open source *nix solution that does this, but I haven't found anything. Any help would be much appreciated. Ideally, it would be cross-platform so that the exact .exe is created from OS X and Windows.

    Edit: ok I just found this. Although it's a Windows program, it appears to be mostly ANSI C, and not based on Win32 too much (besides the GUI). Hm :)
     
  2. macrumors 68000

    savar

    Joined:
    Jun 6, 2003
    Location:
    District of Columbia
    #2
    Hmm...Stuffit stinks anyway, I don't download anything that is Stuff'ed any more.

    I have a simple solution to your problem, however. Create an installer application in XCode. Add a tar'ed gzip'ed copy of the program you want to decompress into the application bundle. Write a shell script or compiled program which executes ungzip, then tar -xf, and then forks a new process which runs your target program.

    If you want to get really clever, make the name of the tar file a parameter in the info.plist, and then create another application which can take a tar file, load into a copy of this application bundle, and then updates the info.plist. That would be a useful little program, actually.
     
  3. thread starter Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #3
    Thanks for the reply. But I guess I didn't make myself clear. I need to be able to make an .exe, as in a Windows executable, from Mac OS X, dynamically. And preferrably, the code should be cross-platform so I can generate the Windows exe from Mac OS X and Windows :) The last link I posted above I think should do the trick. I just need to make it platform-independent.
     
  4. macrumors 603

    gekko513

    Joined:
    Oct 16, 2003
    #4
    I don't think it's possible. Windows and OS X doesn't have the same format for executable binaries. Windows use the PE (portable executable) file format, but it's only portable across the Windows OSes. Linux uses ELF and OS X uses Mach-O files.

    The only "executable" file format I know that work across platforms is .jar files, and that requires a correctly configured Java runtime environment installation.

    Edit: Oh, wait, you don't need to execute the .exe file on OS X, you just want to create it there? Am I right?

    2nd Edit: But why do you want a self extracting .exe? I know I'm very wary of .exe files on Windows, so unless I can be sure it is a program that I want I will not deal with or execute a .exe file.
     
  5. thread starter Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #5
    Yes. I only need to create the .exe from the Mac. I don't need to execute it on the Mac.
     
  6. macrumors 603

    gekko513

    Joined:
    Oct 16, 2003
    #6
    MinGW claims to let you cross-compile .exe files for Windows on OS X: Link. But it doesn't look easy.
     
  7. thread starter Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #7
  8. thread starter Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #8
    :) Well, I got that app ported :D Took several hours, but a lot shorter then I expected. It's pretty ugly with #ifdef WIN_32 everywhere, and my own Win32 compatible functions like...
    Code:
    BOOL ReadFile(
      HANDLE hFile,
      LPVOID lpBuffer,
      DWORD nNumberOfBytesToRead,
      LPDWORD lpNumberOfBytesRead,
      LPOVERLAPPED lpOverlapped
    )
    {
    	int c = fread(lpBuffer, 1, nNumberOfBytesToRead, hFile);
    	(*lpNumberOfBytesRead) = (DWORD)c;
    	return (nNumberOfBytesToRead == c);
    }
    
    BOOL WriteFile(
      HANDLE hFile,
      LPCVOID lpBuffer,
      DWORD nNumberOfBytesToWrite,
      LPDWORD lpNumberOfBytesWritten,
      LPOVERLAPPED lpOverlapped
    )
    {
    	size_t c = fwrite(lpBuffer, nNumberOfBytesToWrite, 1, hFile);
    	(*lpNumberOfBytesWritten) = (DWORD)c;
    	return ((DWORD)c == nNumberOfBytesToWrite);
    }
    But... it works! I will post my code later on once I get some free time to clean it up.

    The app is run from the command line like this:
    Code:
    ./MakeSFX /zip="file.zip" /sfx="setup.exe"
    Then it uses an already existing Win32 installer, and adds the zip file to the .exe file. When you run the .exe, it extracts the zip from the exe into a specified folder. :cool:
     
  9. macrumors 603

    gekko513

    Joined:
    Oct 16, 2003
    #9
    Nice work, kainjow. Maybe you should get involved with the darwine project? :)
     
  10. macrumors newbie

    Joined:
    Jul 19, 2006
    #10
    Mac exe

    Hi,


    I am trying to create exe on OS X platform as well. Would it be possible for you to post updated code ( it doesn't have to be clean :)

    Thanks in advance,
     
  11. thread starter Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #11
    Sure, here it is (couldn't attach it because it was too big):
    http://www.kainjow.com/code/FreeExtractor.zip

    FYI to compile for a universal binary, use
    Code:
    gcc MakeSFX.c -o MakeSFX -arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk
    icon.h and stub.h were compiled on my PC with Visual Studio, I think version 2003. However, I think it's using a custom icon, because the icon option in MakeSFX doens't really work that well (you have to have the icon be an exact size in bytes). So you may have to re-compile that on a PC if you want the original or another icon.
     
  12. macrumors newbie

    Joined:
    Jul 19, 2006
  13. macrumors newbie

    Joined:
    Apr 26, 2010
    #13
    Create self-extracting exe

    Hi kainjow,
    I'm a newbie on this forum and your post "Create self-extracting exe" is the main reason I'm here! I inherited some code which uses MakeSFX executable to create it on a mac via command line and run it on a PC. Everything works fine except for one issue - there is a "back" button the very first window which causes application to crash if user clicks twice on it... Is it possible to hide/grey out this "back" button? Any advice will be greatly appreciated!
     
  14. thread starter Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #14
    I no longer work on or maintain that code, but I would suggest trying to run the installer (if you have the source code) in a debugger on Windows and find out why it's crashing.
     
  15. macrumors newbie

    Joined:
    Apr 26, 2010
    #15
    I can't access "http://www.disoriented.com/FreeExtractor/"...
     

Share This Page