Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kainjow

Moderator emeritus
Original poster
Jun 15, 2000
7,958
7
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 :)
 

savar

macrumors 68000
Jun 6, 2003
1,950
0
District of Columbia
kainjow said:
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

Moderator emeritus
Original poster
Jun 15, 2000
7,958
7
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

macrumors 603
Oct 16, 2003
6,301
1
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

Moderator emeritus
Original poster
Jun 15, 2000
7,958
7
Yes. I only need to create the .exe from the Mac. I don't need to execute it on the Mac.
 

gekko513

macrumors 603
Oct 16, 2003
6,301
1
MinGW claims to let you cross-compile .exe files for Windows on OS X: Link. But it doesn't look easy.
 

kainjow

Moderator emeritus
Original poster
Jun 15, 2000
7,958
7
:) 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:
 

gekko513

macrumors 603
Oct 16, 2003
6,301
1
Nice work, kainjow. Maybe you should get involved with the darwine project? :)
 

drcube26

macrumors newbie
Jul 19, 2006
2
0
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,
 

kainjow

Moderator emeritus
Original poster
Jun 15, 2000
7,958
7
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.
 

vicsf

macrumors newbie
Apr 26, 2010
2
0
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!
 

kainjow

Moderator emeritus
Original poster
Jun 15, 2000
7,958
7
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.