PDA

View Full Version : Create self-extracting exe




kainjow
Apr 19, 2006, 07:51 PM
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 (http://www.chilkatsoft.com/zip-library.asp), 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 (http://www.disoriented.com/FreeExtractor/). Although it's a Windows program, it appears to be mostly ANSI C, and not based on Win32 too much (besides the GUI). Hm :)



savar
Apr 19, 2006, 09:34 PM
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.

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.

kainjow
Apr 19, 2006, 09:39 PM
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.

gekko513
Apr 19, 2006, 10:01 PM
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.

kainjow
Apr 19, 2006, 10:09 PM
Yes. I only need to create the .exe from the Mac. I don't need to execute it on the Mac.

gekko513
Apr 19, 2006, 10:17 PM
MinGW claims to let you cross-compile .exe files for Windows on OS X: Link (http://landonf.bikemonkey.org/code/win32/MinGW.20041207231336.1583.sulu.html). But it doesn't look easy.

kainjow
Apr 19, 2006, 10:23 PM
Hehe.. I don't need to compile, just build. http://www.disoriented.com/FreeExtractor/ is what I need. I am working on porting it though, so I think it'll do what I want.

kainjow
Apr 20, 2006, 01:51 AM
:) 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...
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:./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:

gekko513
Apr 20, 2006, 08:38 AM
Nice work, kainjow. Maybe you should get involved with the darwine project? :)

drcube26
Jul 19, 2006, 08:08 PM
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,

kainjow
Jul 20, 2006, 12:40 AM
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
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.

drcube26
Jul 20, 2006, 03:49 PM
Thank you very much!!!!!;)

vicsf
Apr 26, 2010, 06:53 PM
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!

kainjow
Apr 26, 2010, 10:34 PM
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.

vicsf
Apr 27, 2010, 12:51 PM
I can't access "http://www.disoriented.com/FreeExtractor/"...